oldnewthing-link-unfucker/oldnewthing-link-unfucker.js
2024-07-30 00:58:00 +03:00

27 lines
835 B
JavaScript

// ==UserScript==
// @name The Old New Thing link unfucker
// @version 3
// @grant none
// @match https://devblogs.microsoft.com/oldnewthing/*
// ==/UserScript==
const rewriteRules = [
[/^http:\/\/blogs.msdn.com(\/b)?\/oldnewthing\/archive\/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/[0-9]+.aspx(#.*)?$/,
'https://devblogs.microsoft.com/oldnewthing/$2$3$4-00/'],
[/^https:\/\/blogs.msdn.microsoft.com\//,
'https://devblogs.microsoft.com/'],
];
for (const link of document.getElementsByTagName('a')) {
let target = link.href;
if (target === '') {
continue;
}
for (const [regex, replacement] of rewriteRules) {
target = target.replace(regex, replacement);
}
if (target !== link.href) {
link.href = target;
link.parentNode.insertBefore(document.createTextNode('𝌡'), link.nextSibling);
}
}