Writing a userscript that replaces a background image

后端 未结 2 1424
耶瑟儿~
耶瑟儿~ 2021-01-27 07:38

This is the code

// ==UserScript==
// @name           Wood Background
// @namespace      http://www.nationstates.net/nation=ellorn
// @description    Changes bac         


        
2条回答
  •  Happy的楠姐
    2021-01-27 08:22

    You can define your own user-stylesheet to overwrite the author stylesheets of websites. I think this would be better suited to alter CSS than writing javascript.

    Here is a short introduction on how to achieve that.

    Besides from that your code should work in general if you hand over the CSS-string correctly (fixed quoting and linebreak):

    var css = "* { background: #00ff00 url('http://awesomewallpapers.files.wordpress.com/2010/01/wooden_top.jpg') no-repeat fixed center;  }";
    
    addCss ( css );
    

    Note however, that * will break, since you are applying the wooden background to every element, not only your background-element (HTML or body or a wrapper div).

提交回复
热议问题