stylish里如何使用正则

上网、浏览、聊天、下载等
回复
ubunbates
帖子: 120
注册时间: 2014-04-30 15:44
系统: linux

stylish里如何使用正则

#1

帖子 ubunbates » 2014-06-23 13:00

想屏蔽一个网页中无用的视频, 如图.
q.png
但问题是不能用

代码: 全选

div#sohuplayer{display:none !important;} 
因为另一个有用的视频有一样的结构. 所不同的是, 无用的视频对应"<embed id="player14034.....", 而有用的视频是"<embed id="player", 在player后没有数字.

所以, 我想写一个类似

代码: 全选

embed#player[0-9]+{display:none !important;} 
的正则, 该如何写??
头像
astolia
论坛版主
帖子: 6703
注册时间: 2008-09-18 13:11

Re: stylish里如何使用正则

#2

帖子 astolia » 2014-06-23 14:25

CSS选择器语法不支持这种。。。你只能用子串匹配或者条件取反:
foo[href^="baidu.com"]{color:red} /*选择foo标签的href属性值以baidu.com开头的所有元素*/
foo[href$=".com"]{color:red} /*选择foo标签的href属性值以.com结尾的所有元素*/
foo[href*="baidu"]{color:red} /*选择foo标签的href属性值中包含有baidu的所有元素*/

代码: 全选

#sohuplayer > embed[id^="player0"]{display:none !important;} 
#sohuplayer > embed[id^="player1"]{display:none !important;} 
#sohuplayer > embed[id^="player2"]{display:none !important;} 
...
条件取反要简单点

代码: 全选

#sohuplayer > embed:not(#player){display:none !important;} 
ubunbates
帖子: 120
注册时间: 2014-04-30 15:44
系统: linux

Re: stylish里如何使用正则

#3

帖子 ubunbates » 2014-06-23 18:02

astolia 写了:CSS选择器语法不支持这种。。。你只能用子串匹配或者条件取反:
foo[href^="baidu.com"]{color:red} /*选择foo标签的href属性值以baidu.com开头的所有元素*/
foo[href$=".com"]{color:red} /*选择foo标签的href属性值以.com结尾的所有元素*/
foo[href*="baidu"]{color:red} /*选择foo标签的href属性值中包含有baidu的所有元素*/

代码: 全选

#sohuplayer > embed[id^="player0"]{display:none !important;} 
#sohuplayer > embed[id^="player1"]{display:none !important;} 
#sohuplayer > embed[id^="player2"]{display:none !important;} 
...
条件取反要简单点

代码: 全选

#sohuplayer > embed:not(#player){display:none !important;} 
不支持regexp太不好了.

我用这个, 效果一样

代码: 全选

{embed:not(#player){display:none !important;}

谢谢了
回复