My first GreaseMonkey Script: VeryCD quick search
2009-03-17 04:02
429 查看
版权声明:转载时请以超链接形式标明文章原始出处和作者信息 http://blog.csdn.net/seven20000/
偶然间看到了驴子给豆瓣写的GM脚本
用了下,觉得挺方便
我逛VeryCD和豆瓣一样多
所以反其道而行之
给VeryCD写了个到『豆瓣/射手/google』的速查脚本
对Xpath不熟,写的有点烂,先将就用,等熟悉了XPath再来改进 :D
偶然间看到了驴子给豆瓣写的GM脚本
用了下,觉得挺方便
我逛VeryCD和豆瓣一样多
所以反其道而行之
给VeryCD写了个到『豆瓣/射手/google』的速查脚本
// ==UserScript== // @name VeryCD Search // @namespace blog.csdn.net/seven2000 // @description search VeryCD's resources in other site ... // @include http://www.verycd.com/topics/* // ==/UserScript== /* Author: seven2000 Contact: seven3721.inf@gmail.com Creat: March 17th 2009 */ //get Keyword from verycd html page function getKeyword(){ var keyword = ""; var rs = document.evaluate( "//p[@class='checkall']/a", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); var len = rs.snapshotLength; var hrefPrewKey = "http://www.verycd.com/search/folders?kw="; var hrefPrewKeyLen = hrefPrewKey.length; for(var i=0; i<len; i++){ var href = rs.snapshotItem(i).href; var tmp_index = href.indexOf(hrefPrewKey); if(tmp_index!=-1){ keyword = href.substr(tmp_index+hrefPrewKeyLen); keyword = keyword.split("&")[0]; break; } } return keyword; } //the following part based on xiaoyang's code (xiaoyang.tt@gmail.com) //refrence: http://xydonkey.blogbus.com/logs/6892729.html function addGlobalStyle(css) { var head, style; head = document.getElementsByTagName('head')[0]; if (!head) { return; } style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = css; head.appendChild(style); } addGlobalStyle('#myDouban { position: fixed; z-index: 32767; top: 0; right: 0; padding: 0 0 0 20px; min-height: 20px; background: 2px 2px url("chrome://browser/skin/Search-glass.png") no-repeat; }'); addGlobalStyle('#myDouban:hover { padding: 0; }'); addGlobalStyle('#myDouban > div { display: none; }'); addGlobalStyle('#myDouban:hover > div { display: block; padding: 1px 0; background: #f8f8f8; -moz-border-radius: 0 0 0 10px; border: solid #ccc; border-width: 0 0 1px 1px; }'); addGlobalStyle('#myDouban a { margin: 4px 0; padding: 0 10px; font-family: "Verdana"; font-size: 12px; line-height: 14px; font-weight: normal; color: #000000; text-decoration: underline; text-align: left; background: #f8f8f8; border: 0; }'); addGlobalStyle('#myDouban a:hover { color: #f66; }'); //create new element var myDouban = document.createElement('div'); myDouban.setAttribute('id', 'myDouban'); document.body.appendChild(myDouban); var mySearch = document.createElement('div'); myDouban.appendChild(mySearch); var keyword = getKeyword(); var decode_keyword = decodeURIComponent(keyword); //douban mySearch.innerHTML += '<img src="http://www.douban.com/favicon.ico" mce_src="http://www.douban.com/favicon.ico" height="12" width="12" /><a target="_blank" href="http://www.douban.com/subject_search?search_text=" mce_href="http://www.douban.com/subject_search?search_text="'+ keyword +'>'+ 'douban: ' + decode_keyword +'</a>'; mySearch.innerHTML += '<br>'; //shooter mySearch.innerHTML += '<img src="http://shooter.cn/favicon.ico" mce_src="http://shooter.cn/favicon.ico" height="12" width="12" /><a target="_blank" href="http://shooter.cn/sub/?searchword=" mce_href="http://shooter.cn/sub/?searchword="' + keyword +'>'+ 'shooter: ' + decode_keyword +'</a>'; mySearch.innerHTML += '<br>'; //google mySearch.innerHTML += '<img src="http://www.google.com/favicon.ico" mce_src="http://www.google.com/favicon.ico" height="12" width="12" /><a target="_blank" href="http://www.google.com/search?q=" mce_href="http://www.google.com/search?q="'+ keyword +'>'+ 'google: ' + decode_keyword +'</a>';
对Xpath不熟,写的有点烂,先将就用,等熟悉了XPath再来改进 :D
相关文章推荐
- NS-3 MyFirstScriptExample
- My first Python script
- [Ant存档] My First Hand-writing Ant script
- my first shell script
- This is my first blog in CSDN
- Android Monkey --script的使用
- My First Blog
- 2013.11.7-21:15_My first Java program
- Cordova in action学习笔记二:My First Project
- My First blog
- My first app
- my first GC-just 4 fun (c)
- 【菜鸟学android开发】2-破处:My First App on Android
- My first blog!! About a problem in SQL 2005 configuration...
- 背包问题-<DP>-my first DP answer
- The First Day of My Life
- My first article in CSDN.
- My first time on CSDN blog
- 2011斯坦福大学iOS应用开发教程学习笔记(第二课)My First iOS App
- This is to memorize my first day in this blog.