您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何使用Greasemonkey / Tampermonkey脚本更改类CSS?

如何使用Greasemonkey / Tampermonkey脚本更改类CSS?

为此,只需使用CSS级联。使用将样式表添加页面GM_addStyle()。 注意:

// ==UserScript==
// @name     _Override banner_url styles
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @grant    GM_addStyle
// @run-at   document-start
// ==/UserScript==

GM_addStyle ( `
    .banner_url {
        background: url('http://www.pxleyes.com/images/contests/kiwis/fullsize/sourceimage.jpg') no-repeat center center fixed !important;
        -webkit-background-size: cover !important;
        -moz-background-size: cover !important;
        -o-background-size: cover !important;
        background-size: cover !important;
    }
` );

请注意, ,则它已崩溃GM_addStyle() (以及很多其他事情)。 这是 实际上,Greasemonkey的控制开发人员[本人也这么说。

同时,对于那些坚持使用GM4的受虐狂来说,这是一个垫片:

function GM_addStyle (cssStr) {
    var D               = document;
    var newNode         = D.createElement ('style');
    newNode.textContent = cssStr;

    var targ    = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
    targ.appendChild (newNode);
}
CSS 2022/1/1 18:23:18 有421人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶