Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 05, 2016, 06:36:54 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: DONE: Copy selection on webpage as text with text hyperlink URL's and ASCIIart  (Read 15049 times)

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,474
    • View Profile
    • Donate to Member
After a little fooling around with GreaseMonkey and some outright butchery of a few userscripts, I've come up with something guaranteed to turn any sane website into a masterpiece of confusion.

Using the AutoHK site you gave above as an example, you'll get:

2011-03-30_15-16-32.jpg

Code: Javascript [Select]
  1. // ==UserScript==
  2. // @name          TextLink
  3. // @namespace    
  4. // @description   Append text link after clickable link
  5. // @include       http://*
  6. // @include       https://*
  7. // @exclude       http://192.168.0.*
  8. // ==/UserScript==
  9.  
  10. var links, link;
  11. links = document.evaluate(
  12.    '//a[@href]',
  13.    document,
  14.    null,
  15.    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  16.    null);
  17.  
  18. var re_http  = new RegExp("^http.*:\/\/");
  19. var re_mail = new RegExp("^mailto:");
  20. var re_ftp = new RegExp("^ftp.*:\/\/");
  21. for (var i = 0; i < links.snapshotLength; i++) {
  22.    a = links.snapshotItem(i);
  23.  
  24.    if(a.href.match(re_http)) {
  25.       newDiv = document.createElement('text');
  26.       a.parentNode.insertBefore(newDiv, a.nextSibling);
  27.       newDiv.innerHTML = "&nbsp;[" + a + "]";
  28.    }
  29.    if(a.href.match(re_mail)) {
  30.       newDiv = document.createElement('text');
  31.       a.parentNode.insertBefore(newDiv, a.nextSibling);
  32.       newDiv.innerHTML = "&nbsp;[" + a + "]";
  33.    }
  34.    if(a.href.match(re_ftp)) {
  35.       newDiv = document.createElement('text');
  36.       a.parentNode.insertBefore(newDiv, a.nextSibling);
  37.       newDiv.innerHTML = "&nbsp;[" + a + "]";
  38.    }
  39. }

Save as TextLink.user.js - unless you have another called that, in which case save it as something else and change the name on the @name line.  Then just drop it on the Firefox window, if GreaseMonkey is installed it should recognise and install it.

I've only tested it on a couple of sites and I have no idea if what I've done follows Good Programming Guidelines but hey, what do expect for 30 minutes of completely unintelligent, uneducated keyboard tapping.

I'd recommend you leave it disabled until you're on a site you want to copy text from, then enable it and refresh ;)
« Last Edit: March 30, 2011, 12:19:41 AM by 4wd, Reason: Fix the mailto: address RegExp »

Nater

  • Participant
  • Joined in 2011
  • *
  • Posts: 13
    • View Profile
    • Donate to Member
This works!  Awesome :up: 

I hope others can find this useful.

I have tried it out and it works great.  The only improvement I can think of for it would be to also recognize email addresses that are linked, but I am happy the way it is! 

THANK YOU 4wd!!!!!


skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
Nice work, 4wd.  Well done.   :D

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,474
    • View Profile
    • Donate to Member
This works!  Awesome :up: 

Thanks!

Quote
I have tried it out and it works great.  The only improvement I can think of for it would be to also recognize email addresses that are linked, but I am happy the way it is!

Stupid me, mailto addresses don't have // on the end, just edit it to change:

var re_mail = new RegExp("^mailto:\/\/");

to:

var re_mail = new RegExp("^mailto:");

and that should take care of it.

Nice work, 4wd.  Well done.   :D

Well, I wouldn't call it exactly 'nice' since I don't know if Element type of 'text' actually exists, that was just a guess on my part.  When it worked I stopped looking for the 'legal' method  ;D

Thanks skwire.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
Well, I wouldn't call it exactly 'nice' since I don't know if Element type of 'text' actually exists, that was just a guess on my part.  When it worked I stopped looking for the 'legal' method

Whenever the OP says, "This works!  Awesome  :up:," well, that's nice work.   :D

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,474
    • View Profile
    • Donate to Member
Does that mean I get the coveted csnacks badge ?

 ;)

Nater

  • Participant
  • Joined in 2011
  • *
  • Posts: 13
    • View Profile
    • Donate to Member
var re_mail = new RegExp("^mailto:\/\/");

to:

var re_mail = new RegExp("^mailto:");

Updated and works with email now too.  Thanks!

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
Does that mean I get the coveted csnacks badge ?

Absolutely.  =]

Nater

  • Participant
  • Joined in 2011
  • *
  • Posts: 13
    • View Profile
    • Donate to Member
skwire - thanks for your AHK script.  Though your script was not what I originally had in mind, I can use it with 4wd's greasemonkey user script and get even more functionality than I had originally bargained for.

I ended up getting 2 snacks for the price of one.

 

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
skwire - thanks for your AHK script.  Though your script was not what I originally had in mind, I can use it with 4wd's greasemonkey user script and get even more functionality than I had originally bargained for.

You're welcome.  I figured you would use both in conjunction.

I ended up getting 2 snacks for the price of one.

Gotta love a bargain.   :P

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,474
    • View Profile
    • Donate to Member
Does that mean I get the coveted csnacks badge ?

Absolutely.  =]

Cool!   Next stop the SuperBoy badge  :P