Random Link Follower

This userscript follows random links after a specified delay (Variable delaySeconds). It is intended to be used in conjunction with my Internet Archive Saver script (But keep in mind: Internet Archive will maybe ban your IP if you save too much pages in little time). However, it can also be used for fun, to see where the links take you.

  1. // ==UserScript==
  2. // @name Random Link Follower
  3. // @description This userscript follows random links after a specified delay (Variable delaySeconds). It is intended to be used in conjunction with my Internet Archive Saver script (But keep in mind: Internet Archive will maybe ban your IP if you save too much pages in little time). However, it can also be used for fun, to see where the links take you.
  4. // @namespace https://greasyfork.org/de/users/160920-flo-pinguin
  5. // @author FloPinguin
  6. // @icon https://i.ibb.co/gth30Hk/random-1294119.png
  7. // @version 1.0
  8. // @match *://*/*
  9. // @grant GM_xmlhttpRequest
  10. // @connect *
  11. // ==/UserScript==
  12. var delaySeconds = 15;
  13. setTimeout(function(){
  14. openLink(document.querySelectorAll("a[href]"));
  15. }, delaySeconds * 1000);
  16. setTimeout(function(){
  17. window.history.back();
  18. }, delaySeconds * 3 * 1000);
  19. function openLink(linkElements){
  20. if (linkElements.length) {
  21. var linkElement = linkElements[getRandomInt(0, linkElements.length - 1)];
  22. var link = linkElement.getAttribute('href');
  23. if (link != "" && !link.includes("#") && !link.includes(".xml")){
  24. GM_xmlhttpRequest({
  25. method: 'GET',
  26. url: link,
  27. onload: function(data){
  28. if (data.status == 200 && data.responseText.includes('<a') && data.responseText.includes(' href')){
  29. console.log("Suitable link found! Redirection to " + link);
  30. location.href = link;
  31. }else{
  32. console.log(link + " doesn't fit the requirements. Looking for a better link...");
  33. openLink(linkElements);
  34. }
  35. },
  36. onerror: function(){
  37. console.log("Failed to load " + link + ". Looking for another link...");
  38. openLink(linkElements);
  39. }
  40. });
  41. }else{
  42. console.log("Link " + link + " is invalid. Looking for another one...");
  43. openLink(linkElements);
  44. }
  45. }else{
  46. console.error("Random Link Follower: No link found!");
  47. window.history.back();
  48. }
  49. }
  50. function getRandomInt(min, max){
  51. return Math.floor(Math.random() * (max - min + 1)) + min;
  52. }