Removes all tracking info from imdb links. Keeps other parameters intact.
当前为
// ==UserScript==
// @name IMDb - fix links
// @namespace https://github.com/Procyon-b
// @version 1.1
// @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(/\?$/, '');
}
function normalizeLnk(a) {
if (location.pathname.endsWith('/bio') || location.pathname.startsWith('/title/')) {
if (/^\/(name|title)\/[^\/]+$/.test(a.pathname)) a.pathname+='/';
}
}
if (t=location.search) {
let s=fix(t);
if (s!=t) history.replaceState(null, null, (s || location.pathname)+location.hash);
}
function fixL(L, j=0) {
let i=0, a, S=Date.now()+200;
for (;a=L[j];j++) {
if (a.LnkFixed || !a.href) continue;
if (Date.now() > S) {
setTimeout(function(){fixL(L,j)},0);
return;
}
if (a.protocol && a.protocol.startsWith('http') && a.host.endsWith('imdb.com') && a.search) {
let s=fix(a.search);
if (a.search != s) a.search=s;
normalizeLnk(a);
}
if (a.pathname!=='/') a.LnkFixed=1;
}
}
window.addEventListener('load', function(){fixL(document.links)});
document.addEventListener('DOMContentLoaded', init);
function init() {
new MutationObserver(function(mutL){
for (let m of mutL) {
if (m.addedNodes) {
let e=m.target.querySelectorAll(':scope a');
if (e.length) fixL(e);
}
}
}).observe(document, {childList:true, subtree:true});
fixL(document.links);
}
fixL(document.links);
})();