Last active
December 23, 2022 07:57
-
-
Save DATADEER/d422d0a08b2e2e285dfb1ddf0737f92c to your computer and use it in GitHub Desktop.
Redirects all requests to godot docs to the english / latest version (Godot 4)
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 Force Godot Docs to latest english | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description When opening the godot docs, always show the page in english and the latest version | |
// @author DATADEER | |
// @match https://docs.godotengine.org/* | |
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/Godot_icon.svg/2048px-Godot_icon.svg.png | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const url = new URL(window.location.href) | |
const path = url.pathname; | |
const pathParts = path.split("/").filter((part) => part); | |
const langCode = pathParts[0] | |
const version = pathParts[1] | |
const desiredLangCode = "en"; | |
const desiredVersion = "latest" | |
if(langCode === desiredLangCode && version === desiredVersion) return; | |
// index 0 and 1 contain language and version path part, we replace them later | |
const contentRelevantPathParts = pathParts.slice(2) | |
const newURLParts = ["en","latest", ...contentRelevantPathParts] | |
const newURLPath = `/${newURLParts.join("/")}` | |
const newURL = `${url.origin}${newURLPath}` | |
console.log(`redirecting to ${newURL}`) | |
window.location.href = newURL | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment