25 lines
746 B
JavaScript
25 lines
746 B
JavaScript
|
// ==UserScript==
|
|||
|
// @name The Old New Thing link unfucker
|
|||
|
// @version 1
|
|||
|
// @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/$1$2$3-00/'],
|
|||
|
];
|
|||
|
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|