开发者

Load an external library CSS using a Chrome userscript

I want to load an external library (jQuery) into my .user.js script, to modify the CSS of an existing site. Now i am using $script to load external libraries, but it doesn't work.

On the other hand it would be also good to load external CSS files to modify the page, but I don't know how to do that. How can I modify the CSS easily with .user.js? How can I load external JS libraries?

This is my userscript at pastebin.com.


UPDATE:

I want to write a script or load a CSS which automatically modify the page look.

I tr开发者_StackOverflow中文版ied to load the jQuery library with $script micro library but it doesn't work, because Chrome disables AJAX communication in the .user.js.


If you don't mind taking Chrome Extension route then all problems you describing can be solved very easily without any extra coding, just with manifest file:

{
  "name": "My extension",
  ...
  "content_scripts": [
    {
      "matches": ["http://www.google.com/*"],
      "css": ["mystyles.css"],
      "js": ["jquery.js", "myscript.js"]
    }
  ],
  ...
}

It will automatically inject jquery and css along with your script to domains you specified.


Not sure from the way the question is written, but if the only thing you want is the ability to apply jQuery to any page you happen to be looking at (so you could then change some CSS via the jQuery commands on the console), you could do that with the jQuerify bookmarklet instead of a userscript.

http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet

Of course you could also just directly modify the CSS from the console, no JS required.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜