本博客再次搬家,感谢那些从QQ空间一路追踪到这里的朋友。胜利就在眼前了,再跳转一次你就能到达胜利的彼岸了。
目的地就是——http://www.idalin.cn ,爱生活,idalin.cn
greasemonkey脚本初试
上一篇 /
下一篇 2006-06-27 00:05:39 / 天气: 晴朗
/ 心情: 高兴
/ 精华(3)
/ 个人分类:技术文章
GreaseMonkey是一款很棒的FF扩展,它有通过编写脚本来改变被访问网页的功能。使用它,能使您访问的网站更便于阅读或者更便于使用。使用它,您能修复网页渲染的缺陷,而无须烦扰网站管理员。
使用它,您能让网页更好地使用残疾人援助技术,清楚响亮地说出网页内容,或者将网页内容变为盲文。使用它,您能自动地获得其它网站的数据,从而使两个网站
更好地相互链接起来。
点击查看更详细介绍 今晚闲来无事,就看了看
Dive Into Greasemonkey这个教材,然后试着写了第一个greasemonkey脚本:
// Ignore // version 0.1 BETA! // 2006-06-26 // Copyright (c) 2006, dalin // Released under the GPL license // http://www.gnu.org/copyleft/gpl.html // // -------------------------------------------------------------------- // // This is a Greasemonkey user script. // // To install, you need Greasemonkey: http://greasemonkey.mozdev.org/ // Then restart Firefox and revisit this script. // Under Tools, there will be a new menu item to "Install User Script". // Accept the default configuration and install. // // To uninstall, go to Tools/Manage User Scripts, // select "Ignore", and click Uninstall. // // -------------------------------------------------------------------- // ==UserScript== // @name Ignore // @namespace http://dalin.linuxsky.net // @description to ignore someone's post in Shuiyuan // @include http://linuxfans.org/nuke/modules.php?name=Forums&file=viewforum&f=1 // @include http://linuxfans.org/nuke/modules.php?name=Forums&file=viewforum&f=1&* // @include http://www.linuxfans.org/nuke/modules.php?name=Forums&file=viewforum&f=1 // @include http://www.linuxfans.org/nuke/modules.php?name=Forums&file=viewforum&f=1&* // ==/UserScript==
var allTables,theTable,thisLink,allSpans,thisSpan; var toBeIgnored; toBeIgnored=""; //这里填入你想忽略的那个人的ID就行了,比如dalin。 allTables = document.getElementsByTagName('table');
allTables = document.evaluate( '//table[@class]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); for(i=0;allTables.snapshotLength; i++){ theTable =allTables.snapshotItem(i); allSpans=document.evaluate( "//span[@class='name']", theTable, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); for(j=0;j<allSpans.snapshotLength; j++){ thisSpan=allSpans.snapshotItem(j); thisLink = thisSpan.getElementsByTagName('a'); if(thisLink[0].innerHTML == toBeIgnored){ thisSpan.parentNode.parentNode.innerHTML=''; } } } |
这个脚本的功能是,在
水园里,将特定的人发的帖子过滤掉,使其不在帖子列表中出现。意义其实不大,不过写的过程中,涵盖了很多写greasemonkey的知识,对学习有所帮助。要不然的话,写一个过滤掉“单反”两个字的脚本实用价值更大,现在看到“单反”两个字就想吐了(大H阿姨害的啊),不过这样的脚本很容易写,弄出来也没什么成就感,呵呵
导入论坛
引用链接
收藏
分享给好友
管理
举报
TAG:
技术文章