Last active
November 15, 2018 18:08
-
-
Save hcs64/df69328d87381627e79b384bd31a6c63 to your computer and use it in GitHub Desktop.
Hide all Bugzilla comments by an author
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 Bugzilla hide by user | |
// @description Add a button to hide all comments by a user. | |
// @author Adam Gashlin <[email protected]> | |
// @version 4 | |
// @grant none | |
// @match https://bugzilla.mozilla.org/* | |
// ==/UserScript== | |
function quoteCssString(s) { | |
return ('"' | |
+ (s.replace(RegExp('\\\\', 'g'), '\\\\') | |
.replace(RegExp('"', 'g'), '\\"') | |
.replace(RegExp('\n', 'g'), '\\n')) | |
+ '"'); | |
} | |
function hideCommentsByEmail(email) { | |
const selector = 'td.change-author a.email[href=' + quoteCssString(email) + ']'; | |
for (const cs of document.getElementsByClassName('change-set')) { | |
if (cs.querySelector(selector)) { | |
cs.style.setProperty('display', 'none'); | |
//cs.querySelector('button.change-spinner').click(); | |
} | |
} | |
} | |
function unHideAll() { | |
for (const cs of document.getElementsByClassName('change-set')) { | |
if (cs.style.getPropertyValue('display') == 'none') { | |
cs.style.removeProperty('display'); | |
} | |
} | |
} | |
function onClickHide(event, cs) { | |
event.preventDefault(); | |
const emailTag = cs.querySelector('td.change-author a.email'); | |
if (emailTag) { | |
const profileEmail = emailTag.getAttribute('href'); | |
if (profileEmail) { | |
hideCommentsByEmail(profileEmail); | |
} | |
} | |
} | |
// add hide buttons | |
for (let cs of document.getElementsByClassName('change-set')) { | |
const act = cs.querySelector('td.comment-actions'); | |
if (act) { | |
if (!cs.querySelector('button.minus-minus-hack')) { | |
const b = document.createElement('button'); | |
b.className = 'minor minus-minus-hack'; | |
b.appendChild(document.createTextNode('--')); | |
b.addEventListener('click', (event) => onClickHide(event, cs)); | |
act.appendChild(b); | |
} | |
} | |
} | |
// add reset listener | |
const reset = document.getElementById('view-reset'); | |
if (reset) { | |
reset.addEventListener('click', unHideAll); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment