全局去悬浮广告
var d=document;var s=d.createElement('script');s.setAttribute('src', 'https://greasyfork.org/scripts/7410-jskillad/code/jsKillAD.user.js');d.head.appendChild(s);
悬浮广告屏蔽
/**
* 禁用动态添加脚本,防止广告加载
*
* @param valid bool? true(valid)|false(invalid)|other(off)
* @param rule array 配置允许(valid)|不允许(invalid)的脚本规则:支持regex、string、function
*/
(function(valid, rule) {
if(typeof Element === 'undefined') console.log('IE8以下浏览器无效');
var origin = new RegExp('^' + location.origin),Ele = Element;
each(['appendChild', 'insertBefore', 'insertAfter'], proxy);
function proxy(prop) {
var proxy_obj = Ele.prototype[prop];
Ele.prototype[prop] = function(elem) {
if (!elem.children.length) {
var tag = elem.tagName.toLowerCase();
if (tag == 'script' && isBanScript(elem)) {
console.log('禁用脚本:' + elem.src);
var substitute = document.createElement('script');
substitute.innerHTML = '// 禁用脚本:' + elem.src;
elem = substitute;
}
}
return proxy_obj.apply(this, arguments);
};
}
function isBanScript(script) {
if (origin.test(script.src)) return false;
return valid === each(rule, match);
function match(val) {
var type = typeof val;
if (type === 'string') {
if (script.src == val) return true;
} else if (type === 'function') {
if (val(script)) return true;
} else {
if (val.test(script.src)) return true;
}
return false;
}
}
function each(arr, fn) {
if (arr) {
for (var i = 0, n = arr.length; i < n; i++) {
if (fn.call(arr[i], arr[i], i) === true) return false;
}
}
return true;
}
})(true, []);
//表示有效的脚本规则列表
去网页留白
--常用(顶部)
document.body.style.paddingTop=0
--强制(顶部)
document.body.style.marginTop='-20px'
--左部
document.body.style.marginLeft='-20px'
--右部
document.body.style.marginRight='-20px'
--底部
document.body.style.marginBottom='-20px'
--均放在JavaScript(即JS)
屏蔽网站超链接
document.write('<style>a[href="当前网页"],a[href="主页"],a[href^="要屏蔽超链接"]{display:none;}</style>');
未知id和class删除图片广告
//全局使用或网页控制添加
varelement=document.getElementsByTagName("img");
//广告图片地址
varad="http://www.tianjiyy123.com/template/yely/i/img/logo_min.png";
//遍历查找元素
for(vari=0;i<element.length;i++){
if(element[i].src==ad){
//移除广告
element[i].remove();
break;
}else{
continue;
}
}
js脚本屏蔽网页元素
var remove=n=>{n.split(",").forEach(v=>{if(v.indexOf("@ID(")==0){document.getElementById(v.substring(4,v.length-1)).style.display="none"}else{for(let e of document.getElementsByClassName(v))e.style.display="none"}})}
remove("这里填要屏蔽的元素用,隔开")
强制缩放
varsc=document.createElement("meta");sc.setAttribute("name","viewport");sc.setAttribute("content","width=device-width,initial-scale=1,user-scalable=yes");document.head.appendChild(sc);
让链接可点击
var oHead1016 = document.getElementsByTagName('body').item(0); var oScript1016 = document.createElement("script"); oScript1016.type = "text/javascript"; oScript1016.src="https://greasyfork.org/scripts/342-text-to-link/code/Text%20To%20link.user.js"; oHead1016.appendChild( oScript1016);
仿酷安回到顶部和底
functiontoTopLikeKuAn(){ vartoTopBtn=document.createElement("div"); toTopBtn.id="toTopBtn"; toTopBtn.setAttribute("style","font-size:4vw!important;width:10vw!important;height:10vw!important;line-height:10vw!important;text-align:center!important;background:url(http://www.web605.cn/cdn/images/toTop.png)no-repeatcentercenter!important;background-size:3vw3vw!important;background-color:rgba(250,250,250,0.9)!important;box-shadow:0px1px1pxrgba(0,0,0,0.4);color:#000!important;position:fixed!important;bottom:5vh!important;right:45vw!important;z-index:99999999999999999!important;border-radius:100%!important;display:none;"); document.body.appendChild(toTopBtn);};functionisScrollToTop(){ vartoTopTimer; vartheBody=document.getElementsByTagName('body')[0]; vartopTopBtn=document.getElementById('toTopBtn'); document.ontouchstart=function(e){ if(toTopTimer){ clearTimeout(toTopTimer); }; mystartY=e.changedTouches[0].clientY; }; document.ontouchmove=function(e){ myendY=e.changedTouches[0].clientY; varmyY=myendY-mystartY; if(myY>0){ toTopBtn.style.opacity="1"; toTopBtn.style.display="block"; toTopBtn.style.transform="rotateZ(0deg)"; toTopBtn.style.boxShadow="0px1px1pxrgba(0,0,0,0.4)"; toTopBtn.onclick=function(){ window.scrollTo(0,0); this.style.display="none"; toTopBtn.removeEventListener('click',this,false); }; }elseif(myY<0){ toTopBtn.style.opacity="1"; toTopBtn.style.display="block"; toTopBtn.style.transform="rotateZ(180deg)"; toTopBtn.style.boxShadow="0px-1px1pxrgba(0,0,0,0.4)"; toTopBtn.onclick=function(){ document.body.scrollTop=document.body.scrollHeight; this.style.display="none"; toTopBtn.removeEventListener('click',this,false); }; }else{ toTopBtn.style.display="none"; }; }; document.ontouchend=function(e){ toTopTimer=setTimeout(function(){ toTopBtn.style.transitionProperty="opacity,background-color"; toTopBtn.style.transitionDuration="500ms"; toTopBtn.style.transitionTimingFunction="linear"; toTopBtn.style.opacity="0"; toTopBtn.style.backgroundColor="rgba(200,200,200,1)"; setTimeout(function(){ toTopBtn.style.display="none"; toTopBtn.style.backgroundColor="rgba(250,250,250,0.9)"; },500); },3000); };};varisHaveToTopBtn;isHaveToTopBtn=document.getElementById('toTopBtn');if(!isHaveToTopBtn){ toTopLikeKuAn(); isScrollToTop();};
双击自动滚动
varcurrentPos,startY,endY,msec=40;vari=0;vartimer=newArray();functionScrollWin(){ currentPos=document.body.scrollTop; window.scroll(0,++currentPos); if(currentPos!=document.body.scrollTop){ ScrollWin_Off(); };};functionScrollWin_Off(){ for(varx=0;x<timer.length;x++){ clearInterval(timer[x]); }; i=0;};functionscrollAuto(){ document.onmousedown=ScrollWin_Off(); document.ondblclick=function(){ timer[i]=setInterval("ScrollWin()",msec); i++; }; varBody=document.getElementsByTagName('body')[0]; Body.ontouchstart=function(e){ startY=e.changedTouches[0].clientY; }; Body.ontouchmove=function(e){ endY=e.changedTouches[0].clientY; vary=endY-startY; if(y>=0){ ScrollWin_Off(); }; };};if(!location.href.match("via-app.cn")){ scrollAuto();};