Javascript on Greasemonkey, constraints and limiting factors compared to an addon in Firefox/Chrome?
Disclaimer: Newbie Javascript coder trying to use Greasemonkey; I've read the tutorials but do not understand enough of the parlance used so that I can focus in and learn what's needed. I'm hoping someone can gently point me the way as to how I can implement what I want.
Say I want to make a plugin that applies something to the effect of nyanit.com or bacolicio.us (examples: http://nyanit.com/google.com or http://bacolicio.us/http://google.com).
The way I understand in Javascript, when I would like to apply an effect on a page, would be:
<script type="text/javascript">
(function(doc, t) {
var scr = doc.createElement(t);
scr.async = true;
scr.typ开发者_运维技巧e = 'text/javascript';
// scr.src = ??work-in-progress??
//pseudocode (need to figure this out too): if it's a website that allows framing
//then apply the nyancat, else don't apply or I'll muck it up.
var r = doc.getElementsByTagName(t)[0]; r.parentNode.insertBefore(scr, r);
} (document, 'script'));
</script>
So I guess my questions are, specifically:
1) For Greasemonkey, after installation, I created a file that has a header of // Userscript info, followed by blank space. I am assuming all I need to do is copy my script and paste it in there, and it should work? Are there any constraints and limiting factors to Greasemonkey applying the javascript (versus having it in the HTML of a page)?
2) If I wanted this to be an addon for Firefox, is this conversion tool reliable or should I pick up addon-writing practice for Firefox?
3) If I wanted this to be an addon for Chrome, basically I just upload the .js somewhere (such as userscripts.org) and Google should ideally recognize it as a script?
1) Basically, you are accessing the web page through XPCNativeWrapper
so you have the same limitations. For the code here none of them should apply, just paste that code into the GreaseMonkey script (without <script>
tags).
2) Yes, the script compiler will do ok.
3) Yes, Chrome supports most GreaseMonkey scripts out of the box.
精彩评论