当前位置:   article > 正文

tampermonkey(油猴) GM_addStyle

gm_addstyle

tampermonkey(油猴) GM_addStyle
tampermonkey脚本中 GM_addStyle的教程很少,连自身的文档都没有案例,网上查了很久,自己记录一下。

   var ads=["iframe",".layout-header",".layout-footer",".xuexi",".WNiH6aSBS23IzewzHGi4v",'audio',".redflag-2","div[style='background-repeat: no-repeat;']",".my-points-section .earn-header",'img'];
    for(var i=0 ;i<ads.length;i++){
        GM_addStyle(ads[i]+'{display:none}')
    }

    GM_addStyle(".my-points-card {height:150px !important}");
    GM_addStyle("* {margin-top:0px !important; margin-left:0px !important}");
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

1、GM_addStyle可以自动遍历这里.my-points-card是一个元素数组及多个div公用一个class GM_addStyle将所有元素都添加了指定属性。
2、* 指所有元素,使用要小心。
3、括号内可以指定多个元素,中间用逗号隔开。

GM_addStyle(".my-points-card,.layout-header{height:150px !important}")
  • 1

4、只能添加style属性中的值;多属性用分号隔开。

GM_addStyle("* {margin-top:0px !important; margin-left:0px !important}");
  • 1

5、!important表示添加的属性权限,每一个属性后面都要跟一个。
6、GM_addStyle 要在文件中声明。

// @grant        GM_addStyle
  • 1
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号