Skip to content

Instantly share code, notes, and snippets.

@wbamberg
Created January 8, 2025 18:42
Show Gist options
  • Save wbamberg/af5981cbb0d25ae8928a240a12358660 to your computer and use it in GitHub Desktop.
Save wbamberg/af5981cbb0d25ae8928a240a12358660 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Add MDN link
// @namespace http://tampermonkey.net/
// @version 2025-01-08
// @description Add MDN links to PR preview 404 pages
// @author You
// @match https://*.content.dev.mdn.mozit.cloud/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function() {
'use strict';
function matches() {
const h1 = document.querySelector("h1");
return (
h1 &&
h1.textContent === "404 Not Found");
}
if (matches()) {
const mdnLink = document.createElement("a");
mdnLink.href = `https://developer.mozilla.org/${location.pathname}`;
mdnLink.textContent = "View on MDN";
document.body.appendChild(mdnLink);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment