贴吧主页顶部显示楼层列表

让电脑端贴吧使用起来更便利点.增加了顶部楼层列表,跳转按钮

目前为 2020-03-21 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 贴吧主页顶部显示楼层列表
  3. // @namespace http://tampermonkey.net/
  4. // @version 测试(beta)0.351
  5. // @description 让电脑端贴吧使用起来更便利点.增加了顶部楼层列表,跳转按钮
  6. // @include http*://tieba.baidu.com/p/*
  7. // @include http*://tieba.baidu.com/f?*
  8. // @include http*://tieba.baidu.com/f/good?kw=*
  9. // @author shitianshiwa
  10. // @grant none
  11. // @run-at document-idle
  12. // ==/UserScript==
  13. /*能兼容这个链接了https://tieba.baidu.com/f/good?kw=xxxxxx&tab=good*/
  14. (function($) {
  15. 'use strict';
  16. var t1, t2, t3;
  17. var hrefs = window.location.href;
  18. const css1 = `
  19. /*按钮样式*/
  20. .miaocss01
  21. {
  22. display: inline-block;
  23. cursor: pointer;
  24. line-height: normal;
  25. text-decoration: none;
  26. padding: 5px 9px;
  27. font-size: 12px;
  28. background: #fff;
  29. color: #666;
  30. border: 1px solid #e6e6e6;
  31. }
  32. .miaocss02
  33. {
  34. display: inline-block;
  35. cursor: pointer;
  36. line-height: normal;
  37. text-decoration: none;
  38. padding: 5px 9px;
  39. font-size: 12px;
  40. background: #fff;
  41. color: #333;
  42. border: 1px solid #ccc;
  43. background-image: linear-gradient(to bottom,#fcfcfc 0,#f2f2f2 100%);
  44. }
  45. .miaocss03
  46. {
  47. position: relative;
  48. top:0px;
  49. display: inline-block;
  50. width: 45px;
  51. height: 45px;
  52. font-size: 15px;
  53. font-family:"黑体";
  54. font-weight:bold;
  55. background: #ecf2fc;
  56. color: #89a0c5;
  57. border: 1px solid #e6e6e6;
  58. }
  59. .miaocss04
  60. {
  61. position: relative;
  62. top:-5px;
  63. display: inline-block;
  64. width: 48px;
  65. height: 48px;
  66. font-size: 15px;
  67. font-family:"黑体";
  68. font-weight:bold;
  69. background: #fff;
  70. color: #999;
  71. border: 1px solid #e6e6e6;
  72. }
  73. /*鼠标移动到按钮上显示的样式*/
  74. .miaocss01:hover,.miaocss02:hover,.miaocss03:hover,.miaocss04:hover
  75. {
  76. background: #fff;
  77. color: #3e89fa;
  78. border: 1px solid #3e89fa;
  79. }
  80. `;
  81. const style = document.createElement('style'); //创建新样式节点
  82. style.textContent = css1; //添加样式内容
  83. document.head.appendChild(style); //给head头添加新样式节点
  84. //const text0='跳到 <input class="miaojump1" type="text" style="width:40px;" value="1"/> 页&nbsp;<input class="miaojump2" type="button" value="确定"/>';
  85. function louceliebiao() {
  86. try {
  87. //clearTimeout(t2);
  88. //1-------------------------------------------------
  89. if (hrefs.split("?")[0].split("/")[3] == "f" || hrefs.indexOf("tab=album") == -1) //解决非主题列表和贴吧图片区报错
  90. {
  91. if ($("input.miaojump2")[0] != null) //用来解决翻页后,上下楼层列表不一致的问题,删除上面的,然后再生成一次
  92. {
  93. if ($("input.miaojump2")[0].className == "miaojump2 miaocss01") //用跳转确认按钮的class来作条件
  94. {
  95. $("div.miaoliebiao").remove();
  96. //alert("45000000000000000");
  97. }
  98. }
  99. if ($("div.miaoliebiao")[0] == null) {
  100. if ($("#frs_list_pager").html() != null) {
  101. let text1 = '<div class="miaoliebiao"><div id="frs_list_pager" class="pagination-default clearfix" style="position:relative;left:1px;width:968px;background: #FEFEFE;border:1px solid #e4e6eb;padding:5px;">&nbsp;&nbsp;&nbsp;&nbsp;' + $("#frs_list_pager").html() + '</div></div>';
  102. if (hrefs.indexOf("/f/good?kw=") != -1) {
  103. $("div.nav_wrap ").after(text1); //专门给https://tieba.baidu.com/f/good?kw=XXXXX用的
  104. } else {
  105. $("div.head_content").append(text1); //电脑端贴吧主页主题贴列表顶部增加楼层列表
  106.  
  107. }
  108. }
  109. }
  110. $("div.pagination-default").children("a").each(
  111. function() //主题贴列表
  112. {
  113. let a = false;
  114. for (let i = 0; i < $(this)[0].classList.length; i++) {
  115. //alert($(this)[0].classList[i]);
  116. if ($(this)[0].classList[i] == "miaosuo01") //使用class来判断是否注册(不可用)过事件,如果注册(不可用)了就会检测到
  117. {
  118. a = true;
  119. break;
  120. }
  121. }
  122. //alert($(this)[0].className);
  123. if (a == false) {
  124. $(this)[0].classList.add("miaosuo01"); //添加class
  125. $(this).click(function() {
  126. $("input.miaojump2").remove(); //跳转确认按钮
  127. $("div.miaoliebiao").remove(); //上面的楼层列表
  128. //alert("4500");
  129. });
  130. }
  131. //let a=$.data($(this)[0],"events");
  132. //a["click"];//在脚本管理器中没用
  133. });
  134.  
  135. //2--------------------------------------------------------
  136. $("div.frs_good_nav_wrap").children("span").children("a").each(
  137. function() //精品区列表按钮
  138. {
  139. //alert("2233");
  140. let a = false;
  141. for (let i = 0; i < $(this)[0].classList.length; i++) {
  142. //alert($(this)[0].classList[i]);
  143. if ($(this)[0].classList[i] == "miaosuo02") {
  144. a = true;
  145. break;
  146. }
  147. }
  148. if (a == false) {
  149. $(this)[0].classList.add("miaosuo02");
  150. $(this).click(function() {
  151. // alert("6666");
  152. clearInterval(t2); //清除计时器,反正网页跳转没有完成前,又自动添加楼层列表
  153. $("div.miaoliebiao").remove();
  154. t2 = setInterval(() => { louceliebiao(); }, 1000); //延迟1s工作
  155. });
  156. }
  157. });
  158.  
  159. //3--------------------------------------------------
  160. $("input.miaojump2").each(
  161. function() //跳转楼层
  162. {
  163. let a = false;
  164. for (let i = 0; i < $(this)[0].classList.length; i++) {
  165. //alert($(this)[0].classList[i]);
  166. if ($(this)[0].classList[i] == "miaosuo03") {
  167. a = true;
  168. break;
  169. }
  170. }
  171. if (a == false) {
  172. $(this)[0].classList.add("miaosuo03");
  173. $(this).click(
  174. function(event) {
  175. //alert("3333");
  176. //alert(String(event.target.previousElementSibling.value));//event.target.parentNode.childNodes.length-2
  177. clearInterval(t2); //没有原因,反正先关掉计时器
  178. let temp = window.location.href; //得到该网页的链接
  179. if (temp.indexOf("pn") != -1) //用来解决链接无效变长问题,防止无限增加&pn=xxx,https://tieba.baidu.com/f?kw=xxxx&ie=utf-8&tp=0&pn=0&tp=0&pn=0&tp=0&pn=0&tp=0&pn=0
  180. {
  181. let temp2 = temp.split("&"); //字符串切割
  182. let temp3 = temp2[0];
  183. for (let i = 1; i < temp2.length - 1; i++) //字符串数组不要最后一个
  184. {
  185. temp3 = temp3 + "&" + temp2[i]; //字符串合成
  186. //alert(temp2[i]);
  187. }
  188. //alert(temp3);
  189. window.location.href = temp3 + "&pn=" + String(event.target.previousElementSibling.value - 1) * 50; //得到按钮所在地,前一个文本框的内容
  190. } else {
  191. window.location.href = temp + "&pn=" + String(event.target.previousElementSibling.value - 1) * 50;
  192. }
  193. });
  194. //alert($("#miaojump1")[0].value);
  195. //alert(String(window.location.href).split("&")[0]);
  196. //alert(String(window.location.href).split("&")[0]+"&pn="+String(($("#miaojump1")[0].value-1)*50));
  197. }
  198. });
  199. }
  200. } catch (error) {
  201. clearInterval(t2);
  202. alert(error + ",贴吧主页顶部显示楼层列表已停止运行");
  203. }
  204. try {
  205. for (var i = 0; i < 2; i++) //楼层跳转输入框和确定按钮
  206. {
  207. if ($("input.miaojump1")[i] == null && $("div.pagination-default")[0] != null) //只有class可以捕捉多个标签,id不行
  208. {
  209. let temp1 = document.createElement("input"); //创建节点<input/>
  210. temp1.setAttribute('class', 'miaojump1'); //为input添加属性<input class="miaojump1"/>
  211. temp1.setAttribute('type', 'text'); //<input class="miaojump1" type="text"/>
  212. temp1.setAttribute('style', 'width:40px;'); //<input class="miaojump1" type="text" style="width:40px;"/>
  213. temp1.setAttribute('value', '1'); //<input class="miaojump1" type="button" value="1" style="width:40px;"/>
  214. //---------------------------------------------------
  215. let temp2 = document.createElement("input"); //创建节点<input/>
  216. temp2.setAttribute('class', 'miaojump2 miaocss01'); //为input添加属性<input class="miaojump2 miaocss01"/>//贴吧自带的楼层跳转链接样式class为pagination-item
  217. temp2.setAttribute('type', 'button'); //<input class="miaojump2 miaocss01" type="button"/>
  218. temp2.setAttribute('value', '确定'); //<input class="miaojump2 miaocss01" type="button" value="确定"/>
  219. let temp3 = document.querySelectorAll("div.pagination-default");
  220. //---------------------------------------------------
  221. if (temp3[i] != null) {
  222. temp3[i].append(" 跳到: ");
  223. temp3[i].append(temp1); //添加跳转文本框和确认按钮
  224. temp3[i].append(" 页 ");
  225. temp3[i].append(temp2);
  226. }
  227. }
  228. }
  229. } catch (error) {
  230. clearInterval(t2);
  231. alert(error + ",贴吧主页顶部显示楼层列表已停止运行_添加添加跳转文本框和确认按钮");
  232. }
  233. }
  234. //louceliebiao();使用这个的话,重复切换楼层后,上面就不显示楼层列表了
  235. t2 = setInterval(louceliebiao, 1000); //延迟1s工作,等网页基本加载完毕
  236. //t2=setInterval(()=>{louceliebiao();},1000);//延迟1s工作,等网页基本加载完毕
  237. })($);
  238. /*
  239. Jquery attr()方法 属性赋值和属性获取详解
  240. jquery中用attr()方法来获取和设置元素属性,attr是attribute(属性)的缩写,在jQuery DOM操作中会经常用到attr(),attr()有4个表达式。
  241.  
  242. 1. attr( 属性名 )//获取属性的值(取得第一个匹配元素的属性值。通过这个方法可以方便地从第一个匹配元素中获取一个属性的值。如果元素没有相应属性,则返回 undefined )
  243.  
  244. 2. attr( 属性名, 属性值 )//设置属性的值 (为所有匹配的元素设置一个属性值。)
  245.  
  246. 3. attr( 属性名 , 函数值 )//设置属性的函数值 (为所有匹配的元素设置一个计算的属性值。不提供值,而是提供一个函数,由这个函数计算的值作为属性值。)
  247.  
  248. 4. attr(properties)//给指定元素设置多个属性值,即:{属性名一: “属性值一” , 属性名二: “属性值二” , … … }。(这是一种在所有匹配元素中批量设置很多属性的最佳方式。 注意,如果你要设置对象的class属性,你必须使用'className' 作为属性名。或者你可以直接使用'class'或者'id'。)
  249.  
  250. //var hrefx=window.location.href.split(":")[0];
  251. //var p=window.location.href.split("/")[3];
  252. //4--------------------------------------------------
  253. try
  254. {
  255. //4---------------------------------------------------
  256. if($("input.miaotop")[0]==null&&$("input.miaobottom")[0]==null)//主题贴列表滚动条到底
  257. {
  258. //$("div.miaoliebiao").children("div.pagination-default").append(' <input type="button" class="miaobottom miaocss01" value="到网页底部"/>');//增加空格让按钮与前面的按钮隔开点
  259. if(hrefx=="https"||(hrefx=="http"&&p!="p"))
  260. {
  261. $("li.tbui_fbar_top").remove();//删掉贴吧自带的到顶
  262. $("ul.tbui_aside_float_bar").append('<input type="button" class="miaotop miaocss03" value="到顶↑"/><br/>');//增加回车换行
  263. $("ul.tbui_aside_float_bar").append('<input type="button" class="miaobottom miaocss03" value="到底↓"/>');
  264. event_registration();
  265. }
  266. else if(hrefx=="http"&&p=="p")
  267. {
  268. t3=setTimeout(delayed_action,1000);//延迟1s发动动作
  269. }
  270.  
  271. }
  272.  
  273. if($("input.miaobottom2")[0]==null&&$("ul.l_posts_num")[0]!=null)////主题贴滚动条到底
  274. {
  275. //$("ul.l_posts_num")[0].append(' <input type="button" class="miaobottom2" value="到网页底部"/>');//为了可以定位添加节点(一键到底只有贴子顶部有用,一键到顶贴吧自带有),所以使用下面的添加节点方法
  276. let temp2=document.createElement("input");
  277. let temp3=document.querySelectorAll("ul.l_posts_num");
  278. temp2.setAttribute('class','miaobottom2 miaocss02');//btn-sub btn-small贴吧自带的主题贴确定按钮样式
  279. temp2.setAttribute('type','button');
  280. temp2.setAttribute('style','position:relative;left:5px;');
  281. temp2.setAttribute('value','到网页底部');
  282. temp3[0].append(temp2);
  283. $("input.miaobottom2").click(function()
  284. {
  285. window.scrollTo(0,document.body.scrollHeight);
  286. });
  287. }
  288. }
  289. catch(error)
  290. {
  291. alert(error+",主题贴列表滚动条到底未正常运行");
  292. }
  293. function delayed_action()//延迟动作
  294. {
  295. clearTimeout(t3);
  296. $("li.tbui_fbar_top").remove();//删掉贴吧自带的到顶
  297. $("ul.tbui_aside_float_bar").append('<input type="button" class="miaotop miaocss04" value="到顶↑"/><br/>');//增加回车换行
  298. $("ul.tbui_aside_float_bar").append('<input type="button" class="miaobottom miaocss04" value="到底↓"/>');
  299. event_registration();
  300. }
  301. function event_registration()//事件注册(不可用)
  302. {
  303. $("input.miaotop").click(
  304. function()
  305. {
  306. window.scrollTo(0,0);//到顶
  307. });
  308. $("input.miaobottom").click(
  309. function()//到底
  310. {
  311. window.scrollTo(0,document.body.scrollHeight);
  312. });
  313. }
  314. */

QingJ © 2025

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