From d9eb4dfd988a35a57c7d533db35d780d7b997b4d Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Fri, 25 Jul 2025 23:21:05 -0400 Subject: [PATCH] Initial commit of 'The Old New Thing URL Rewriter' --- oldnewthing/oldnewthing.js | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 oldnewthing/oldnewthing.js diff --git a/oldnewthing/oldnewthing.js b/oldnewthing/oldnewthing.js new file mode 100644 index 0000000..893cfc0 --- /dev/null +++ b/oldnewthing/oldnewthing.js @@ -0,0 +1,51 @@ +// ==UserScript== +// @name The Old New Thing URL Rewriter +// @author Michael Becker +// @version 1 +// @grant none +// @include https://devblogs.microsoft.com/oldnewthing/* +// ==/UserScript== + +var config = { + "patterns": [ + { + "find": "blogs.msdn.microsoft.com", + "replaceWith": "devblogs.microsoft.com" + }, + { + "find": "blogs.msdn.com/b/oldnewthing/archive", + // "redirectTo": "https://web.archive.org/*/http://%1" + redirectTo: function (originalUrl) { + var parts = originalUrl.split('/'); + if (parts.length > 8) { + var datetime = parts[6] + parts[7] + parts[8]; + return "https://web.archive.org/web/" + datetime + "000000/" + originalUrl; + } + return originalUrl; + } + } + ] +} + +window.addEventListener("load", function() +{ + var links = document.getElementsByTagName("A"); + console.log(links.length + " links found"); + for (var i = 0; i < links.length; i++) + { + for (var j = 0; j < config.patterns.length; j++) { + if (links[i].href.indexOf(config.patterns[j].find) !== -1) { + if (typeof (config.patterns[j].replaceWith) === 'string') { + links[i].href = links[i].href.replace(config.patterns[j].find, config.patterns[j].replaceWith); + } + else if (typeof (config.patterns[j].redirectTo) === 'string') { + links[i].href = config.patterns[j].redirectTo.replace('%1', links[i].href); + } + else if (typeof (config.patterns[j].redirectTo) === 'function') { + links[i].href = config.patterns[j].redirectTo(links[i].href); + } + } + } + } + +});