Skip to content

Instantly share code, notes, and snippets.

@hcs64
Last active November 15, 2018 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hcs64/df69328d87381627e79b384bd31a6c63 to your computer and use it in GitHub Desktop.
Save hcs64/df69328d87381627e79b384bd31a6c63 to your computer and use it in GitHub Desktop.
Hide all Bugzilla comments by an author
// ==UserScript==
// @name Bugzilla hide by user
// @description Add a button to hide all comments by a user.
// @author Adam Gashlin <agashlin@mozilla.com>
// @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