[英]Overriding/removing inline !important
I have a site using htmlcommentbox.com's comment system. 我有一个使用htmlcommentbox.com评论系统的网站。 It seems to use inline !importants to make a link to the site stay there.
它似乎使用内联!重要信息来建立到该网站的链接。 This is the code I'm using from them:
这是我正在使用的代码:
<!-- begin htmlcommentbox.com --> <div id="HCB_comment_box">Loading comments...</div> <link rel="stylesheet" type="text/css" href="htmlcommentbox.css" /> <script type="text/javascript" id="hcb"> /*<!--*/ if(!window.hcb_user){hcb_user={};} (function(){var s=document.createElement("script"), l=(hcb_user.PAGE || ""+window.location), h="//www.htmlcommentbox.com";s.setAttribute("type","text/javascript");s.setAttribute("src", h+"/jread?page="+encodeURIComponent(l).replace("+","%2B")+"&mod=%241%24wq1rdBcg%247.bGleVasiPPOiHF49trb0"+"&opts=342&num=10");if (typeof s!="undefined") document.getElementsByTagName("head")[0].appendChild(s);})(); /*-->*/ </script> <!-- end htmlcommentbox.com -->
My CSS is: 我的CSS是:
body {
background-color: #000;
}
p {
color: #FFF;
}
a {
color: #FFF;
}
span,
div a {
display: none !important;
}
I will include more if necessary. 如有必要,我会包括更多内容。 Can I remove the link to their site?
我可以删除其网站的链接吗?
You could simply select the element and remove the style
attribute: 您只需选择元素并删除
style
属性:
document.querySelector('.home-desc + a').removeAttribute('style');
..then you can use the following CSS to hide it: ..然后你可以使用以下CSS来隐藏它:
.home-desc + a,
.home-desc {
display: none;
}
Alternatively, since all you are doing is hiding the elements, you could just remove them entirely. 或者,由于您所做的只是隐藏元素,您可以完全删除它们。
You could also avoid JS completely and set the opacity
to 0
and add pointer-events: none
. 您还可以完全避免使用JS并将
opacity
设置为0
并添加pointer-events: none
。 This will essentially hide the element(s). 这基本上会隐藏元素。
.home-desc + a,
.home-desc {
opacity: 0;
pointer-events: none;
}
I'd suggest to remove the link from the DOM after the script has been executed, then you do not need to remove or override the !important: 我建议在脚本执行后从DOM中删除链接,然后你不需要删除或覆盖!important:
document.getElementById('HCB_comment_box').addEventListener('DOMSubtreeModified', function () {
var desc = document.querySelector('#HCB_comment_box .home-desc');
var link = document.querySelector('#HCB_comment_box .home-desc').nextSibling;
var parent = desc.parentNode;
parent.removeChild(desc);
parent.removeChild(link);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.