IMDb - fix links

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

目前為 2021-04-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name         IMDb - fix links
// @namespace    https://github.com/Procyon-b
// @version      1.0
// @description  Removes all tracking info from imdb links. Keeps other parameters intact.
// @author       Achernar
// @match        https://www.imdb.com/*
// @run-at       document-body
// @grant        none
// ==/UserScript==

(function() {
"use strict";
var t;

function fix(u) {
  return u.replace('?', '?&').replace(/&(pf_rd_[a-z]|ref_)=[^&#]*/g, '').replace('?&', '?').replace(/\?$/, '');
}

if (t=location.search) {
  let s=fix(t);
  if (s!=t) history.replaceState(null, null, (s || location.pathname)+location.hash);
  }

new MutationObserver(function(mutL){
  for (let m of mutL) {
    if (m.addedNodes) fixL(m.target.querySelectorAll('a'));
    }
  }).observe(document, {childList:true, subtree:true});

function fixL(L) {
  for (let a of L) {
    if (a.LnkFixed || !a.href) continue;
    if (a.protocol && a.protocol.startsWith('http') && (a.host == 'www.imdb.com') && a.search) a.search=fix(a.search);
    if (a.pathname!=='/') a.LnkFixed=1;
    }
}

fixL(document.links)

})();