class GetReady implements IUserScriptTemplate
{
    public function new()
    {
    }

    private function make_loader(code:String)
    {
        var out = "";

        out += "(function(){";
        out +=     "inject__ = document.createElement('script');";
        out +=     "inject__.type = 'text/javascript';";
        out +=     "inject__.appendChild(document.createTextNode(";
        out +=         code;
        out +=     "));";
        out +=     "document.getElementsByTagName('head')[0].";
        out +=         "appendChild(inject__);";
        out += "})();";

        return out;
    }

    public function generate(code:String):String
    {
        return this.make_loader(code);
    }
}

class GetReady implements IUserScriptTemplate
{
    public function new()
    {
    }

    private function get_watcher_on(teststr:String, code:String)
    {
        var out = "";

        out += "(function() {";
        out += "var wtimer__;";
        out += "function watch_timer__(){";
        out +=     "if(" + teststr + "){";
        out +=         this.make_loader(code);
        out +=         "window.clearInterval(wtimer__);";
        out +=     "}";
        out += "}";
        out += "var wtimer__ = window.setInterval(watch_timer__, 1000);";
        out += "})();";

        return out;
    }

    private function make_loader(code:String)
    {
        var out = "";

        out += "(function(){";
        out +=     "inject__ = document.createElement('script');";
        out +=     "inject__.type = 'text/javascript';";
        out +=     "inject__.appendChild(document.createTextNode(";
        out +=         code;
        out +=     "));";
        out +=     "document.getElementsByTagName('head')[0].";
        out +=         "appendChild(inject__);";
        out += "})();";

        return out;
    }

    public function generate(code:String):String
    {
        return this.get_watcher_on("typeof(webfrontend) == 'object'", code);
    }
}

Implement preliminary watch for webfrontend.
Implement preliminary watch for webfrontend.

This is not working at the moment, as we really need to inject _twice_. But
do so a few commits later.

It is implemented as a timer using window.setInterval() and every function has
the whole body of the userscript itself. So _THAT_ could definitely become a big
memory hog on the *client-side*.

We might want to avoid that (if possible), but for testing its okay.

imps/cncta