Created
November 8, 2013 08:38
-
-
Save BenoitDuffez/7368097 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 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> </i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i> </i></td></tr><tr><td class="x-btn-ml"><i> </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> </i></td></tr><tr><td class="x-btn-bl"><i> </i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i> </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