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-11-26 提交的版本,查看 最新版本

  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.0
  6. // @grant GM_xmlhttpRequest
  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 = ["http://tineye.com/search","http://saucenao.com/search.php","http://web.archive.org/web/form-submit.jsp","wayback/available"];
  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.attributeName == "href") replaceURL(mutation.target);
  23. });
  24. });
  25. var config = { attributes: true, childList: true, characterData: true };
  26.  
  27. for(var l = 0; l < links.length; l++)
  28. {
  29. if(skipList.some(elem => links[l].href.indexOf(elem) > -1)) continue;
  30. observer.observe(links[l], config);
  31. replaceURL(links[l]);
  32. }
  33.  
  34. function replaceURL(link)
  35. {
  36. var testURL = URLToObject(link.href);
  37. if(testURL == null) return;
  38. if(specialCases.hasOwnProperty(testURL.base))
  39. {
  40. link.href = archivePrefix + testURL[specialCases[testURL.base]];
  41. return;
  42. }
  43. if(testURL.hasOwnProperty("url")) link.href = archivePrefix + testURL.url;
  44. else if(testURL.hasOwnProperty("URL")) link.href = archivePrefix + testURL.URL;
  45. }
  46.  
  47. function URLToObject(url)
  48. {
  49. var URLBits = {};
  50.  
  51. var splitURL = url.split("?");
  52.  
  53. if(splitURL[1] == undefined) return null;
  54. URLBits.base = splitURL[0];
  55. var params = splitURL[1].split("&");
  56.  
  57. for(var i = 0; i < params.length; i++)
  58. {
  59. var splitParameter = params[i].split("=");
  60. URLBits[splitParameter[0]] = decodeURIComponent(splitParameter[1]);
  61. }
  62.  
  63. return URLBits;
  64. }

QingJ © 2025

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