Skip to content

Instantly share code, notes, and snippets.

@BenoitDuffez
Created November 8, 2013 08:38
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 BenoitDuffez/7368097 to your computer and use it in GitHub Desktop.
Save BenoitDuffez/7368097 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name SelfServicePlus
// @namespace SelfServicePlus
// @match http://astsih/SelfService/*
// @version v1.0
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function loadJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
// the guts of this userscript
function main() {
var customSelfServiceLaunch=0;
// Note, jQ replaces $ to avoid conflicts.
jQ('body').ajaxSuccess(function (event, requestData) {
console.log (requestData.responseText);
});
function addNewButton() {
newButton='<table cellspacing="0" class="x-btn x-btn-text-icon x-item-disabled" style="width: auto;"><tbody class="x-btn-small x-btn-icon-small-left"><tr><td class="x-btn-tl"><i>&nbsp;</i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i>&nbsp;</i></td></tr><tr><td class="x-btn-ml"><i>&nbsp;</i></td><td class="x-btn-mc"><em class="" unselectable="on"><button type="button" class=" x-btn-text">Open Outlook Folder</button></em></td><td class="x-btn-mr"><i>&nbsp;</i></td></tr><tr><td class="x-btn-bl"><i>&nbsp;</i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i>&nbsp;</i></td></tr></tbody></table>';
saveButton=jQ(".x-panel-body.x-panel-body-noheader").find("iframe").contents().find("body").find("#WorkspaceFrame").find(".x-panel-tbar.x-panel-tbar-noheader").find(".x-toolbar-right").find(".x-toolbar-right-ct").find("table").eq(8).find(">:first-child").find(">:first-child").find(">:first-child");
console.log("--");
console.log(saveButton);
console.log("--");
jQ(".x-panel-body.x-panel-body-noheader").find("iframe").contents().find("body").find("#WorkspaceFrame").find(".x-panel-tbar.x-panel-tbar-noheader").find(".x-toolbar-right").find(".x-toolbar-right-ct").find("table").eq(8).find(">:first-child").find(">:first-child").find(">:first-child").before('<td class="x-toolbar-cell"><button>Open Outlook Folder</button></td>');
saveButton.before("<h1>OO</h1>");
jQ.each(saveButton, new function(i,v) { console.log("#"+i+": "+v); });
saveButton.before(newButton);
}
// Capture XHR readystatechange
(function(open) {
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
this.addEventListener("readystatechange", function() {
if (this.readyState==4 && this.status==200&&url=="http://astsih/SelfService/Services/FormService.asmx/GetFormValidationListData") {
r =JSON.parse(this.responseText);
if (r.d.Urgency!=null){
customSelfServiceLaunch++;
if (customSelfServiceLaunch==1) {
addNewButton();
}
setTimeout(function(){customSelfServiceLaunch=0;}, 1000);
}
}
}, false);
open.call(this, method, url, async, user, pass);
};
})(XMLHttpRequest.prototype.open);
}
// load jQuery and execute the main function
loadJQuery(main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment