Add MediaWiki Redirects Fixer

This commit is contained in:
blankie 2023-11-07 22:20:01 +11:00
parent 148f9eb43d
commit 2f94174353
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,46 @@
// ==UserScript==
// @name MediaWiki Redirects Fixer
// @namespace blankie-scripts
// @match https://*.wikipedia.org/*
// @grant none
// @version 1.0.0
// @author blankie
// @description Fixes redirects of pages with anchors on Wikipedia/MediaWiki instances when Javascript is disabled
// @inject-into content
// @run-at document-end
// ==/UserScript==
"use strict";
function scrollToHash(scrollTo) {
if (!scrollTo) {
return;
}
let element = document.querySelector(scrollTo);
if (element) {
element.scrollIntoView();
}
}
for (let script of document.querySelectorAll("script")) {
let match = /;RLCONF=({"[\s\S]+?});RLSTATE={"/.exec(script.textContent);
if (!match) {
continue;
}
let rlconf = JSON.parse(match[1]);
if (rlconf.wgInternalRedirectTargetUrl) {
let url = new URL(rlconf.wgInternalRedirectTargetUrl, location);
let scrollTo = url.hash;
if (location.hash) {
url.hash = location.hash;
scrollTo = null;
}
history.replaceState(null, "", url);
scrollToHash(scrollTo);
}
break;
}

View File

@ -87,6 +87,11 @@ elements
Removes image loading placeholders from images loaded via Javascript, such as Removes image loading placeholders from images loaded via Javascript, such as
https://closeronline.co.uk, https://wired.com, and https://knowyourmeme.com. https://closeronline.co.uk, https://wired.com, and https://knowyourmeme.com.
## MediaWiki Redirects Fixer
Fixes redirects of pages with anchors on Wikipedia/MediaWiki instances when
Javascript is disabled
## nightly.link buttons ## nightly.link buttons
A script to add [nightly.link](https://nightly.link) buttons on artifacts and A script to add [nightly.link](https://nightly.link) buttons on artifacts and