Extensions :  K-Meleon Web Browser Forum
All about K-Meleon extensions. 
Pages: 12Next
Current Page: 1 of 2
Macro request - Copy all links from all tabs
Posted by: rodocop
Date: June 23, 2016 11:58AM

Hi, folks!

There is a FF-addon named Copy All Links

It allows do, in particular, the next job: copy all links present on pages from all the tabs open at moment in browser.

There is a request for same functionality in K-Meleon. As I can suppose this possibly could be done through macro - using parts of docinfo.kmm (extracting all links from current page - using injected JS).

But I haven't enough knowledge to create this by myself (or confirm that it cannot be done).

What about anybody dare to manage this?

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: siria
Date: June 23, 2016 06:50PM

sure can, but no time...
Different windows are probably complicated, but all tabs in 1 window probably easy (for the js-savvy)

John...? :cool:

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JohnHell
Date: June 23, 2016 09:46PM

Quote
siria
sure can, but no time...
Different windows are probably complicated, but all tabs in 1 window probably easy (for the js-savvy)

John...? :cool:

Tell me then.

Because we are facing the same problem as with YesScript. There isn't a focus (OnActivateWindow) for tabs.

Ok, we can switch from tab to tab, but, how to interact with the next tab?

We lack a focus event for tabs. Or is there some method to interact with all tabs inside a window. Tell me, I don't use tabs.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: siria
Date: June 24, 2016 12:23AM

Luckily an event isn't needed when the user starts something manually. Am just never quite sure about possible new behaviour/bugs in newest KM-versions.

A little snippet from another macro as example:

_macro_collectTabs{
$_nr=0; while($_nr<$TabNumber) {
$_nr=($_nr+1);
.....(action)....
id(ID_TAB_NEXT);
}}

If absolutely need be there are crazy convoluted workarounds to also hop from window to window and inside from tab to tab again, but got absolutely confused because of my multiversion-macro attempts, and each version needs other tricks, but all forgotten again meanwhile, sigh.
For this macro though all tabs in 1 window are hopefully enough, if the user is tab-fan as most people :cool:

HA - just noticed the subject line! grinning smiley



Edited 1 time(s). Last edit at 06/24/2016 12:28AM by siria.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JohnHell
Date: June 24, 2016 02:03AM

If so, then, reusing the _DocInfo_lstLinks from docinfo.kmm should work. I guess...

Probably anyone of us can do this as all the work is already done.

Anyway, I'm with the mind in other things now, as the elections we have here too, so if no one takes the challenge, I'd do, but not these days.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JamesD
Date: June 24, 2016 11:31AM

Where is the information to be copied? Current method creates a source for the current tab to display like a HTML page.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: siria
Date: June 24, 2016 06:59PM

Uh oh... you're right, it may not be as easy as first thought! Just remembered now: the links are collected by JS, but tabs have to be switched by macro - and never could find a decent way how to exchange long and complicated strings between them?? Wasted already endless time and nerves with that insolvable prob, again and again over the years, but still no real solution :-( Knowing nearly nothing about JS sure doesn't help! Out of pure desperation even tried stuff like having JS inject the collected string into the current web page, to be able to highlight it all and import it back into a macro, then flipping the page forward again, but that's awful, and with KM76 even that method broke ("document.write()" or some such, have forgotten)
Perhaps someone with more JS skills knows a solution? Or a new macro command some day...?

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JamesD
Date: June 24, 2016 08:48PM

My JS skills even more limited that yours. Is there a limit on how long the js code that is injected can be? Is there any way to specify another object for document.write? I suspect file object will not be allowed.

I had hoped that my understanding of WScript would help but an not too sure anymore.

I am not giving up but it may be Monday before I have time to really dig into this.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: siria
Date: June 24, 2016 08:59PM

Quote
JamesD
I had hoped that my understanding of WScript would help but an not too sure anymore.

Perhaps that would really help? Perhaps it can write into a file? Of WScript I have 0.0 clue!

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: rodocop
Date: June 24, 2016 09:22PM

Quote
JamesD
Where is the information to be copied? Current method creates a source for the current tab to display like a HTML page.

I thought it could be smth like Note4me output (txt-file opened finally in new tab)

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JohnHell
Date: June 24, 2016 09:50PM

Quote
siria
Uh oh... you're right, it may not be as easy as first thought! Just remembered now: the links are collected by JS, but tabs have to be switched by macro - and never could find a decent way how to exchange long and complicated strings between them??

DAMN IT, hate tabs. Ok, in tabs worked, forget the text below this.

MMM.

So, no way to interact with other tabs or windows.

I ended making a simple test with yours and with macro code and injectJS and the result is the same: code is not applied to next windows or tabs.


As simple as this:

$_taprueba = "";

_taprueba{
	$_tadf = injectJS("(function(e){e = document.title.toString(); return e;})();");
	$_taprueba = $_taprueba."\n".$_tadf;

#	$_taprueba = $_taprueba."\n".$TITLE;  first attempt
}

prueba{
$_nr=0;

	while($_nr<$TabNumber) {
		&_taprueba;
		id(ID_TAB_NEXT);
		$_nr=($_nr+1);
	}

alert($_taprueba);
}

EDIT: fixed to avoid confusion, I tested with tabs and windows but I left $WindowNumber and ID_TAB_NEXT in my paste.




The title is ever taken from original window or tab. It never interacts with the switched ones. So, I don't bet for more complicated scripts to work.

As I said, we need a $OnActivateWindow for tabs. That would help to loop and make actions while the macro runs based on a temporary preference. That was my initial thought with my first post here.




Edited 5 time(s). Last edit at 06/24/2016 10:14PM by JohnHell.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JamesD
Date: June 25, 2016 10:49AM

Tested code from JohnHell. Works great. Three tabs return three titles.

Now I must try to find what in the code from docinfo finds the links. I don't need the part that makes a HTML document.

Question for JohnHell or siria: Can I do two injectJS()'s on a single tab? First for tab title and another to obtain the links.

$JS_doitLink="
j=a.length;
var l=getAttribute('hreflang'),p=getAttribute('ping'),t=getAttribute('type'),s='"._("Link Properties:")."\\n\\n"._("URL:\\t%s")."'.replace(/%s/,unescape(href));
if(p)s+='\\n"._("Ping:\\t%s")."'.replace(/%s/,unescape(p));
if(l||t){s+='\\n\\n"._("Properties of Linked Resource:")."\\n';if(t)s+='\\n"._("MIME Type:\\t%s")."'.replace(/%s/,t);
if(l)s+='\\n"._("Language:\\t%s")."'.replace(/%s/,l)}s+='\\n\\n"._("Do you want to view the linked resource now?")."';
if(confirm(s)){if(top.location==self.location)open(href);top.location.href=href}";
&JS_hndlLink;

Might I have to obtain each link and write to doc title until there are no more links? Would mean that 7 links would require 8 injectJS()'s - one for title and one for each link (7).

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JamesD
Date: June 26, 2016 01:39PM

I think that I will have to admit that I know nothing of js. Every attempt to improve on JohnHell's code gets me nothing. I am using code right from the http://www.w3schools.com/jsref/coll_doc_links.asp page.

Example

[index]

Get the URL of the first link (index 0) in the document:
var x = document.links[0].href;

Removing the # to un-comment my additions only results in obtaining a missing value.

_Snippet_taprueba{
	$_tadf = injectJS("(function(e){e = document.title.toString(); return e;})();");
	$_taprueba = $_taprueba."\n".$_tadf;
	&_Snippet_taprueba2;
}

_Snippet_taprueba2{
    $_tadf2 = "..";
	#$_tadf2 = injectJS("{function(u)(var u = document.links[0].href.toString(); return u;})();");
	$_tadf2 = injectJS("{function(u)(var u = document.links[0].href; return u;})();");
	length($_tadf2) == 0 ? $_tadf2 = "!!" : 0; 
    $_taprueba = $_taprueba."\n".$_tadf2;
}

_Snippet_RunCode{
$_taprueba = "";
$_nr=0;
	while($_nr<$TabNumber) {
		&_Snippet_taprueba;
		id(ID_TAB_NEXT);
		$_nr=($_nr+1);
	}
alert($_taprueba);
}

I always get the !! so something replaced the .. but it was not the first URL. Can one have a while loop from 0 to the number of URLs inside the injectJS()? I ask but I don't need that answer until I can get the first URL.



Edited 1 time(s). Last edit at 06/26/2016 01:42PM by JamesD.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JohnHell
Date: June 26, 2016 10:47PM

You have a typo for the auto invoked function.This got me time to learn too:

(function(){})();
(I colored it to make distinctions, as I did time ago with the new skin system. Hope it helps.)

I bet you have the console filled with errors.

Maybe tomorrow night I can give some time on this.

Maybe, too, wasn't a good hint to think in the docinfo.kmm macro. Tomorrow will see.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JamesD
Date: June 27, 2016 01:23AM

Thank you, JohnHell.

My eyes are as old as I am. I may have to see if there is a way to color the ( differently from the { in Notepad++.

I have the URL data showing now. Lots more work to do yet.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JamesD
Date: June 27, 2016 02:22AM

Some progress but not what I had hoped.

I don't seem to be able to get the number of links so for demo I have only first link in each of 2 tabs. The code has what I planned to do if I could get the 'document.links.length;'.

Output:

Macro request - Copy all links from all tabs

-> http://kmeleonbrowser.org/forum/read.php?9,1466990595,newer
HTML DOM links Collection

-> javascript:void(0);

Code used:
_Snippet_taprueba {
	$_tadf = injectJS("(function(e){e = document.title.toString(); return e;})();");
	$_taprueba = $_taprueba."\n".$_tadf;
	&_Snippet_taprueba2;
}

_Snippet_taprueba2 {
    $_ucount = 0 ;
	$_tadf2 = injectJS("(function(x){x = document.links.length; return x;})();");
	$_taprueba = $_taprueba."\n".$_tadf2;
#    while ( $_ucount < $_tadf2 ) {
#	   &_Snippet_taprueba3 ;
#	   $_ucount = $_ucount + 1;
#	}
&_Snippet_taprueba3 ;
}

_Snippet_taprueba3 {
	#$_tadf3 = injectJS("(function(u){var u = document.links[".$_ucount."].href; return u;})();");
	$_tadf3 = injectJS("(function(u){var u = document.links[1].href; return u;})();");
    $_taprueba = $_taprueba."\n-> ".$_tadf3;
}

_Snippet_RunCode{
$_taprueba = "";
$_nr=0;
	while($_nr<$TabNumber) {
		&_Snippet_taprueba;
		id(ID_TAB_NEXT);
		$_nr=($_nr+1);
	}
alert($_taprueba);
$writeRet = writefile(getfolder(ProfileFolder)."\\taprueba.txt", $_taprueba);
}

Edit: In the error console, there was this item. I don't know if it has anything to do with my problem.
Sun Jun 26 2016 21:59:51
Error: TypeError: list is undefined
Source file: resource://gre/modules/AppsServiceChild.jsm
Line: 118



Edited 1 time(s). Last edit at 06/27/2016 02:27AM by JamesD.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: siria
Date: June 27, 2016 03:21AM

The number of links is just a plain number, that is easy to transfer with injectJS and return-function. And the links don't need to be transfered 1 by 1, only one complete list per page. I'd leave the JS part to John...

My concerns with transfering lots of text between JS+macro are rather all the non-latin characters that can nowadays be contained in URLs, and other special characters. Let alone if trying to list the link names too. That's why my other macro uses convoluted workarounds instead of escaping all that stuff, which I'd never get 100% right anyway.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JamesD
Date: June 27, 2016 11:44AM

siria

This code did not give me the number. I got it from this:
http://www.w3schools.com/jsref/coll_doc_links.asp

$_tadf2 = injectJS("(function(x){x = document.links.length; return x;})();");

Is there not a limit on the number of characters the injectJS() can return? It would be great to get all links in one statement, if that is possible.

I also wonder if there is validation needed. The second link on one of the tabs in my test was "javascript:void(0);". Does the "ping" stuff in docinfo.kmm's injectJS() check to see if the link is a URL outside the document? Edit: Checked docinfo and that is included.

Oh, wow! I just ran the docinfo links on URL I noted above. What happens after link 42? The item numbers go on to 85 and there are some marks, boxes, and a box in blue like a URL among the mostly blank items.



Edited 1 time(s). Last edit at 06/27/2016 11:51AM by JamesD.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JohnHell
Date: June 27, 2016 07:09PM

Quote
JamesD
siria

This code did not give me the number. I got it from this:
http://www.w3schools.com/jsref/coll_doc_links.asp

$_tadf2 = injectJS("(function(x){x = document.links.length; return x;})();");

Is there not a limit on the number of characters the injectJS() can return? It would be great to get all links in one statement, if that is possible.

I also wonder if there is validation needed. The second link on one of the tabs in my test was "javascript:void(0);". Does the "ping" stuff in docinfo.kmm's injectJS() check to see if the link is a URL outside the document? Edit: Checked docinfo and that is included.

Oh, wow! I just ran the docinfo links on URL I noted above. What happens after link 42? The item numbers go on to 85 and there are some marks, boxes, and a box in blue like a URL among the mostly blank items.

HTML Objects
<a>

When it found that text for tag "A" it didn't escape it so it broke the whole generated page duplicating the <a> and never closing it.



I don't know if there is a return limit, or a variable length limit (it was, right?), so all this may be waste of time.


From the first thoughts to the final result, it may be a world in between.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: siria
Date: June 27, 2016 07:22PM

injectJS limit: the wiki says it's about 4kB, but somehow I think Dorian increased it recently... or may confuse it with another command...
http://kmeleonbrowser.org/wiki/macrolanguage2
Never noticed any limit for variables.

Yeah the escaping is the hardest part.

function(x)....
Shouldn't the x be removed here?
And afterwards the x be defined as a var first...



Edited 2 time(s). Last edit at 06/27/2016 07:24PM by siria.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JamesD
Date: June 27, 2016 07:58PM

Yes, the limit is 4096 characters.

There is also the 'LOCATION' parameter which can be set to alltabs.

Parameter  Required Type 	Value 	    Meaning
JS 	   YES 	    STRING 	JS code     The JavaScript code to be injected.
location   NO 	    PREDEFINED 	alltabs     Address all tabs in the current window.
			        frame 	    Address the current frame only.

I still cannot get the count, "document.links.length", to be returned.

I have removed the function (x) and added var in all the ways that I could. Is the ",toString" possible here. It should be a numeric value, but maybe only strings work?

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JamesD
Date: June 27, 2016 08:02PM

count must be a string

There are 182 links in this thread.

EDIT:

The code works. My output file looks like this.


Macro request - Copy all links from all tabs
189
-> http://kmeleonbrowser.org/forum/list.php?9
-> http://kmeleonbrowser.org/forum/read.php?9,1467057730,newer
-> http://kmeleonbrowser.org/forum/read.php?9,1467057730,older
-> http://kmeleonbrowser.org/forum/index.php
-> http://kmeleonbrowser.org/forum/list.php?9
-> http://kmeleonbrowser.org/forum/posting.php?9
-> http://kmeleonbrowser.org/forum/search.php?9
-> http://kmeleonbrowser.org/forum/read.php?9,139024,markthreadread
-> http://kmeleonbrowser.org/forum/login.php?9,logout=1
-> http://kmeleonbrowser.org/forum/read.php?9,139024,printview,page=1
-> http://kmeleonbrowser.org/forum/profile.php?9,2624
-> http://kmeleonbrowser.org/forum/follow.php?9,139024

. . . I cut a bunch out somewhere about here . .

-> http://kmeleonbrowser.org/forum/report.php?9,139079
-> http://kmeleonbrowser.org/forum/posting.php?9,edit,139079
-> http://www.phorum.org/
-> http://kmeleonbrowser.org/
-> http://kmeleonbrowser.org/shots.php
-> http://kmeleonbrowser.org/download.php
-> http://kmeleonbrowser.org/docs.php
-> http://kmeleonbrowser.org/resources.php
-> http://kmeleonbrowser.org/contrib.php
-> http://kmeleonbrowser.org/forum/
-> http://kmeleonbrowser.org/bugs/
-> http://sourceforge.net/projects/kmeleon/
-> http://sourceforge.net/projects/kmeleon
-> http://sourceforge.net/donate/index.php?group_id=14285
->



Edited 1 time(s). Last edit at 06/27/2016 08:18PM by JamesD.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JohnHell
Date: June 27, 2016 08:27PM

Quote
JamesD
count must be a string

Yes, remember this:
http://kmeleonbrowser.org/forum/read.php?3,131400,133260#msg-133260

Do you already have a working macro?

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JohnHell
Date: June 27, 2016 08:33PM

Quote
siria

function(x)....
Shouldn't the x be removed here?
And afterwards the x be defined as a var first...

x is the function local variable.

This or this is valid:

function (x){}

function (){var x;}

Or global if you prefer:
var x; function(){}



Edited 1 time(s). Last edit at 06/27/2016 08:33PM by JohnHell.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JohnHell
Date: June 27, 2016 08:57PM

Yep, 4096 :/






Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JamesD
Date: June 27, 2016 09:02PM

I am sure someone can improve on my method. A user could wind up with a VERY LARGE NUMBER of injectJS()'s. I have a fast system and do not notice much wait time.

Someone needs to tell me where the menu for this goes. I have been testing in my test code area, but not that many users will be using IE favorites. A complete rename of the variables is required. This is the code as I have tested.

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage2)
#
# ---------- Snippet.kmm
# ---------- code testing 
#
# Dependencies        : main.kmm
# Resources           : -  
# Preferences         : -
# Version             : -  		
# --------------------------------------------------------------------------------

_Snippet_taprueba {
	$_tadf = injectJS("(function(e){e = document.title.toString(); return e;})();");
	$_taprueba = $_taprueba."\n".$_tadf;
	&_Snippet_taprueba2;
}

_Snippet_taprueba2 {
    $_ucount = 0 ;
	$_tadf2 = injectJS("(function (x){var x = document.links.length.toString(); return x;})();");
	$_taprueba = $_taprueba."\n".$_tadf2;
	$_tadCount = 0 + $_tadf2 ;
    while ( $_ucount < $_tadCount ) {
	   &_Snippet_taprueba3 ;
	   $_ucount = $_ucount + 1;
	}
}

_Snippet_taprueba3 {
	$_tadf3 = injectJS("(function(u){var u = document.links[".$_ucount."].href; return u;})();");
    $_taprueba = $_taprueba."\n-> ".$_tadf3;
}

_Snippet_RunCode{
$_taprueba = "";
$_nr=0;
	while($_nr<$TabNumber) {
		&_Snippet_taprueba;
		id(ID_TAB_NEXT);
		$_nr=($_nr+1);
	}
$writeRet = writefile(getfolder(ProfileFolder)."\\taprueba.txt", $_taprueba);
$writeRet ? alert("Output file: taprueba.txt", "All links in Window", INFO) : alert("Job ended - error", "All links in Window", INFO);
}

_Snippet_BuildMenu {
	# add another option to Favorites menu
	setmenu("F&avorites",macro,"Snippet Testing","_Snippet_RunCode",4);
}

_Snippet_GetPath {
#$__Data=readfile(getfolder(MacroFolder)."\\Snippet.kmm");
#$_Snippet_Path=getfolder($__Data==""?UserMacroFolder:MacroFolder);
#$_Snippet_J_Path=getfolder($__Data==""?UserMacroFolder:MacroFolder)."\\Snippet.txt";
#$_Snippet_J_Path=getfolder($__Data==""?UserMacroFolder:MacroFolder)."\\Snippet.js";
#delpref("k-meleon_Snippet_active");
#setpref( BOOL, "k-meleon_Snippet_active", false);
#$_Snippet_ini_path=getfolder(ProfileFolder)."\\Snippet.ini";
}
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#$OnLoad=$OnLoad."_Snippet_AutoRun;"; 
#$OnStartup=$OnStartup."_Snippet_GetPath;";
$OnInit=$OnInit."_Snippet_BuildMenu;";
#$OnInit=$OnInit."_Snippet_SetAccels;";
#$OnInit=$OnInit."_Snippet_Get_LoadedSkin;";
$macroModules=$macroModules."Snippet;";



Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: JohnHell
Date: June 27, 2016 09:30PM

Works for me.

@rodocop, one important question:

would I be wrong if what the requester really wants is:

"It supports direct file links (e.g. http://www.some-server.com/some-file.zip) as well as the links to the most popular file sharing sites (e.g. http://www.netload.in/dateiabCdeFGH1.htm, etc.)."


Because, then, there is the need to change a little the macro to include an optional array to check every link.

That would be really the most CPU time consuming task.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: rodocop
Date: June 28, 2016 12:03AM

That was not my own request so I should to verify the exact point.

But as I understand there wasn't any talk about resolving links - just collecting them in form they are present on pages.



Edited 1 time(s). Last edit at 06/28/2016 12:04AM by rodocop.

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: siria
Date: June 28, 2016 04:46AM

With my near-zero knowledge: isn't "document.links" the whole list of all as array, that means comma-separated?

Options: ReplyQuote
Re: Macro request - Copy all links from all tabs
Posted by: rodocop
Date: June 28, 2016 11:03AM

Quote
siria
With my near-zero knowledge: isn't "document.links" the whole list of all as array, that means comma-separated?

Didn't know anything about this but have googled this

Options: ReplyQuote
Pages: 12Next
Current Page: 1 of 2


K-Meleon forum is powered by Phorum.