A simple alternative to Greasemonkey

I like the concept of GM, but in practice, if you do not use it all the time and are not the absolute god of JS, it is impossible to use (maybe I just suck?).

It would be so useful to have a small extension that spanned several lines of JS and ran them after loading the page for a specific site. But that’s not what GM does. With GM you have to deal with several frames and these layers at the levels of annoying problems and security capabilities. Even when you simply ignore the correct procedure and use unsafewindow or one of the other hacks, it often still doesn't work.

It's so easy to come up with JS that you can run a browser console that will do what you want, but it never works when porting to usercript. Are there any settings in greasemonkey that I can change, or another extension completely designed for ease of use?

Note. I use Chrome, therefore bonus points for a solution that works for this particular browser.

Summery: I need a way to automatically run scripts with the same capabilities / permissions, like a console on certain pages.

+5
source share
1 answer

Firefox Greasemonkey Chrome, JS. /, .

, , GM userscripts, "" JS () "- iframes, :

// ==UserScript==
// @name    _Base template for simple, cross-browser, JS injection.
// @match   *://YOUR_SERVER.COM/YOUR_PATH/*
// @run-at  document-start
// ==/UserScript==

if (window.top != window.self)  //-- Don't run on frames or iframes.
    return;


function scriptMain () {
    // PUT ALL OF YOUR CODE HERE, INCLUDING ANY FUNCTIONS YOU CREATE.
    console.log ("Hello World!");
}

window.addEventListener ("load", scriptMainLoader, false);

function scriptMainLoader () {
    addJS_Node (null, null, scriptMain);
}

function addJS_Node (text, s_URL, funcToRun) {
    var D                                   = document;
    var scriptNode                          = D.createElement ('script');
    scriptNode.type                         = "text/javascript";
    if (text)       scriptNode.textContent  = text;
    if (s_URL)      scriptNode.src          = s_URL;
    if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';

    var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
    targ.appendChild (scriptNode);
}

, @run-at document-start ( Chrome), - .

+7

All Articles