Skip to content

Instantly share code, notes, and snippets.

@eqvinox
Last active March 29, 2024 07:26
Show Gist options
  • Select an option

  • Save eqvinox/37d0dc7d9a2f6d71a026aafcc88d2619 to your computer and use it in GitHub Desktop.

Select an option

Save eqvinox/37d0dc7d9a2f6d71a026aafcc88d2619 to your computer and use it in GitHub Desktop.
Greasemonkey script to fold open zammad ticket items by default
// ==UserScript==
// @name Zammad ticket items expand-by-default
// @match https://requests.cccv.de/*
// @version 1
// @grant none
// ==/UserScript==
let seen_before = new Set();
function direct_text(parent) {
/* get direct text content of this node */
let rv = new Array();
for (const node of parent.childNodes) {
if (node.nodeType !== node.TEXT_NODE)
continue;
let text = node.textContent.trim();
if (text === "")
continue;
rv.push(text);
}
return rv.join(" ");
}
function fold_open() {
/* need to re-run this because zammad will dynamically reload when you go to another ticket */
setTimeout(fold_open, 250);
let items = document.getElementsByClassName("ticket-article-item");
for (let item of items) {
/* only touch items once, so you can still close things manually */
if (seen_before.has(item))
continue;
seen_before.add(item);
/* click on it to show the fold-out headers... */
if (!item.classList.contains("state--folde-out")) {
console.log("folding open:", item);
item.getElementsByClassName("textBubble")[0].click();
}
/* different style for mails */
for (let meta of item.getElementsByClassName("article-meta-row")) {
let key = meta.getElementsByClassName("article-meta-key")[0].textContent;
let value = direct_text(meta.getElementsByClassName("article-meta-value")[0]);
if (key === "Channel")
item.classList.add("channel-".concat(value));
}
}
}
fold_open();
function add_css(rules) {
const head = document.getElementsByTagName('head')[0];
if (!head)
return;
let style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = rules;
head.appendChild(style);
}
add_css(".channel-email .article-meta { background: hsl(150, 42%, 23%); }");
add_css(".article-meta.bottom { background: var(--background-quaternary-alt); color: var(--text-muted-alt); }");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment