Skip to content

Instantly share code, notes, and snippets.

@DownRangeDevOps
Created October 1, 2012 05:42
Show Gist options
  • Save DownRangeDevOps/3809675 to your computer and use it in GitHub Desktop.
Save DownRangeDevOps/3809675 to your computer and use it in GitHub Desktop.
Kayako, collapse all departments
// ==UserScript==
// @name Kayako Collapse All
// @namespace https://gist.github.com
// @version 0.1
// @include http://imatrixsupport.com/staff/index.php*
// @grant Sandbox
// ==/UserScript==
// Licensed under the MIT license: http://opensource.org/licenses/MIT
// Enable or disable GreaseMonkey function, GM_log
var GM_Debug = 0;
// Access jQuery as loaded by Kayako
var $ = unsafeWindow.jQuery;
if (!GM_Debug) {
var GM_log = function() {
};
}
// If FireBig is active, send GM log events to FB.
if (unsafeWindow.console && GM_Debug) {
var GM_log = unsafeWindow.console.log;
}
GM_log("Running collapse kayako response script"); // Debug
// Don't run on frames or iframes.
if (window.top !== window.self) {
return;
}
window.onload = addDepIcon;
function addDepIcon() {
var curElement = $('#itemoptionsnav').find('navtitle').first();
var p = document.createElement('p');
var a = document.createElement('a');
GM_log("Node: " + curElement.className); // Debug
styleLink(a);
styleParagraph(p);
p.appendChild(a);
p.appendChild(span);
a.appendChild(document.createTextNode('-'));
a.addEventListener("click", toggle, false);
curElement.parentNode.insertBefore(p, curElement);
GM_log("Inserting element"); // Debug
function toggle(e) {
if (this.firstChild.nodeValue === '-') {
this.parentNode.nextSibling.style.display = 'none';
this.firstChild.nodeValue = '+';
this.nextSibling.style.display = 'inline';
} else {
this.parentNode.nextSibling.style.display = 'block';
this.firstChild.nodeValue = '-';
this.nextSibling.style.display = 'none';
}
e.preventDefault();
}
function styleLink(a) {
a.href = '#';
a.style.fontWeight = 'bold';
a.style.background = '#F6F1E7';
a.style.border = '1px solid #cccccc';
a.style.color = '#B24C58';
a.style.textDecoration = 'none';
a.style.width = '15px';
a.style.height = '15px';
a.style.textAlign = 'center';
a.style.fontSize = '100%';
a.style.margin = '0 5px 5px 8px';
a.style.cssFloat = 'left';
a.style.display = 'block';
a.style.lineHeight = '13px';
}
function styleParagraph(p) {
p.style.margin = '0 0 0 0';
p.style.lineHeight = '16px';
p.style.clear = 'both';
p.style.height = '15px';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment