27 lines
832 B
JavaScript
27 lines
832 B
JavaScript
// ==UserScript==
|
||
// @name The Old New Thing link unfucker
|
||
// @version 2
|
||
// @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/'],
|
||
[/^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);
|
||
}
|
||
}
|