Share Pastebin
Guest
Public paste!

Fanfiction link grabber

By: a guest | Mar 20th, 2010 | Syntax: JavaScript | Size: 1.61 KB | Hits: 56 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. // ==UserScript==
  2. // @name           herby
  3. // @namespace      herby
  4. // @description    testetst
  5. // @include        http://www.fanfiction.net/book/Harry_Potter/*
  6. // ==/UserScript==
  7. // ==UserScript==
  8. // @name Fanfiction.net link grabber
  9. // @include   http://www.fanfiction.net/book/*
  10. // @author    Herby Canopy
  11. // @ description Thanks for AncientSpirit, Joe Simmons and Fang
  12. // @version   1.1
  13. // ==/UserScript==
  14. // License    Public Domain
  15.  
  16. // 1) when the page is loaded it starts a time counter once it gets to that time it runs the funciotn grabber.
  17. window.addEventListener("load", function(e) {
  18. window.setTimeout(grabber, 2000);
  19. }, false);
  20.  
  21. // 2) from here down starts the function that is called by the end of the timer
  22.  
  23. function grabber(){
  24. // 3) get all links
  25.     var allLinks = document.getElementsByTagName('a');
  26.  
  27. // 4) create a new array for the links that we want
  28.     var myLinks = [];
  29.  
  30. // 5) walk through all links and add their addresses to myLinks array only if they match
  31.     for (var i = 0; i < allLinks.length; i++) {
  32.      if (allLinks[i].href.match(/\/s\/.*\/1\//)) {
  33.          myLinks.push(allLinks[i].href);
  34.       }
  35.     }
  36.  
  37. // 6) create a new div element, insert it into the document and display the links there
  38.     document.body.insertBefore(document.createElement('div'),
  39.     document.body.firstChild).innerHTML = myLinks.join('<br>');
  40. }
  41.  
  42.  
  43. // Change log
  44. // 1.1 = Thanks to Joe Simmons for the timer code
  45. // 1.0 = Thanks to AncientSpirit for the "allLinks" and myLinks ver, also the inserting of the  links to the page.  
  46. // 1.0 beta = my crappy attempt at the code of the link grabber