油猕猴(greasemonkey)初步体验心得

油猴子(greasemonkey)初步体验心得
项目需要把微博搜索的东西发送到指定服务器上,我想到了油猴子,现学之,

// ==UserScript==
// @name        weibo_test2
// @namespace   http://www.oreilly.com/catalog/greasemonkeyhacks/
// @description 抓取微博搜素结果的uid
// @include     http://s.weibo.com/*
// @exclude     %exclude%
// @version     1
// ==/UserScript==


	alert('Hello world! myweibo');
	function work(){
		var lst = document.getElementsByClassName("person_name");
		var len = lst.length;
		if(len<1){
			return;
		}
		var uid ="";
		for(var idx=0;idx<len;idx++){
			var aE = lst[idx].getElementsByTagName("a")[0].getAttribute("uid");
			uid = uid+aE+",";
		}
		//alert("abc"+uid);
		GM_xmlhttpRequest({
		  method: "GET",
		  url: "http://localhost/test.php?id="+uid,
		  onload: function(response) {
			alert(response.responseText);
		  }
		});
	}
	
	work();



发现的问题:// ==UserScript==中东西是一样的,但是从模板拷贝过来和自己写的效果不一样,2.一定要用alert,当用户单击alert的时候要迟疑几秒,迟缓页面加载,否则alert后面的代码可能执行不了。