javascript学习

废话不说,直接贴代码

/**
	执行转发开始clearInterval(myInterval);
	地址:http://tuitu.sinaapp.com/weibo/task
	http://qqtuitu.sinaapp.com/weibo/task
**/
(function(){ 
    var doc = document, script = doc.createElement("script"), _s = doc.getElementsByTagName("script")[0];
	//script.src = "http://libs.baidu.com/jquery/1.4.1/jquery.min.js";/assets/js/jquery.js
	script.src = "http://kaixinpig.net/assets/js/jquery.js";
	_s.parentNode.insertBefore(script,_s);
	script.onload = function(){
		console.log("-------------------------jQuery is loaded!");
	}
})()



function invokeClick(element) {
	if(element.click) element.click(); 
	else if(element.fireEvent) element.fireEvent('onclick'); 
	else if(document.createEvent){
	var evt = document.createEvent("MouseEvents"); 
	evt.initEvent("click", true, true); 
	element.dispatchEvent(evt); 
	}
}

function waitSecs(seconds){
	var t = Date.now();
	while(true){
	  if(Date.now()-t>seconds*1000){
	     break;
	  }
	}
}


function zhuanfa(){
	var slist = $("span.right a");
	var len = slist.length;
	console.log("len "+len);
	if(len==0){
	   //$("a#refresh")
	   console.log(" click refresh click !");
	   invokeClick($("a#refresh")[0]);
	   return;
	}
	for(var k = 0; k < len; k++) {
		var id =slist[k].id;
		var index1 = id.indexOf("fast");
		//console.log("id "+id);
		//console.log("index1 "+index1);
		if(index1>=0){
		   //console.log("click "+k);
		   console.log("id "+id);
		   waitSecs(5);
		   invokeClick(slist[k]);
		}
	}
	//$("a.next")[0]
	invokeClick($("a.next")[0]);
}


setInterval("zhuanfa()",90000);

/**
	执行转发结束
**/


/**
	关注开始
**/

function work()
{
	console.log("click at ["+(new Date()).toString()+"]");
	invokeClick($("#follow_all_btn")[0]);
	waitSecs(30);
	invokeClick($("a.next")[0]);
}

setInterval("work()",60000);

/**
	关注结束
**/



function invokeClick(element) {
if(element.click)element.click(); //判断是否支持click() 事件
else if(element.fireEvent)element.fireEvent('onclick'); //触发click() 事件
else if(document.createEvent){
var evt = document.createEvent("MouseEvents"); //创建click() 事件
evt.initEvent("click", true, true); //初始化click() 事件
element.dispatchEvent(evt); //分发click() 事件
}

}

相关推荐