oldnewthing-link-unfucker/oldnewthing-link-unfucker.js

27 lines
835 B
JavaScript
Raw Permalink Normal View History

2024-07-29 21:27:01 +00:00
// ==UserScript==
// @name The Old New Thing link unfucker
// @version 3
2024-07-29 21:27:01 +00:00
// @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/'],
2024-07-29 21:27:01 +00:00
];
for (const link of document.getElementsByTagName('a')) {
let target = link.href;
if (target === '') {
continue;
}
2024-07-29 21:39:18 +00:00
for (const [regex, replacement] of rewriteRules) {
2024-07-29 21:27:01 +00:00
target = target.replace(regex, replacement);
}
if (target !== link.href) {
link.href = target;
link.parentNode.insertBefore(document.createTextNode('𝌡'), link.nextSibling);
}
}