Last active
March 4, 2020 11:20
-
-
Save kosiew/79d1125398ce9883da1dc055171d467e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Zendesk Plus | |
// @namespace https://wpcomhappy.wordpress.com/ | |
// @icon https://raw.githubusercontent.com/soufianesakhi/feedly-filtering-and-sorting/master/web-ext/icons/128.png | |
// @version 1.0 | |
// @description Tool for enhancing Zendesk | |
// @author Siew "@xizun" | |
// @match https://woothemes.zendesk.com/* | |
// @grant GM_setClipboard | |
// @require http://code.jquery.com/jquery-3.4.1.min.js | |
// ==/UserScript== | |
(function($){ //function to create private scope with $ parameter | |
const options = { | |
DEBUG: true, | |
WAIT_MILISECONDS: 2000 | |
} | |
function dlog(message){ | |
if (options.DEBUG) { | |
console.log(message); | |
} | |
} | |
function isJquery(elem) { | |
return elem instanceof jQuery && elem.length > 0; | |
} | |
function addBorder(elem) { | |
elem.css('border', '2px solid red'); | |
} | |
//private scope and using $ without worry of conflict | |
dlog('loading Zendesk Plus'); | |
document.addEventListener('keydown', function(event) { | |
if (event.ctrlKey && event.key === 'z') { | |
let $v = $("label:contains('Private Note')"); | |
let $s = $v.next(); | |
select($s) | |
} | |
}); | |
document.addEventListener('keydown', function(event) { | |
if (event.ctrlKey && event.key === 'x') { | |
let $f = $('.comment_input_wrapper .content .ember-view.body textarea.ember-view'); | |
let $mf = $f.eq(0); | |
select($mf); | |
} | |
}); | |
function flashBackground(s) { | |
let style = { | |
backgroundColor: 'yellow' | |
}; | |
s.css(style); | |
let revertStyle = { | |
backgroundColor: 'initial' | |
}; | |
setTimeout(function () { | |
s.css(revertStyle); | |
}, options.WAIT_MILISECONDS); | |
} | |
function css(s, style){ | |
s.css(style); | |
} | |
function select(s) { | |
s.select(); | |
// s.get(0).scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"}); | |
s.get(0).scrollIntoView({block: "end"}); | |
flashBackground(s); | |
} | |
})(jQuery); //invoke nameless function and pass it the jQuery object | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment