IMDb - fix links

Removes all tracking info from imdb links. Keeps other parameters intact.

当前为 2021-04-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name IMDb - fix links
  3. // @namespace https://github.com/Procyon-b
  4. // @version 1.0.1
  5. // @description Removes all tracking info from imdb links. Keeps other parameters intact.
  6. // @author Achernar
  7. // @match https://www.imdb.com/*
  8. // @run-at document-body
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. "use strict";
  14. var t;
  15.  
  16. function fix(u) {
  17. return u.replace('?', '?&').replace(/&(pf_rd_[a-z]|ref_)=[^&#]*/g, '').replace('?&', '?').replace(/\?$/, '');
  18. }
  19.  
  20. if (t=location.search) {
  21. let s=fix(t);
  22. if (s!=t) history.replaceState(null, null, (s || location.pathname)+location.hash);
  23. }
  24.  
  25. new MutationObserver(function(mutL){
  26. for (let m of mutL) {
  27. if (m.addedNodes) fixL(m.target.querySelectorAll('a'));
  28. }
  29. }).observe(document, {childList:true, subtree:true});
  30.  
  31. function fixL(L) {
  32. for (let a of L) {
  33. if (a.LnkFixed || !a.href) continue;
  34. if (a.protocol && a.protocol.startsWith('http') && a.host.endsWith('imdb.com') && a.search) a.search=fix(a.search);
  35. if (a.pathname!=='/') a.LnkFixed=1;
  36. }
  37. }
  38.  
  39. fixL(document.links)
  40.  
  41. })();