Created
February 10, 2025 16:42
-
-
Save g0t4/8178970fd7c017a53d7cc55104d0c6f5 to your computer and use it in GitHub Desktop.
redirect to "current" postgres version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name postgres redirect to current version | |
// @namespace http://tampermonkey.net/ | |
// @version 2025-02-10 | |
// @match https://www.postgresql.org/docs/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=postgresql.org | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// right now I don't need older versions, I'd prefer to always see latest so lets redirect automatically | |
// example: | |
// https://www.postgresql.org/docs/current/monitoring-stats.html | |
// https://www.postgresql.org/docs/16/monitoring-stats.html | |
// https://www.postgresql.org/docs/9.4/functions-matching.html | |
// so, major \d\d, or major.minor \d.\d | |
const href = window.location.href; | |
const specific_version = /docs\/\d+(\.\d)*/; // i.e. docs/9.1 or docs/16 | |
if(!href.match(specific_version)){ | |
return; | |
} | |
console.log(`redirecting to current postgres docs\nfrom: ${window.location.href}`); | |
const redirect_to = window.location.href.replace(specific_version, "docs/current"); | |
console.log(`redirecting to: ${redirect_to}`); | |
window.location.href = redirect_to; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment