Skip to content

Instantly share code, notes, and snippets.

@bindreams
Last active July 4, 2024 19:07
Show Gist options
  • Save bindreams/9e21b772b637855030762090bd45361b to your computer and use it in GitHub Desktop.
Save bindreams/9e21b772b637855030762090bd45361b to your computer and use it in GitHub Desktop.
Tampermonkey: Redirect Qt5 docs to Qt6 docs
// ==UserScript==
// @name Redirect Qt5 docs to Qt6 docs
// @version 1.0.1
// @author bindreams
// @match https://doc.qt.io/qt-5/*
// @run-at document-start
// @grant none
// ==/UserScript==
// Check if a url returns 404. Return true if url does not return 404.
function urlExists(url) {
var req = new XMLHttpRequest();
req.open('HEAD', url, false);
req.send();
return (req.status != 404);
}
var reSuffix = /qt-5\/([\s\S]*)/;
// If regex finds an expected suffix and a matching page on qt-6 exists, redirect
var result = reSuffix.exec(location.pathname);
if (result !== null) {
var suffix = result[1];
var url = 'https://doc.qt.io/qt-6/' + suffix;
if (urlExists(url)) location.replace(url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment