Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.