Baidu Tieba快速浏览帖子

模仿googlecode的看帖模式

  1. // ==UserScript==
  2. // @name Baidu Tieba快速浏览帖子
  3. // @namespace http://tieba.baidu.com/f?kw=chrome
  4. // @description 模仿googlecode的看帖模式
  5. // @include http://tieba.baidu.com/f*kw=*
  6. // @include http://tieba.baidu.com/p/*
  7. // @version 14.04.22
  8. // @grant GM_addStyle
  9. // ==/UserScript==
  10. function resize(a,b,c,d,ele1,ele2,doc){
  11. var e=doc.documentElement;
  12. ele1.style.left=a+'px';
  13. ele1.style.top=b+'px';
  14. ele2.style.width=e.offsetWidth-a-d+'px';
  15. ele1.style.height=e.offsetHeight-b-c-10+'px';
  16. ele2.style.height=ele1.clientHeight-21+'px'
  17. }
  18. function sc(a1,b1,c1,d1){
  19. var e1=a1.classList;
  20. if (e1.contains('soc')){
  21. b1.preventDefault();
  22. c1.click()
  23. }
  24. else {
  25. e1.add('soc');
  26. if (d1)
  27. d1()
  28. }
  29. }
  30. function rfc(ele1,ele2,doc){
  31. /*resize后面括号中前四个数字分别为小窗口与浏览器窗口左侧 顶端 下端以及右侧的距离,请自行替换调整相应数值来获取最佳效果*/
  32. var ref=document.getElementById('tab_forumname')||parent.document.getElementById('tab_forumname'),
  33. left;
  34. if(ref){
  35. var refl=ref.offsetLeft,
  36. refw=ref.offsetWidth;
  37. left=refl+refw>95?refl+refw:95
  38. }
  39. else
  40. left=95;
  41. resize(left,85,83,10,ele1,ele2,doc)
  42. }
  43. function w(ele1,ele2,doc){
  44. var m=ele1.classList.contains('ms');
  45. if (!m)
  46. resize(2,2,0,10,ele1,ele2,doc);
  47. else
  48. rfc(ele1,ele2,doc);
  49. ele1.classList.toggle('ms')
  50. }
  51. function removecl(ele,cl){
  52. if (ele.classList.contains(cl))
  53. ele.classList.remove(cl)
  54. }
  55. var script=document.createElement('script'),
  56. code=document.createTextNode('if(!PageData.user.is_login)\n\tPageData.user.is_login=true');
  57. script.type='text/javascript';
  58. script.appendChild(code);
  59. document.body.appendChild(script);
  60. if (window.location.href.indexOf('http://tieba.baidu.com/f?')==0){
  61. var floatkj=document.createElement('div'),
  62. pgn,
  63. idf=function(x){
  64. return document.getElementById(x)
  65. };
  66. floatkj.id='floatdiv';
  67. floatkj.style.visibility='hidden';
  68. floatkj.style.opacity='1';
  69. floatkj.innerHTML='<div id="rq1" align="right" title="按ESC键终止载入,F5键刷新,M键切换窗口大小,Z键聚焦框架,X键聚焦窗口,小键盘4和6键分别向前后翻页">\
  70. <form id="tielistfm" name="tielistfm" style="float:left;margin-left:5px">\
  71. <select id="tielistsel" name="tielistsel" title="按S键切换帖子列表展开/收拢,执行选择按回车键(鼠标操作需点击展开列表)">\
  72. </select>\
  73. </form>\
  74. <img id="first" src="https://ssl.gstatic.com/codesite/ph/images/pagination-first.png" alt="第一帖(F键)"/>\
  75. <img id="previous" src="https://ssl.gstatic.com/codesite/ph/images/pagination-prev.png" alt="上一帖(P键)"/>\
  76. <img id="next" src="https://ssl.gstatic.com/codesite/ph/images/pagination-next.png" alt="下一帖(N键)"/>\
  77. <img id="last" src="https://ssl.gstatic.com/codesite/ph/images/pagination-last.png" alt="最后一帖(L键)"/>\
  78. <img id="kjclosebtn" src="https://ssl.gstatic.com/codesite/ph/images/close_icon.png" title="关闭(ESC键)" alt="关闭(ESC键)"/>\
  79. </div>\
  80. <iframe name="myifrm" id="kjfrm" scrolling="yes" frameborder="0" style="overflow:auto">\
  81. </iframe>';
  82. document.body.appendChild(floatkj);
  83. GM_addStyle('#floatdiv{background-color:rgb(255,255,255);width:auto;height:auto;border:outset 3px rgba(30,144,255,0.7);border-radius:5px;box-shadow:0px 0px 0px 4px rgba(128,128,128,0.7);z-index:10010}\
  84. #floatdiv,#tielistsel{position:fixed}\
  85. #rq1{background-image:linear-gradient(to bottom,rgb(6,76,107),rgb(0,67,90));background-color:rgb(6,76,107)}\
  86. #rq1>img{width:16px;height:16px;margin-left:5px;cursor:pointer}\
  87. #first{margin-left:0}\
  88. #tielistsel{-moz-appearance:none!important;background:none;background-color:rgba(255,255,255,0.7);color:rgba(0,0,0,0.9)}\
  89. #tielistsel>option{background-color:rgba(0,0,0,0.7);color:rgb(255,255,255)}\
  90. div.threadlist_rep_num{cursor: pointer !important}');
  91. var sylj=document.querySelectorAll('a.j_th_tit'),
  92. loc=location.href,
  93. ljArray=[],
  94. update=function(){
  95. if(document.querySelectorAll('a.j_th_tit').length>sylj.length||location.href!=loc){
  96. sylj=document.querySelectorAll('a.j_th_tit');
  97. loc=location.href;
  98. if(location.href!=loc)
  99. ljArray=[];
  100. return true
  101. }
  102. else
  103. return false
  104. },
  105. tiefmsel=document.tielistfm.tielistsel,
  106. makeSel=function(lj){
  107. var tielistnames='',
  108. tiename=Array.prototype.reduce.call(lj,function(a,b,c){
  109. var tn=c+1,
  110. tnt=tn<10?'0'+tn:tn;
  111. tielistnames+='<option>'
  112. +tnt
  113. +'&nbsp;&nbsp;'
  114. +b.innerHTML
  115. +'&nbsp;&nbsp;&nbsp;'
  116. +b.parentNode.parentNode.parentNode.parentNode.querySelector("div.threadlist_rep_num").innerHTML
  117. +'回复&nbsp;BY&nbsp;'
  118. +b.parentNode.nextElementSibling.firstElementChild.title.split(':')[1].trim()
  119. +'</option>';
  120. return tielistnames
  121. },tielistnames);
  122. tiefmsel.innerHTML=tiename;
  123. tiefmsel.selectedIndex=pgn?pgn:0
  124. };
  125. makeSel(sylj);
  126. function addListener(lj){
  127. Array.prototype.forEach.call(lj,function(link,index){
  128. if(ljArray.indexOf(link)>-1)
  129. return;
  130. ljArray.push(link);
  131. var scutdiv=link.parentNode.parentNode.parentNode.parentNode.querySelector('div.threadlist_rep_num');
  132. var timer = null;
  133. scutdiv.addEventListener('mouseover',function(){
  134. clearTimeout(timer);
  135. timer = setTimeout(function(){
  136. if (kj.src==link.href)
  137. return;
  138. if (floatkj.style.visibility!='visible')
  139. floatkj.style.visibility='visible';
  140. if (floatkj.classList.contains('ms')){
  141. rfc(floatkj,kj,document);
  142. floatkj.classList.remove('ms')
  143. }
  144. if(floatkj.style.opacity=='0.3')
  145. floatkj.style.opacity='1';
  146. removecl(floatkj,'soc');
  147. kj.src=link.href;
  148. tiefmsel.selectedIndex=pgn=index;
  149. panp()
  150. }, 1000);
  151. },false);
  152. scutdiv.addEventListener('mouseout',function(){clearTimeout(timer);},false);
  153. })
  154. }
  155. addListener(sylj);
  156. function check(c){
  157. if (c<0)
  158. c=sylj.length-1;
  159. else if (c==sylj.length)
  160. c=0;
  161. return c
  162. }
  163. function page(n){
  164. removecl(floatkj,'soc');
  165. kj.src=n.name;
  166. switch (n){
  167. case ljf: pgn=0;
  168. break;
  169. case ljp: pgn=check(pgn-1);
  170. break;
  171. case ljn: pgn=check(pgn+1);
  172. break;
  173. case ljl: pgn=sylj.length-1;
  174. break
  175. }
  176. panp();
  177. tiefmsel.selectedIndex=pgn
  178. }
  179. function closefrm(){
  180. if (floatkj.style.visibility=='hidden')
  181. return;
  182. kj.src='';
  183. floatkj.style.visibility='hidden'
  184. }
  185. var kj=idf('kjfrm'),
  186. gbkj=idf('kjclosebtn'),
  187. chkxsh=document.querySelector('.wrap1'),
  188. ljf=idf('first'),
  189. ljl=idf('last'),
  190. ljp=idf('previous'),
  191. ljn=idf('next');
  192. function iw(){
  193. kj.contentWindow.focus()
  194. }
  195. kj.addEventListener('load',function(){
  196. if (!floatkj.classList.contains('soc'))
  197. floatkj.classList.add('soc');
  198. this.contentWindow.focus()
  199. },false);
  200. rfc(floatkj,kj,document);
  201. function panpage(btn,idx,ct1,ct2){
  202. btn.title=ct1+'一帖:'+sylj[idx].title+ct2+"键)";
  203. btn.name=sylj[idx].href
  204. }
  205. panpage(ljf,0,'第','(F');
  206. panpage(ljl,sylj.length-1,'最后','(L');
  207. function panp(){
  208. panpage(ljp,check(pgn-1),'上','(P');
  209. panpage(ljn,check(pgn+1),'下','(N');
  210. panpage(ljl,sylj.length-1,'最后','(L')
  211. }
  212. Array.prototype.forEach.call([gbkj,chkxsh,ljf,ljl,ljp,ljn],function(a){
  213. if (a==gbkj || a==chkxsh)
  214. a.addEventListener('click',closefrm,false);
  215. else
  216. a.addEventListener('click',function(){
  217. page(this)
  218. },false)
  219. });
  220. tiefmsel.addEventListener('change',function(){
  221. if (!this.size){
  222. pgn=this.selectedIndex;
  223. removecl(floatkj,'soc');
  224. kj.src=sylj[pgn];
  225. panp();
  226. this.blur()
  227. }
  228. },false);
  229. tiefmsel.addEventListener('blur',function(){
  230. if (this.size){
  231. this.size=0;
  232. this.selectedIndex=pgn
  233. }
  234. iw()
  235. },false);
  236. document.addEventListener('keydown',function(e){
  237. function selcol(evt){
  238. var et=evt.target,
  239. colact=function(){
  240. et.size=0;
  241. et.blur()
  242. };
  243. if (et==tiefmsel)
  244. pgn=et.selectedIndex;
  245. if (kj.src==sylj[pgn]){
  246. colact();
  247. return
  248. }
  249. removecl(floatkj,'soc');
  250. kj.src=sylj[pgn];
  251. panp();
  252. colact()
  253. }
  254. if (floatkj.style.visibility=='visible')
  255. if (e.target.tagName.toLowerCase()!='input' && !e.target.hasAttribute('contenteditable'))
  256. switch (e.keyCode){
  257. case 70: ljf.click();
  258. break;
  259. case 80: ljp.click();
  260. break;
  261. case 78: ljn.click();
  262. break;
  263. case 76: ljl.click();
  264. break;
  265. case 27: sc(floatkj,e,gbkj,iw);
  266. break;
  267. case 83: if(e.target==tiefmsel)e.target.blur();
  268. break;
  269. case 13: selcol(e);
  270. break;
  271. case 77: w(floatkj,kj,document);iw();
  272. break;
  273. case 90: if(floatkj.style.opacity=='0.3')floatkj.style.opacity='1';iw();
  274. break
  275. }
  276. },false);
  277. setInterval(function(){
  278. if(update()){
  279. makeSel(sylj);
  280. addListener(sylj);
  281. panp();
  282. }
  283. },3000)
  284. }
  285. else if (window.top!=window.self){
  286. var id=function(x){
  287. return parent.document.getElementById(x)
  288. },
  289. a=document.querySelector('span.tP'),
  290. changeFocus=function(){
  291. var a=navigator.userAgent,
  292. b=/Chrome/,
  293. c=/Firefox/;
  294. if(id('floatdiv').style.opacity=='1')
  295. id('floatdiv').style.opacity='0.3';
  296. if (b.test(a))
  297. window.parent.focus();
  298. else if (c.test(a))
  299. parent.document.documentElement.focus()
  300. };
  301. document.addEventListener('keydown',function(e){
  302. var pd=parent.document;
  303. if (e.target.tagName.toLowerCase()!='input' && !e.target.hasAttribute('contenteditable'))
  304. switch (e.keyCode){
  305. case 70: id('first').click();
  306. break;
  307. case 80: id('previous').click();
  308. break;
  309. case 78: id('next').click();
  310. break;
  311. case 76: id('last').click();
  312. break;
  313. case 83: var tielistsel=id('tielistsel');tielistsel.size=pd.querySelectorAll('a.j_th_tit').length>20?20:pd.querySelectorAll('a.j_th_tit').length;tielistsel.focus();
  314. break;
  315. case 77: w(id('floatdiv'),id('kjfrm'),pd);
  316. break;
  317. case 116: removecl(id('floatdiv'),'soc');window.location.reload();e.preventDefault();
  318. break;
  319. case 27: sc(id('floatdiv'),e,id('kjclosebtn'));if (/Firefox/.test(navigator.userAgent) && pd.hasFocus(id('kjfrm')))id('kjfrm').blur();
  320. break;
  321. case 100: if (a && a.previousElementSibling){
  322. removecl(id('floatdiv'),'soc');
  323. a.previousElementSibling.click()
  324. }
  325. break;
  326. case 102: if (a && a.nextElementSibling){
  327. removecl(id('floatdiv'),'soc');
  328. a.nextElementSibling.click()
  329. }
  330. break;
  331. case 88: changeFocus();
  332. break
  333. }
  334. },false)
  335. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址