Last active
January 2, 2020 05:57
-
-
Save xanderlent/b60c3e9c8b2d1946a7e425e6b12355d1 to your computer and use it in GitHub Desktop.
Rewrites internal JIRA links on the Joyent Gerrit instance to public bugview links
This file contains 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 Joyent Gerrit Bug Link Rewriter | |
// @namespace https://gist.github.com/xanderlent/b60c3e9c8b2d1946a7e425e6b12355d1 | |
// @include https://cr.joyent.us/ | |
// @version 0.1 | |
// @description Rewrites internal JIRA links on the Joyent Gerrit instance to public bugview links | |
// @author Alexander Lent | |
// @match https://addons.mozilla.org/en-US/firefox/addon/tampermonkey/ | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Rewrite links of the form https://devhub.joyent.com/jira/browse/TRITON-1217 to https://smartos.org/bugview/TRITON-1217 | |
function rewrite_links () { | |
console.log("Running Joyent CR bug link rewriter!"); | |
for (var tag of document.getElementsByTagName("a")) { | |
if (tag.hostname === "devhub.joyent.com") { | |
var path_components = tag.pathname.split('/'); | |
if (path_components[0] === "" && | |
path_components[1] === "jira" && | |
path_components[2] === "browse" && | |
path_components.length === 4) { | |
var bug_name = path_components[3]; | |
var new_pathname = "/bugview/" + bug_name; | |
tag.hostname = "smartos.org"; | |
tag.pathname = new_pathname; | |
console.log("Joyent CR Link Rewriter rewrote a link!"); | |
// TODO: Fetch bugview links and disable non-public links! | |
// This will require using @connect and GM_xmlhttpRequest | |
} | |
} | |
} | |
} | |
console.log("Joyent CR Link Rewriter installing handler!"); | |
document.addEventListener("DOMNodeInserted", rewrite_links); | |
console.log("Joyent CR Link Rewriter installed rewriter!"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was a little experiment I wrote a few months ago because I was tired of accidentally clicking on non-public links when browsing Joyent's Gerrit instance. It's no longer relevant since cr.joyent.us seems to have been shut down.