使用 Userscript 加载外部脚本适用于 Fx 4,但在 Fx 3.6 中失败

发布于 2024-10-04 17:35:41 字数 1942 浏览 3 评论 0原文

这是代码,未删节(有点短):

// ==UserScript==
// @name           Manga ChapterReader
// @license        MIT/X11 + Attribution (passcod)
// @namespace      http://www.mangareader.net
// @include        http://www.mangareader.net/*
// @description    Displays full chapters from MangaReader.net in a simpler interface.
// @author         passcod
// @version        10.331
// ==/UserScript==

// version format: y.z
function START(array_of_scripts_to_load, callback) {
    document.documentElement.innerHTML = '<head></head><body></body>';
    for ( i in array_of_scripts_to_load) {
        var script = document.createElement('script');
        script.src = array_of_scripts_to_load[i];
        var evl = new Object();
        evl.handleEvent = function (e) {
            callback();
        };
        script.addEventListener('load', evl, true);
        document.getElementsByTagName('head')[0].appendChild(script);
    }
}

var regular = /mangareader\.net\/[a-z0-9\-]+\/[0-9]+(\/.+)?/i, old = /mangareader\.net\/[0-9\-]+\/([a-z0-9\-]+)\/chapter-([0-9]+)\.htm/i;

if ( regular.test(window.location) ) {
    //START(['http://lib/libstore/jquery.js','http://scrap.book/userscripts/mangareader/index.js'],
    START(['http://code.jquery.com/jquery-1.4.2.min.js','https://bitbucket.org/passcod/scrap.book/raw/tip/userscripts/mangareader/index.js'],
    function() {
        $$$();
    });
}
else if ( old.test(window.location) ) {
    var parts = old.exec(window.location);
    window.location = 'http://www.mangareader.net/'+parts[1]+'/'+parts[2];
}

这在 Firefox 4.0b7 (Windows) 和 nightly (Linux) 中完美运行,但在 Fx 3.6.x 中失败(来自 3.6、3.6.2 和 3.6.12 的报告)。

我不明白为什么。

哦,等等...我在 Fx 4 上使用 Scriptish...也许这与某些事情有关?

但除此之外,我完全不知所措。脚本不会被加载。它甚至看起来像 document.documentElement.innerHTML = '...' 行不起作用...在 Firebug 中做到了,它将文档删除为 <; /html>,但之后什么也没有发生。

有什么想法吗?

Here's the code, not abridged (it's shortish):

// ==UserScript==
// @name           Manga ChapterReader
// @license        MIT/X11 + Attribution (passcod)
// @namespace      http://www.mangareader.net
// @include        http://www.mangareader.net/*
// @description    Displays full chapters from MangaReader.net in a simpler interface.
// @author         passcod
// @version        10.331
// ==/UserScript==

// version format: y.z
function START(array_of_scripts_to_load, callback) {
    document.documentElement.innerHTML = '<head></head><body></body>';
    for ( i in array_of_scripts_to_load) {
        var script = document.createElement('script');
        script.src = array_of_scripts_to_load[i];
        var evl = new Object();
        evl.handleEvent = function (e) {
            callback();
        };
        script.addEventListener('load', evl, true);
        document.getElementsByTagName('head')[0].appendChild(script);
    }
}

var regular = /mangareader\.net\/[a-z0-9\-]+\/[0-9]+(\/.+)?/i, old = /mangareader\.net\/[0-9\-]+\/([a-z0-9\-]+)\/chapter-([0-9]+)\.htm/i;

if ( regular.test(window.location) ) {
    //START(['http://lib/libstore/jquery.js','http://scrap.book/userscripts/mangareader/index.js'],
    START(['http://code.jquery.com/jquery-1.4.2.min.js','https://bitbucket.org/passcod/scrap.book/raw/tip/userscripts/mangareader/index.js'],
    function() {
        $$();
    });
}
else if ( old.test(window.location) ) {
    var parts = old.exec(window.location);
    window.location = 'http://www.mangareader.net/'+parts[1]+'/'+parts[2];
}

This works perfectly in Firefox 4.0b7 (Windows) and nightly (Linux), but it fails with Fx 3.6.x (Reports from 3.6, 3.6.2, and 3.6.12).

I can't see why.

Oh, wait... I use Scriptish on Fx 4... maybe this has to do with something?

But apart from that, I'm totally at loss. The scripts don't get loaded. It even looks like the document.documentElement.innerHTML = '...' line doesn't work... did it in Firebug and it erases the document to <html></html>, but nothing more happens afterward.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗喜 2024-10-11 17:35:41

我通过将加载的脚本更改为立即执行来修复此问题:

(function () { /* ... */ })();

然后删除回调。

浏览器没有问题,但反应时间有问题。由于某种原因,Fx 4 中的用户脚本完成得太早。

I fixed this by changing the loaded scripts to execute immediately:

(function () { /* ... */ })();

and then removing the callbacks.

There was no problem with the browser, but in the reaction time. For some reason, the userscript finished too early in Fx 4.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文