Is there a better way to copy multiple links? Topic is solved

Users and developers helping users with generic and technical Pale Moon issues on all operating systems.

Moderator: trava90

Forum rules
This board is for technical/general usage questions and troubleshooting for the Pale Moon browser only.
Technical issues and questions not related to the Pale Moon browser should be posted in other boards!
Please keep off-topic and general discussion out of this board, thank you!
Binky

Is there a better way to copy multiple links?

Unread post by Binky » 2021-04-11, 01:26

I'm using Pale Moon 29.1.1 in Linux MInt 20 XFCE. Occasionally I find a web page where I want to select and copy multiple links simultaneously instead of stepping through each link one at a time.

I tried the extension Multi LInks Plus 3.9.3, but that caused problems - when I tried to drag a selection around part of the page content it disappeared from view so I couldn't see what I was selecting.

I've got a working solution but it's clunky:
  • install 'Open With' 6.8.6 extension for Firefox
  • install lynx text-mode browser
  • create a 'Lynx links' menu item for 'Open With' using the command 'xfce4-terminal --title="Lynx links" --hide-menubar --hide-toolbar --hold --execute /usr/bin/lynx -listonly -dump -nonumbers'
  • select the required links from the list in the xfce4-terminal window and copy them
I'm wondering if there's a better way that works with the latest Pale Moon browser.

User avatar
micwoj92
Fanatic
Fanatic
Posts: 175
Joined: 2020-12-22, 20:57

Re: Is there a better way to copy multiple links?

Unread post by micwoj92 » 2021-04-11, 11:04

I'm wondering if there's a better way that works with the latest Pale Moon browser.
This doesn't really work with Pale Moon, but with your XFCE Desktop https://docs.xfce.org/panel-plugins/xfc ... ugin/start

Package name on Mint should be " xfce4-clipman-plugin"

Binky

Re: Is there a better way to copy multiple links?

Unread post by Binky » 2021-04-11, 21:40

@ micwoj92

Thanks for the response. I already have the Clipman plugin installed. That does not help with copying multiple links, it merely keeps a list of previously copied items.

User avatar
opus_27
Apollo supporter
Apollo supporter
Posts: 36
Joined: 2020-06-16, 13:29

Re: Is there a better way to copy multiple links?

Unread post by opus_27 » 2021-04-11, 22:32

This would probably be done best by an extension, but to see the possibilities, you can put the following code in a bookmarklet. Then on a page containing some links, select a few and click the bookmarklet. It should pop up an alert containing the links, which you can copy-paste into a text file, changing the extension to .htm or .html. Then open the file in your browser.

An extension could put the results directly on the clipboard or save them to a file. The alert technique would become too cumbersome if the number of links grew much.

Code: Select all

javascript:{
  let linkHarvester = {
    serializer: new XMLSerializer(),
    handleEvent: function(event){
      var oSel = window.getSelection(), hldr = document.createElement('div'), hrvst = hldr.cloneNode(false),
      styl = hrvst.appendChild(document.createElement('style')); styl.setAttribute('scoped', 'scoped'); styl.appendChild(document.createTextNode('a[href]{display:block;}'));
      for(let i = 0, k = oSel.rangeCount; i < k; i++){hldr.appendChild(this.extendRange(this.extendRange(oSel.getRangeAt(i), true)).cloneContents())};
      var lnks=hldr.querySelectorAll('a[href]');
      for(let i=0, k=lnks.length;i<k;i++){hrvst.appendChild(lnks[i].cloneNode(true))};
      alert(this.serializer.serializeToString(hrvst));
    },
    extendRange: function(rng,bBackward){
      var rc=rng[bBackward? 'startContainer' : 'endContainer']; if(rc.nodeType !=1){rc = rc.parentNode};
      var x=this.seekLink(rc);
      if(x && (x !== rc)){rng[bBackward? 'setStartBefore' : 'setEndAfter'](x)};
      return rng;
    },
    seekLink:function(nd){
      do{
        if(nd.matches('a[href]')){return nd};
        if(nd.matches('a')){return null};
      }while((nd = nd.parentNode) && (nd.nodeType == 1));
    }
  };
  linkHarvester.handleEvent(null);
}

User avatar
opus_27
Apollo supporter
Apollo supporter
Posts: 36
Joined: 2020-06-16, 13:29

Re: Is there a better way to copy multiple links?

Unread post by opus_27 » 2021-04-12, 12:53

I just noticed that my code, as given, leaves relative links as they are—probably not terribly useful. Sorry I missed this, but the revision below fixes it, I think.

So far, the code makes no effort to remove images or special text effects, or to handle cases where the link contains no text. Depending on your use case, any or all could be fixed.

Code: Select all

javascript:{
  let linkHarvester = {
    serializer: new XMLSerializer(),
    handleEvent: function(event){
      var oSel = window.getSelection(), hldr = document.createElement('div'), hrvst = hldr.cloneNode(false),
      styl = hrvst.appendChild(document.createElement('style')); styl.setAttribute('scoped', 'scoped');
      styl.appendChild(document.createTextNode('a[href]{display:list-item; list-style-type:decimal-leading-zero;}'));
      for(let i = 0, k = oSel.rangeCount; i < k; i++){hldr.appendChild(this.extendRange(this.extendRange(oSel.getRangeAt(i), true)).cloneContents())};
      var lnks=hldr.querySelectorAll('a[href]');
      for(let i = 0, k = lnks.length; i<k ; i++){let a = hrvst.appendChild(lnks[i].cloneNode(true)); a.setAttribute('href',a.href)};
      alert(this.serializer.serializeToString(hrvst));
    },
    extendRange: function(rng,bBackward){
      var rc=rng[bBackward? 'startContainer' : 'endContainer']; if(rc.nodeType !=1){rc = rc.parentNode};
      var x=this.seekLink(rc);
      if(x && (x !== rc)){rng[bBackward? 'setStartBefore' : 'setEndAfter'](x)};
      return rng;
    },
    seekLink:function(nd){
      do{
        if(nd.matches('a[href]')){return nd};
        if(nd.matches('a')){return null};
      }while((nd = nd.parentNode) && (nd.nodeType == 1));
    }
  };
  linkHarvester.handleEvent(null);
}
Last edited by opus_27 on 2021-04-12, 22:22, edited 1 time in total.

User avatar
opus_27
Apollo supporter
Apollo supporter
Posts: 36
Joined: 2020-06-16, 13:29

Re: Is there a better way to copy multiple links?

Unread post by opus_27 » 2021-04-12, 15:36

Another glitch eliminated.

Code: Select all

javascript:{
  let linkHarvester = {
    serializer: new XMLSerializer(),
    handleEvent: function(event){
      var oSel = window.getSelection(), hldr = document.createElement('div'), hrvst = hldr.cloneNode(false),
      styl = hrvst.appendChild(document.createElement('style')); styl.setAttribute('scoped', 'scoped');
      styl.appendChild(document.createTextNode('a[href]{display:list-item; list-style-type:decimal-leading-zero;}'));
      for(let i = 0, k = oSel.rangeCount; i < k; i++){hldr.appendChild(this.extendRange(this.extendRange(oSel.getRangeAt(i), true)).cloneContents())};
      var lnks=hldr.querySelectorAll('a[href]');
      for(let i = 0, k = lnks.length; i<k ; i++){let a = hrvst.appendChild(lnks[i].cloneNode(true)); a.setAttribute('href',a.href)};
      alert(this.serializer.serializeToString(hrvst));
    },
    extendRange: function(rng,bBackward){
      var rc=rng[bBackward? 'startContainer' : 'endContainer']; if(rc.nodeType != 1){rc = rc.parentNode};
      var x=this.seekLink(rc);
      rng[bBackward? 'setStartBefore' : 'setEndAfter'](x);
      return rng;
    },
    seekLink:function(nd){
      do{
        if(nd.matches('a[href]')){return nd};
        if(nd.matches('a')){return null};
      }while((nd = nd.parentNode) && (nd.nodeType == 1));
    }
  };
  linkHarvester.handleEvent(null);
}
Last edited by opus_27 on 2021-04-12, 22:22, edited 1 time in total.

Binky

Re: Is there a better way to copy multiple links?

Unread post by Binky » 2021-04-12, 21:11

@ opus_27
Thanks for your persistent effort.

The problem I face is that I had no idea what a bookmarklet is or how to use it. I did a search that gave me some background info but no practical example of how to run it in Pale Moon on a particular web page.

User avatar
opus_27
Apollo supporter
Apollo supporter
Posts: 36
Joined: 2020-06-16, 13:29

Re: Is there a better way to copy multiple links?

Unread post by opus_27 » 2021-04-12, 22:29

Try this:
  1. For convenience, make sure your Bookmarks Toolbar is visible.
  2. Copy the contents of the CODE box below by clicking SELECT ALL just to the right of the word CODE, then press Ctrl-C or right click and select Copy.
  3. You might find it advisable to paste the code in a text file to avoid having to interrupt the bookmark creation process and start it over.
  4. Create a bookmark by right clicking on the Bookmarks Toolbar and clicking New Bookmark.
  5. In the Name box, type a name of your own choosing, preferably short to save space.
  6. In the Location Box, paste the code you copied in steps 2-3.
  7. Then click the Add (or Save) button

Code: Select all

javascript:{
  let linkHarvester = {
    serializer: new XMLSerializer(),
    handleEvent: function(event){
      var oSel = window.getSelection(), hldr = document.createElement('div'), hrvst = hldr.cloneNode(false),
      styl = hrvst.appendChild(document.createElement('style')); styl.setAttribute('scoped', 'scoped');
      styl.appendChild(document.createTextNode('a[href]{display:list-item; list-style-type:decimal-leading-zero;}'));
      for(let i = 0, k = oSel.rangeCount; i < k; i++){hldr.appendChild(this.extendRange(this.extendRange(oSel.getRangeAt(i).cloneRange(), true)).cloneContents())};
      var lnks=hldr.querySelectorAll('a[href]');
      for(let i = 0, k = lnks.length; i<k ; i++){let a = hrvst.appendChild(lnks[i].cloneNode(true)); a.setAttribute('href',a.href)};
      alert(this.serializer.serializeToString(hrvst));
    },
    extendRange: function(rng,bBackward){
      var rc=rng[bBackward? 'startContainer' : 'endContainer']; if(rc.nodeType != 1){rc = rc.parentNode};
      var x=this.seekLink(rc);
      rng[bBackward? 'setStartBefore' : 'setEndAfter'](x);
      return rng;
    },
    seekLink:function(nd){
      do{
        if(nd.matches('a[href]')){return nd};
        if(nd.matches('a')){return null};
      }while((nd = nd.parentNode) && (nd.nodeType == 1));
    }
  };
  linkHarvester.handleEvent(null);
}
Last edited by opus_27 on 2021-04-12, 23:02, edited 1 time in total.

vannilla
Moon Magic practitioner
Moon Magic practitioner
Posts: 2189
Joined: 2018-05-05, 13:29

Re: Is there a better way to copy multiple links?

Unread post by vannilla » 2021-04-12, 22:43

I also created an extension using opus_27's bookmarklet code.
It's called "Link Harvester" and I'm uploading it to various places as I'm writing this message.
Give it some time for it to be reviewed and approved and you can use it in alternative to or even side by side with the bookmarklet.

By the way:
@opus_27
I added you as a contributor to the extension. If you want to add or change or remove any info about yourself (e.g. I used the "opus_27" username as your name), just tell me.

Post-submission edit:
Since I've been programming it non-stop during the night I completely forgot to add basic informations to the XPI like a description and the likes.
I apologize to the addons team. I should probably not do an all-nighter like this.

User avatar
opus_27
Apollo supporter
Apollo supporter
Posts: 36
Joined: 2020-06-16, 13:29

Re: Is there a better way to copy multiple links?

Unread post by opus_27 » 2021-04-12, 23:05

The code needed yet another correction. I've fixed the version in my message of 2021-04-12, 18:29, and replicate the latest version here for convenience:

Code: Select all

{
  let linkHarvester = {
    serializer: new XMLSerializer(),
    handleEvent: function(event){
      var oSel = window.getSelection(), hldr = document.createElement('div'), hrvst = hldr.cloneNode(false),
      styl = hrvst.appendChild(document.createElement('style')); styl.setAttribute('scoped', 'scoped');
      styl.appendChild(document.createTextNode('a[href]{display:list-item; list-style-type:decimal-leading-zero;}'));
      for(let i = 0, k = oSel.rangeCount; i < k; i++){hldr.appendChild(this.extendRange(this.extendRange(oSel.getRangeAt(i).cloneRange(), true)).cloneContents())};
      var lnks=hldr.querySelectorAll('a[href]');
      for(let i = 0, k = lnks.length; i<k ; i++){let a = hrvst.appendChild(lnks[i].cloneNode(true)); a.setAttribute('href',a.href)};
      alert(this.serializer.serializeToString(hrvst));
    },
    extendRange: function(rng,bBackward){
      var rc=rng[bBackward? 'startContainer' : 'endContainer']; if(rc.nodeType != 1){rc = rc.parentNode};
      var x=this.seekLink(rc);
      rng[bBackward? 'setStartBefore' : 'setEndAfter'](x);
      return rng;
    },
    seekLink:function(nd){
      do{
        if(nd.matches('a[href]')){return nd};
        if(nd.matches('a')){return null};
      }while((nd = nd.parentNode) && (nd.nodeType == 1));
    }
  };
  linkHarvester.handleEvent(null);
}

User avatar
Lootyhoof
Themeist
Themeist
Posts: 1569
Joined: 2012-02-09, 23:35
Location: United Kingdom

Re: Is there a better way to copy multiple links?

Unread post by Lootyhoof » 2021-04-12, 23:40

vannilla wrote:
2021-04-12, 22:43
Post-submission edit:
Since I've been programming it non-stop during the night I completely forgot to add basic informations to the XPI like a description and the likes.
I apologize to the addons team. I should probably not do an all-nighter like this.
Thanks I think, but please submit with a valid description and such before we can approve. The site doesn't like it when there isn't a description there as it requires one.

New Tobin Paradigm

Re: Is there a better way to copy multiple links?

Unread post by New Tobin Paradigm » 2021-04-12, 23:41

Well we can delete add-ons now (though not specific versions) so inital corrections can be handled that way now.

Like everything else it is the NEED to do a thing that makes it exist plus the WILL to do it ;)

Also, I suppose the validator will need updated to check for more than existance?

vannilla
Moon Magic practitioner
Moon Magic practitioner
Posts: 2189
Joined: 2018-05-05, 13:29

Re: Is there a better way to copy multiple links?

Unread post by vannilla » 2021-04-13, 00:22

Yeah, if you can delete the unapproved submission please do so.
I'll add the required informations tomorrow first thing first I have some free time. :)

User avatar
opus_27
Apollo supporter
Apollo supporter
Posts: 36
Joined: 2020-06-16, 13:29

Re: Is there a better way to copy multiple links?

Unread post by opus_27 » 2021-04-13, 00:28

Please note my message of 2021-04-12, 19:05, vanilla. That .cloneRange() addition in line 8 is important.

Also, links with no useful text content (empty string or all whitespace) aren't yet taken care of. This should be a relatively easy fix. I'll try to post it in the next 24 hours, maybe sooner.

New Tobin Paradigm

Re: Is there a better way to copy multiple links?

Unread post by New Tobin Paradigm » 2021-04-13, 00:45

vannilla wrote:
2021-04-13, 00:22
Yeah, if you can delete the unapproved submission please do so.

Code: Select all

2021-04-13 @ 00:43:31 	mattatobin 	x.x.x.x 	[ADMIN] SUCCESS - Deleted Add-on: linkharvester

vannilla
Moon Magic practitioner
Moon Magic practitioner
Posts: 2189
Joined: 2018-05-05, 13:29

Re: Is there a better way to copy multiple links?

Unread post by vannilla » 2021-04-13, 11:56

Thank you Tobin.

I re-submitted the extension, this time hopefully without anything important missing.
opus_27 wrote:
2021-04-13, 00:28
Please note my message of 2021-04-12, 19:05, vanilla. That .cloneRange() addition in line 8 is important.
Actually due to differences between a bookmarklet and an extension, and between copying to clipboard and showing an alert, half of the code was changed so it probably does not apply.
Once the add-on is made available feel free to check it out and report any issue, if you want to.

User avatar
opus_27
Apollo supporter
Apollo supporter
Posts: 36
Joined: 2020-06-16, 13:29

Re: Is there a better way to copy multiple links?

Unread post by opus_27 » 2021-04-13, 12:26

@vanilla, please remove any reference to me from the extension.

New Tobin Paradigm

Re: Is there a better way to copy multiple links?

Unread post by New Tobin Paradigm » 2021-04-13, 14:17

opus_27 wrote:
2021-04-13, 12:26
@vanilla, please remove any reference to me from the extension.
Why? Don't you want to be credited for your contribution?

User avatar
opus_27
Apollo supporter
Apollo supporter
Posts: 36
Joined: 2020-06-16, 13:29

Re: Is there a better way to copy multiple links?

Unread post by opus_27 » 2021-04-14, 00:35

New Tobin Paradigm wrote:
2021-04-13, 14:17
opus_27 wrote:
2021-04-13, 12:26
@vanilla, please remove any reference to me from the extension.
Why? Don't you want to be credited for your contribution?
@New Tobin Paradigm: No, but thanks for your inquiry. Your interest matters to me as I've come to respect you a lot in my relatively short time here. :thumbup:

"No" is a bit of an oversimplification, as you may have guessed, but it's all I'm prepared to say in a public forum.

vannilla
Moon Magic practitioner
Moon Magic practitioner
Posts: 2189
Joined: 2018-05-05, 13:29

Re: Is there a better way to copy multiple links?

Unread post by vannilla » 2021-04-14, 07:08

Since the addon has been approved, today I'll release 1.0.2 to comply with opus_27's request.

Locked