开发者

Execute a Greasemonkey script on every page, regardless of page-type (like foo.com/image.jpg)?

Chrome works just fine, and my Greasemonkey script, if copy/pasted into Firefox's Firebug, works just fine on these pages but I can't seem to get it automatically execute.

Download & install the script: http://sente.cc/js/testing_greasemonkey.user.js

and then go to http://imgur.com/gallery/VaA9c (observe simple alert) and http://i.imgur.com/VaA9c.jpg (observe no alert)

the script:

// ==UserScript==
// @name          Testing Greasemonkey
// @namespace     stuartpowers
// @description   Testing Greasemonkey
// @author        Stuart Powers
// @homepag开发者_如何学运维e      http://sente.cc/
// @include       http://i.imgur.com/*
// @include       http://imgur.com/*
// ==/UserScript==


// load http://imgur.com/gallery/VaA9c (works)
// load http://i.imgur.com/VaA9c.jpg (doesn't work)

(function () {
    alert("worked");
})()


No, Greasemonkey requires an explicit DOM to fire and act upon. It cannot run on Chrome-generated1 pseudo-DOM2.

If you want to act on these kind of "pages", you'll have to write a Firefox extension (add-on). (Note that userscripts in Google-Chrome are converted into mini extensions.)

Here are some add-on resources, I've found helpful:

  • Mozilla extensions home page
  • Add-on Builder
  • 10 Things They Never Tell You In Firefox Extension School
  • Developing Firefox Extensions – Paper



1 Here, "Chrome" refers to the privileged DOM that makes up the Firefox's UI.
2 With select exceptions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜