Last active
May 12, 2022 18:03
-
-
Save multun/9e0693af621cd5e7cb031f8cff265b6e to your computer and use it in GitHub Desktop.
zenhub SAFe bullshitizer
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 SAFe bullshitizer | |
// @version 1 | |
// @grant none | |
// @include https://app.zenhub.com/* | |
// @include https://github.com/* | |
// ==/UserScript | |
console.log("starting replacement script"); | |
var replacements = { | |
"epic": "feature", | |
"Epic": "Feature", | |
"milestone": "iteration", | |
"Milestone": "Iteration", | |
}; | |
var fixupText = function(text) { | |
for (var original in replacements) | |
text = text.replace(original, replacements[original]); | |
return text; | |
} | |
var fixupAttr = function(node, attrName) { | |
var attr = node.getAttributeNode(attrName); | |
if (attr === null) | |
return; | |
var newText = fixupText(attr.nodeValue); | |
if (newText != attr.nodeValue) | |
attr.nodeValue = newText; | |
} | |
var fixupNode = function(node) { | |
if (node.nodeType == Node.TEXT_NODE) { | |
var newText = fixupText(node.data); | |
if (newText != node.data) | |
node.data = newText; | |
} else if (node.nodeType == Node.ELEMENT_NODE) { | |
fixupAttr(node, "placeholder"); | |
} | |
} | |
var fixupTree = function(node) { | |
if (node.nodeType == Node.ELEMENT_NODE && node.isContentEditable) { | |
console.log("skipping content-editable", node); | |
return; | |
} | |
if (node.parentNode !== null) { | |
if (node.parentNode.nodeName == "HEAD") | |
return; | |
if (node.parentNode.nodeName == "STYLE") | |
return; | |
} | |
fixupNode(node); | |
if (node.childNodes === null) | |
return; | |
for (var i = 0; i < node.childNodes.length; i++) | |
fixupTree(node.childNodes[i]); | |
} | |
var observeDOM = (function() { | |
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; | |
return function(obj, callback) { | |
if (!obj || obj.nodeType !== 1) return; | |
if (MutationObserver) { | |
// define a new observer | |
var mutationObserver = new MutationObserver(callback) | |
// have the observer observe foo for changes in children | |
mutationObserver.observe(obj, { | |
childList: true, | |
subtree: true | |
}) | |
return mutationObserver | |
} | |
// browser support fallback | |
else if (window.addEventListener) { | |
obj.addEventListener('DOMNodeInserted', callback, false) | |
obj.addEventListener('DOMNodeRemoved', callback, false) | |
} | |
} | |
})() | |
var onDomChange = function(changes) { | |
try { | |
console.log("dom changed"); | |
var addedNodes = []; | |
changes.forEach(record => record.addedNodes.length & addedNodes.push(...record.addedNodes)) | |
console.log('Added:', addedNodes); | |
for (const node of addedNodes) { | |
fixupTree(node) | |
} | |
} catch (e) { | |
console.log("ERROR IN DOMCHANGE HOOK", e) | |
} | |
} | |
// Observe a specific DOM element: | |
observeDOM(document.documentElement, onDomChange); | |
console.log("hooking complete"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment