douban小组中的'只看楼主'
此脚本已过时,请访问这个替代 From: notsobad 最近在追着就看豆瓣的那些直播贴,很无聊。。。。 写了个greasemokey脚本,添加了个只看楼主功能。 代码在这里 /********************************************************* 用于douban小组中的"只看搂主",会把楼主的帖子加边框,同时,添加快捷键n,p “n”: 跳转到楼主下一个帖子,如果到了本页结尾,则跳回第一条 "p": 跳转到楼主下一个帖子,如果到了本页结尾,则跳回下一页 *********************************************************/ // ==UserScript== // @name douban // @namespace douban // @description test // @include *.douban.com/* // ==/UserScript== var log = (unsafeWindow.console && console.log) || GM_log; var $ = unsafeWindow.jQuery || function(){}; log("now url: " + location.href); function xPath(aNode, aExpr) { var xpe = new XPathEvaluator(); var nsResolver = xpe.createNSResolver(aNode.ownerDocument == null ? aNode.documentElement : aNode.ownerDocument.documentElement); var result = xpe.evaluate(aExpr, aNode, nsResolver, 0, null); var found = []; var res; while (res = result.iterateNext()) found.push(res); return found; } (function(){ /********************************************************** 用于douban小组中的"只看搂主",会把楼主的帖子加边框,同时,添加快捷键n,p “n”: 跳转到楼主下一个帖子,如果到了本页结尾,则跳回第一条 "p": 跳转到楼主下一个帖子,如果到了本页结尾,则跳回下一页 **********************************************************/ if(location.href.indexOf("http://www.douban.com/group/topic") != 0) return; var temp = /&_lz_id=([^&\/\#]+)/.exec(location.href); if(temp){ var lz_id = temp[1]; var lz_url = "http://www.douban.com/people/"+ lz_id + "/"; }else{ // First page var lz = xPath(document , '//div[@id="in_tablem"]//td[@class="wrtd"][1]/a')[0]; var lz_id = lz.href.split('/people/')[1].replace('/',''); var lz_url = lz.href; } log("lz is: " + lz_url); var all = xPath(document , '//div[@id="in_tablem"]/table[@class="wr"]//table[@class="wr"]'); var pages = xPath(document , '//div[@id="in_tablem"]/div[@class="paginator"]//a'); //为分页链接附加参数,_lz_id Array.forEach(pages, function(p){ var sep = p.href.indexOf('?') != -1 ? '&' : '?'; p.href += sep + '_lz_id=' + lz_id; }); //高亮楼主, 添加锚点 var lz_list = []; Array.forEach(all, function(table, index){ user = table.getElementsByTagName('a')[0]; //log("now user: " + user.href); if(user.href == lz_url){ table.style.border="5px solid black"; table.style.overflow = "scroll"; lz_list.push(index); var a = document.createElement('a'); a.name = index; table.parentNode.insertBefore(a, table); } }); //快捷键 var i = 0; document.addEventListener('keydown', function(e){ if(e.target.tagName == 'INPUT' || e.target.tagName == 'TEXTAREA') return; var has_more = !!lz_list && i < lz_list.length && true; // 'n'=>78, 'p'=>80, 'j'=>74 if(!has_more){ if(e.keyCode == 80) location.href = pages[pages.length-1].href; else if(e.keyCode == 78) i=0; return; } if(e.keyCode == 78 || e.keyCode == 80){ //log('Moving next....'); location.href = '#' + lz_list[i]; i++; } },false); })();