有些网页外链都是广告,想办法隐藏防止误点击。
抓取隐藏:
function hideOutA() {
var a = document.getElementsByTagName('a');
for (i=0; i<a.length; i++) {
if (!a[i].href.startsWith('/')) { //排除相对链接
var host = location.protocol + '//' + location.host;
if (!a[i].href.startsWith(host)) {
a[i].style.display = 'none';
}
}
}
}
规则解析:
var rule1 = rule[i].split('*');
if (document.URL.startsWith(rule1[0])) {
eval(rule1[1]);
}
规则设置:
URL*hideOutA()