Last active
January 10, 2025 03:53
-
-
Save wbamberg/96987ba6656847d77f5337c1872fd61a to your computer and use it in GitHub Desktop.
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 Add MDN link | |
// @namespace http://tampermonkey.net/ | |
// @version 2025-01-08 | |
// @description Add MDN links to PR preview 404 pages | |
// @author wbamberg | |
// @match https://*.content.dev.mdn.mozit.cloud/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
"use strict"; | |
function run() { | |
const h1 = document.querySelector("h1"); | |
if ( | |
h1 && | |
( h1.textContent === "404 Not Found" || | |
h1.textContent === "Page not found" ) | |
) { | |
const mdnLink = document.createElement("a"); | |
mdnLink.href = `https://developer.mozilla.org${location.pathname}`; | |
mdnLink.textContent = "View on MDN"; | |
h1.insertAdjacentElement("afterend", mdnLink); | |
} | |
} | |
window.setTimeout(run, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment