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.

当前为 2015-12-18 提交的版本,查看 最新版本

  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.5
  6. // @exclude *saucenao.com/*
  7.  
  8. // ==/UserScript==
  9.  
  10. var links = document.links;
  11.  
  12. var isInArchive = window.location.hostname == "web.archive.org";
  13.  
  14. var specialCases = [];
  15. specialCases["https://www.youtube.com/redirect"] = "q";
  16. var skipList = ["tineye.com/search","saucenao.com/search.php","web.archive.org/web/form-submit.jsp","wayback/available", "iqdb.org","amazon.com"];
  17.  
  18. var archivePrefix = isInArchive ? /http:\/\/web\.archive\.org\/web\/\d{1,14}\//.exec(window.location.href) : "";
  19.  
  20. var observer = new MutationObserver(function(mutations) {
  21. mutations.forEach(function(mutation) {
  22. if(mutation.type == "attributes") replaceURL(mutation.target);
  23. });
  24. });
  25.  
  26. var config = { attributes: true, childList: true, characterData: true, subtree: true, attributeFilter: ["href"] };
  27. observer.observe(document.body, config);
  28.  
  29. for(var l = 0; l < links.length; l++)
  30. {
  31. if(skipList.some(elem => links[l].href.indexOf(elem) > -1)) continue;
  32. replaceURL(links[l]);
  33. }
  34.  
  35. function replaceURL(link)
  36. {
  37. var testURL = URLToObject(link.href);
  38. if(testURL == null) return;
  39. if(link.href.split("?")[1].indexOf("http") == 0)
  40. {
  41. var strippedURL = link.href.split("?")[1];
  42. while(strippedURL.indexOf("%") > -1) strippedURL = decodeURIComponent(strippedURL);
  43. link.href = strippedURL;
  44. return;
  45. }
  46. if(specialCases.hasOwnProperty(testURL.base))
  47. {
  48. link.href = archivePrefix + testURL[specialCases[testURL.base]];
  49. return;
  50. }
  51. if(testURL.hasOwnProperty("url")) link.href = archivePrefix + testURL.url;
  52. else if(testURL.hasOwnProperty("URL")) link.href = archivePrefix + testURL.URL;
  53. }
  54.  
  55. function URLToObject(url)
  56. {
  57. var URLBits = {};
  58.  
  59. var splitURL = url.split("?");
  60.  
  61. if(splitURL[1] == undefined) return null;
  62. URLBits.base = splitURL[0];
  63. var params = splitURL[1].split("&");
  64.  
  65. for(var i = 0; i < params.length; i++)
  66. {
  67. var splitParameter = params[i].split("=");
  68. if(splitParameter[1] == undefined) continue;
  69. URLBits[splitParameter[0]] = splitParameter[1];
  70. while(URLBits[splitParameter[0]].indexOf("%") > -1) URLBits[splitParameter[0]] = decodeURIComponent(URLBits[splitParameter[0]]);
  71. }
  72.  
  73. return URLBits;
  74. }

QingJ © 2025

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