首页
登录 | 注册

皮皮书屋页面链接修正

开博这么久,没写过文章,今天心血来潮,写了一个js处理皮皮书屋的链接问题(通过IP访问),在此发篇水文,终于让博文突破0篇了 = =!:

使用方法:

1、先firefox安装greasemonkey插件,然后对皮皮书屋使用以下脚本即可;(用greasemonkey的话,设置好URL匹配规则,以后怎么跳转都会自动运行)

2、或者直接在浏览器调试工具的控制台运行下面的js代码即可。

PS:皮皮书屋链接:http://222.73.57.56/

这么水的东西就不用解释了,源代码直接贴上:

// ==UserScript==
// @name        ppurl
// @namespace   sugan
// @include     http://222.73.57.56/*
// @version     1
// ==/UserScript==

if (!unsafeWindow)
	var unsafeWindow=window;
	
unsafeWindow.flag=false;
unsafeWindow.handle;
unsafeWindow.counter=0;

//修正anchor、link的href属性
function replaceHrefByTagName(tagName){
	var a=document.getElementsByTagName(tagName);
	if(a.length>0){
		for(var x=0;x<a.length;x++){ 
			 if(a[x].href.indexOf("www.ppurl.com")) 
				a[x].href=a[x].href.replace('www.ppurl.com','222.73.57.56')
		}
	}
}

//修正表单的action
function fixFormAction(){
	var a=document.getElementsByTagName('form');
	if(a.length>0){
		for(var x=0;x<a.length;x++){ 
			 if(a[x].action.indexOf("www.ppurl.com")) 
				a[x].action=a[x].action.replace('www.ppurl.com','222.73.57.56')
		}
	}
}

//加载丢失的js文件
function loadJsCode(){
	var headEle = document.head;
	var scriptArr=document.getElementsByTagName('script');
	var store=[];
	for (var index=0; index<scriptArr.length; index++){
		if(scriptArr[index].src && scriptArr[index].src.indexOf('www.ppurl.com')){
			var scrEle= document.createElement("script");
			scrEle.type = "text/javascript";
			scrEle.src=scriptArr[index].src.replace('www.ppurl.com','222.73.57.56');
			store.push(scrEle);
		}
		else{
			store.push(scriptArr[index].cloneNode(true));
		}
	}
	
	for( var i=scriptArr.length-1; i>=0; i--)
		scriptArr[i].parentNode.removeChild(scriptArr[i]);
	
	for(var i=0; i<store.length; i++)
		headEle.appendChild(store[i]);
	
}

//修正下载书籍时验证码相关的东东 (仅适用于下载页面)
unsafeWindow.myFixReady=function () {
		var YAHOO=unsafeWindow.YAHOO;
		var KR=unsafeWindow.KR;
		var flag=unsafeWindow.flag;
		if(typeof YAHOO!=='undefined' && flag===false){
			var $D=unsafeWindow.$D = YAHOO.util.Dom;
			
			$D.get('pageloading').style.display = 'none';
			KR.app.captcha.init();
			KR.app.showContent.init();
			KR.app.user.favor();
			KR.app.Zoom.init('content'); 
			
			unsafeWindow.pageTracker = unsafeWindow._gat._getTracker('UA-888900-3');
			unsafeWindow.pageTracker._trackPageview(); 
			
			flag=true;
			clearInterval(unsafeWindow.handle);
			console.log('success');
			replaceHrefByTagName('a');
		}
		else{
			if(unsafeWindow.counter>10){
				clearInterval(unsafeWindow.handle);
				console.log('fail: attempt'+unsafeWindow.counter); 
			}
			unsafeWindow.counter+=1;
			//console.log(unsafeWindow.handle); 
		}
}


//调用全部
function fixAll(){
	replaceHrefByTagName('link');
	replaceHrefByTagName('a');
	fixFormAction();
	loadJsCode();
	unsafeWindow.handle=setInterval( unsafeWindow.myFixReady,2000);
}

//开始修正页面链接错误
fixAll();




2020 jeepxie.net webmaster#jeepxie.net
10 q. 0.008 s.
京ICP备10005923号