Greasy Fork is available in English.

Дискусии » Разработка

How to run a user script WITHOUT greasemonkey.

§
Публикуван на: 24.10.2014

How to run a user script WITHOUT greasemonkey.

Hi all, first post, please be patient.

I'm very much a 'basic' user of javascript. Myself and a friend are both making headway learning the basics of javascript and app development. As this question will probably make you aware, we're both absolute beginners.

I currently have a user script which works wonders on one of my webpages. What I'm wanting to do is package my web site as a Webview application. However, I also want to use the userscript that runs through greasemonkey...obviously this relies on greasemonkey and firefox. Is there a way of stripping the code out of the javascript and slamming it into my document as inline javascript? Or will the code have to be rewritten to make it not rely on greasemonkey?

§
Публикуван на: 24.10.2014

You can try "javascript:" bookmark, which may be what you want.

§
Публикуван на: 24.10.2014

*UPDATE*

I've just found the attached method, which apparently allows you to insert the user script into your html code.

I've tried this, and it doesn't seem to work, after trying this in both the head section, and then in the body section, can anyone offer any advice?

§
Публикуван на: 24.10.2014
You can try "javascript:" bookmark, which may be what you want.

Hi ts, thanks for the reply. I don't think this is what I'm looking for. I've googled it and read a few pages. Thanks though :)

Jixun.MoeМод
§
Публикуван на: 24.10.2014

Just copy the whole script and put between <script> tag.

Jixun.MoeМод
§
Публикуван на: 24.10.2014

However, the script will fail if they are using any GM_ functions, as they don't exist in browser.

§
Публикуван на: 24.10.2014

Thanks for the reply JixunMoe. Yes, the script does use GM_ functions, is there anyway in which the script can be rewritten to enable these functions to work within the script tags?

Jixun.MoeМод
§
Публикуван на: 24.10.2014
Thanks for the reply JixunMoe. Yes, the script does use GM_ functions, is there anyway in which the script can be rewritten to enable these functions to work within the script tags?

You could reference a implementation of GM_ in pure JavaScript, for example GM_xmlHttpRequest (Well, cross domain request will not work):

// A simple implementation of GM_xmlHttpRequest with limited parameter support.
var GM_xmlHttpRequest = function ( opts ) {
    var oReq = new XMLHttpRequest ();
    var cbCommon = function (cb) {
        return (function () {
            cb ({
                readyState: oReq.readyState,
                responseHeaders: opts.getHeader ? oReq.getAllResponseHeaders() : null,
                getHeader: oReq.getResponseHeader.bind (oReq),
                responseText: oReq.responseText,
                status: oReq.status,
                statusText: oReq.statusText
            });
        }).bind (opts);
    };

    if (opts.onload)  oReq.onload   = cbCommon (opts.onload);
    if (opts.onerror) oReq.onerror  = cbCommon (opts.onerror);

    oReq.open(opts.method || 'GET', opts.url, !opts.synchronous);

    if (opts.headers) {
        Object.keys(opts.headers).forEach (function (key) {
            oReq.setRequestHeader (key, opts.headers[key]);
        });
    }
    return oReq.send(opts.data || null);
};

If you want, give me the list of GM_ functions used, I'll try to implement them.

§
Публикуван на: 27.11.2014

Here is GM_ lib that have lots of GM_function, include GM_setClipboard n=in my 2nd post, anyone can maintain it then I will really appreciate:https://greasyfork.org/forum/discussion/2207/anyone-can-continue-maintain-this-script-library#latest

Jixun.MoeМод
§
Публикуван на: 27.11.2014
Here is GM_ lib that have lots of GM_function, include GM_setClipboard n=in my 2nd post, anyone can maintain it then I will really appreciate:https://greasyfork.org/forum/discussion/2207/anyone-can-continue-maintain-this-script-library#latest

I do remember something like this in the past, but I forgot its name... Thanks pointing out that :3

Публикувайте отговор

Влезте, за да публикувате отговор.