URL Stripper

Takes offsite links that stick the original URL into an onsite link with extra parameters and changes the href to that original URL.

当前为 2016-01-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name URL Stripper
  3. // @namespace DoomTay
  4. // @description Takes offsite links that stick the original URL into an onsite link with extra parameters and changes the href to that original URL.
  5. // @version 1.1.6
  6. // @exclude *iqdb.org/*
  7. // @exclude *saucenao.com/*
  8.  
  9. // ==/UserScript==
  10.  
  11. var links = document.links;
  12.  
  13. var isInArchive = window.location.hostname == "web.archive.org";
  14.  
  15. var specialCases = [];
  16. specialCases["https://www.youtube.com/redirect"] = "q";
  17. specialCases["http://www.amazon.com/exec/obidos"] = "path";
  18. specialCases["http://t.umblr.com/redirect"] = "z";
  19. var blacklist = ["tineye.com/search","saucenao.com/search.php","web.archive.org/web/form-submit.jsp","wayback/available","iqdb.org","amazon.com","smashbros.com/wii/en_us/notify.html","multiez.com"];
  20.  
  21. var archivePrefix = isInArchive ? /http:\/\/web\.archive\.org\/web\/\d{1,14}\//.exec(window.location.href) : "";
  22.  
  23. var observer = new MutationObserver(function(mutations) {
  24. mutations.forEach(function(mutation) {
  25. if(mutation.type == "attributes") replaceURL(mutation.target);
  26. });
  27. });
  28.  
  29. var config = { attributes: true, childList: true, characterData: true, subtree: true, attributeFilter: ["href"] };
  30. observer.observe(document.body, config);
  31.  
  32. for(var l = 0; l < links.length; l++)
  33. {
  34. if(blacklist.some(elem => links[l].href.indexOf(elem) > -1)) continue;
  35. replaceURL(links[l]);
  36. }
  37.  
  38. function replaceURL(link)
  39. {
  40. var testURL = URLToObject(link.href);
  41. if(testURL == null) return;
  42. if(link.href.substring(link.href.indexOf("?") + 1).indexOf("http") == 0)
  43. {
  44. var strippedURL = link.href.substring(link.href.indexOf("?") + 1);
  45. while(strippedURL.indexOf("%") > -1) strippedURL = decodeURIComponent(strippedURL);
  46. link.href = archivePrefix + strippedURL;
  47. return;
  48. }
  49. if(specialCases.hasOwnProperty(testURL.base))
  50. {
  51. link.href = archivePrefix + testURL[specialCases[testURL.base]];
  52. return;
  53. }
  54. if(testURL.hasOwnProperty("url")) link.href = archivePrefix + testURL.url;
  55. else if(testURL.hasOwnProperty("URL")) link.href = archivePrefix + testURL.URL;
  56. }
  57.  
  58. function URLToObject(url)
  59. {
  60. var URLBits = {};
  61.  
  62. var splitURL = url.split("?");
  63.  
  64. if(splitURL[1] == undefined) return null;
  65. URLBits.base = splitURL[0];
  66. var params = splitURL[1].split("&");
  67.  
  68. for(var i = 0; i < params.length; i++)
  69. {
  70. var splitParameter = params[i].split("=");
  71. if(splitParameter[1] == undefined) continue;
  72. URLBits[splitParameter[0]] = splitParameter[1];
  73. while(URLBits[splitParameter[0]].indexOf("%") > -1) URLBits[splitParameter[0]] = decodeURIComponent(URLBits[splitParameter[0]]);
  74. }
  75.  
  76. return URLBits;
  77. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址