22fd253b4c
Greasemonkey makes userscripts that are named so easier to install.
26 lines
870 B
JavaScript
26 lines
870 B
JavaScript
// ==UserScript==
|
|
// @name The Old New Thing link unfucker
|
|
// @version 4
|
|
// @grant none
|
|
// @match https://devblogs.microsoft.com/oldnewthing/*
|
|
// ==/UserScript==
|
|
const rewriteRules = [
|
|
[/^(http:\/\/blogs.msdn.com(\/b)?|https:\/\/devblogs.microsoft.com)\/oldnewthing\/archive\/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/[0-9]+.aspx(#.*)?$/,
|
|
'https://devblogs.microsoft.com/oldnewthing/$3$4$5-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);
|
|
}
|
|
}
|