How to create a toolbar button for a Chrome Tampermonkey user script? -


i have written userscript run when call (not every time matching web page loads). ideally i'd create toolbar button starting script. how can done?

ps: need run in same context web page scripts , able call functions embedded in it.

i don't know toolbar you're talking about, it's possible add menu command tampermonkey's action menu.

since script should able run @ page need @include pages might slow down pages lot of iframes little bit.

this script execute main function (with alert statement) if menu command clicked.

// ==userscript== // @name       run on click // @namespace  http://tampermonkey.net/ // @version    0.1 // @description  run on click // @include    /https?:\/\/*/ // @copyright  2012+, // @grant      unsafewindow // @grant      gm_registermenucommand // ==/userscript==  gm_registermenucommand('run now', function() {      alert("put script's main function here"); }, 'r'); 

accessing pages functions possible 2 ways:

function main () {   window.function_at_the_page(); }  var script = document.createelement('script'); script.appendchild(document.createtextnode('('+ main +')();')); (document.body || document.head || document.documentelement).appendchild(script); 

or just:

unsafewindow.function_at_the_page(); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -