百度贴吧-宽版

隐藏侧边栏,拓宽贴子的显示宽度,图片变得更清晰,贴吧链接不跳转直接打开,移动版页面自动跳转为PC版

  1. // ==UserScript==
  2. // @name 百度贴吧-宽版
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-9-9
  5. // @description 隐藏侧边栏,拓宽贴子的显示宽度,图片变得更清晰,贴吧链接不跳转直接打开,移动版页面自动跳转为PC版
  6. // @author AN drew
  7. // @match *://tieba.baidu.com/*
  8. // @match *://gsp0.baidu.com/*
  9. // @match *://jump.bdimg.com/safecheck/*
  10. // @match *://jump2.bdimg.com/safecheck/*
  11. // @require https://lib.baomitu.com/jquery/3.5.0/jquery.min.js
  12. // @grant GM_addStyle
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. GM_addStyle(`
  20. .tb_rich_poster .poster_success{left:334px!important} /*发表成功提示居中*/
  21. .af_display_mask{ background: #009eff38} /*图片缩略图聚焦框显示为淡蓝色*/
  22. .p_content img.BDE_Image.origin{ max-width: 810px!important; cursor:pointer!important;} /*图片变大*/
  23. .media_bigpic img{ max-width: 800px!important; cursor:pointer!important;} /*图片变大*/
  24. #ueditor_replace img.BDE_Image{width:auto!important; height:auto!important;}/*编辑区删除图片长宽限制*/
  25. .core_title_theme_bright .core_title_txt{ width: 700px!important;} /*标题变长*/
  26. .post_bubble_top, .post_bubble_middle, .post_bubble_bottom{ width:auto!important } /*拉宽回复气泡*/
  27. /*帖子内容变宽*/
  28. .replace_div{ width: 810px!important; height: auto!important;}
  29. .replace_tip{display:none!important}
  30. .right_section{display:none!important}
  31. /*吧内首页变宽*/
  32. #plat_recom_carousel{visibility:hidden!important}
  33. #aside{display:none!important}
  34. #content_leftList{background:white!important}
  35. .enter_pb_wrapper{left:850px!important;margin-top:-32px!important}/*进入帖子按钮靠右*/
  36. .tbui_aside_fbar_button.tbui_fbar_down{display:none!important}/*隐藏下载按钮*/
  37. .j_poster_share.poster_share .j_use_share{margin-left: 0px;}/*图标对齐*/
  38. .tb_rich_poster .poster_body .editor_bottom_panel{margin: 0 20px 0 0!important;}/*内容恢复提示对齐*/
  39. .passMod_spin-coordinate{z-index:1!important}
  40. /*个人主页变宽*/
  41. .right_aside{display:none!important}
  42. .ihome_body{border:1px solid #87BED9}
  43. .ihome_nav_wrap{margin:0px}
  44. .left_aside{background:white}
  45. .n_right{background:white}
  46. .new_list .n_post_time{margin-right:20px}
  47. .n_right:hover{background-color: #f7f9fc;}
  48. /*隐藏广告*/
  49. #search_back_box{display:none!important}
  50. .lu-search-box{display:none!important}
  51. #search_fengchao{display:none!important}
  52. #search_union_mod{display:none!important}
  53. .af_head_gamelink{display:none!important}
  54. #error_404_iframe{display:none!important}
  55. .ifram-wrapper-gamen-ad{display:none!important}
  56. .fengchao-wrap-feed{display:none!important}
  57. .banner_theme{display:none!important}
  58. .bus-top-activity-wrap{display:none!important}
  59. #mediago-tb-first-floor{display:none!important}
  60. [id*="mediago-tb-"]{display:none!important}
  61. [class*="mediago-ad-"]{display:none!important}
  62. .gift-goin{display:none!important}
  63. #pc2client{display:none!important}
  64. .tb_poster_placeholder{display:none!important}/*隐藏回复框会员特权提示*/
  65. .emotion{background: transparent url(//tb2.bdstatic.com/tb/editor/images/default/fFace.png?t=20140529&t=1675423791162) no-repeat scroll left top;
  66. width: 30px;
  67. height: 30px;
  68. background-position: left -30px;
  69. }
  70. `);
  71.  
  72. //移动版页面自动跳转为PC版
  73. if(window.location.pathname.indexOf('/mo') > -1)
  74. {
  75. var reg = new RegExp('(^|&)' + 'tid' + '=([^&]*)(&|$)', 'i');
  76. var r = window.location.search.substr(1).match(reg);
  77. if (r != null) {
  78. window.location.href='https://tieba.baidu.com/p/'+r[2];
  79. }
  80. }
  81.  
  82. if(window.location.href.indexOf('/photo/')>-1)
  83. {
  84. let right_fold=setInterval(function(){
  85. if($('.af_right_fold.right_close').length>0)
  86. {
  87. $('.af_right_fold').get(0).click();
  88. clearInterval(right_fold);
  89. }
  90. },100);
  91. }
  92.  
  93. if(window.location.href.indexOf('jump.bdimg.com') > -1 || window.location.href.indexOf('jump2.bdimg.com') > -1)
  94. {
  95. window.location.href=$('.link').text();
  96. }
  97.  
  98. let flag=0;
  99.  
  100. setInterval(()=>{
  101.  
  102. if(window.location.href.indexOf('/p/')!= -1) //帖子
  103. {
  104. //帖子内容变宽
  105. if(!$('.left_section').hasClass('wide'))
  106. {
  107. $('.left_section').width($('.pb_content').width());
  108. $('#j_core_title_wrap').width($('.pb_content').width()); //标题栏
  109. $('#j_p_postlist').width($('.pb_content').width()); //内容列表
  110. $('.left_section').addClass('wide');
  111. }
  112.  
  113. $('.l_post_bright').each(function(){
  114. if(!$(this).hasClass('wide'))
  115. {
  116. $(this).width($('.pb_content').width());
  117. $(this).find('.d_post_content_main').width($('.pb_content').width() - 153);
  118. $(this).find('.d_post_content_main .p_content').width($('.pb_content').width() - 173);
  119. $(this).find('.core_reply_tail').width($('.pb_content').width() - 168);
  120. $(this).find('.core_reply_wrapper').width($('.pb_content').width() - 168);
  121. $(this).find('.core_reply_wrapper').width($('.pb_content').width() - 168);
  122. $(this).find('.lzl_editor_container_s').width($('.pb_content').width() - 173);
  123.  
  124. if( $(this).find('.core_reply_wrapper').css('width')!=undefined && parseInt( $(this).find('.core_reply_wrapper').css('width')) >= 800)
  125. {
  126. $(this).addClass('wide');
  127. }
  128. }
  129. //楼中楼回复框
  130. $(this).find('.edui-container').width($('.pb_content').width() - 203);
  131. $(this).find('.p_content .edui-editor-body').width($('.pb_content').width() - 203);
  132. $(this).find('.editor_for_container.editor_lzl_container').width($('.pb_content').width() - 203);
  133. $(this).find('.lzl_simple_wrapper').width($('.pb_content').width() - 203);
  134. $(this).find('.lzl_panel_wrapper').width($('.pb_content').width() - 203);
  135. })
  136.  
  137. /*let furl=$('meta[furl]').attr('furl');*/
  138. /*let barname=furl.match(/(?<=kw=)(.*?)(?=&)/)[0];*/
  139. /*let barname=furl.substring(furl.lastIndexOf('?')+1, furl.lastIndexOf('&'));*/
  140. let barname=encodeURI($('meta[furl]').attr('fname'))
  141. let canonical=$('link[rel="canonical"]').attr('href');
  142. let tid=canonical.substring(canonical.lastIndexOf('/')+1);
  143.  
  144. //图片变清晰
  145. $('.p_content img.BDE_Image').each(function(){
  146. if(!$(this).hasClass('origin'))
  147. {
  148. let pic_src=$(this).attr('src');
  149. let pic_id=pic_src.substring(pic_src.lastIndexOf('/')+1, pic_src.lastIndexOf('.'));
  150. let pic_page="https://tieba.baidu.com/photo/p?kw="+barname+"&flux=1&tid="+tid+"&pic_id="+pic_id+"&pn=1&fp=2&see_lz=1";
  151. let ts=$(this);
  152.  
  153. $.ajax({
  154. url:pic_page,
  155. method:'get',
  156. success:function (res) {
  157. let waterurl=res.substring(res.indexOf('waterurl')+11);
  158. let origin_src=waterurl.substring(0, waterurl.indexOf('\",'));
  159. if(origin_src!=undefined && origin_src!='')
  160. ts.attr('src',origin_src);
  161. }
  162. })
  163.  
  164. $(this).removeAttr('width');
  165. $(this).removeAttr('height');
  166. $(this).removeAttr('style');
  167. $(this).addClass('origin');
  168. $(this).wrap('<a href="'+pic_page+'" target="_blank"></a>');
  169. }
  170. });
  171.  
  172. //发表回复变宽
  173. $('.poster_head').width($('.pb_content').width() - 40);
  174. $('.old_style_wrapper').width($('.pb_content').width() - 70);
  175. $('.old_style_wrapper .edui-container').width($('.pb_content').width() - 70);
  176. $('.edui-toolbar').width($('.pb_content').width() - 70);
  177. $('.old_style_wrapper .edui-editor-body').width($('.pb_content').width() - 70);
  178. $('#ueditor_replace').width($('.old_style_wrapper .edui-editor-body').width() - 20);
  179. $('.poster_component').width($('.pb_content').width() - 40);
  180.  
  181. if($('.tbui_aside_fbar_button tbui_fbar_props').length==0)
  182. {
  183. $('.tb_rich_poster').css('margin','0px');
  184. $('.editor_wrapper').css('margin-left','20px');
  185. }
  186.  
  187. if(!$('title').hasClass('replace'))
  188. {
  189. let title=$('title').text();
  190. if(title.indexOf('[lbk]') > -1)
  191. title=title.replace(/\[lbk\]/g, '[');
  192. if(title.indexOf('[rbk]') > -1)
  193. title=title.replace(/\[rbk\]/g, ']');
  194. $('title').text(title);
  195. $('title').addClass('replace');
  196. }
  197.  
  198. if(!$('.core_title_txt').hasClass('replace'))
  199. {
  200. let title=$('.core_title_txt').text();
  201. if(title.indexOf('[lbk]') > -1)
  202. title=title.replace(/\[lbk\]/g, '[');
  203. if(title.indexOf('[rbk]') > -1)
  204. title=title.replace(/\[rbk\]/g, ']');
  205. $('.core_title_txt').text(title);
  206. $('.core_title_txt').addClass('replace');
  207. }
  208.  
  209. if(flag==0)
  210. {
  211. if($(".d_post_content").length>0)
  212. {
  213. $($(".d_post_content").get(0).childNodes).filter(function() {
  214. return this.nodeType === Node.TEXT_NODE;
  215. }).each(function() {
  216. let title=this.textContent
  217. if(title.indexOf('[lbk]') > -1)
  218. title=title.replace(/\[lbk\]/g, '[');
  219. if(title.indexOf('[rbk]') > -1)
  220. title=title.replace(/\[rbk\]/g, ']');
  221. this.textContent=title;
  222. flag=1;
  223. });
  224. }
  225. }
  226.  
  227. }
  228. else if(window.location.href.indexOf('/home/')!= -1) //个人主页
  229. {
  230. $('.content_wrap').width($('#container').width());
  231. $('.ihome_section').width($('#container').width()-23);
  232. $('.n_right').width($('#container').width()-40);
  233. }
  234. else if(window.location.href.indexOf('/search/')!= -1) //搜索结果页
  235. {
  236. setTimeout(function(){
  237. //图片变清晰
  238. $('.p_content img.BDE_Image').each(function(){
  239. if(!$(this).hasClass('origin'))
  240. {
  241. let barname=encodeURI($(this).closest('.s_post').find('.p_forum .p_violet').text())
  242. let tid=$(this).closest('.s_post').find('.p_title a').attr('data-tid');
  243. let pic_src=$(this).attr('src');
  244. let pic_id=pic_src.substring(pic_src.lastIndexOf('/')+1, pic_src.lastIndexOf('.'));
  245. let pic_page="https://tieba.baidu.com/photo/p?kw="+barname+"&flux=1&tid="+tid+"&pic_id="+pic_id+"&pn=1&fp=2&see_lz=1";
  246. let ts=$(this);
  247.  
  248. $.ajax({
  249. url:pic_page,
  250. method:'get',
  251. success:function (res) {
  252. let waterurl=res.substring(res.indexOf('waterurl')+11);
  253. let origin_src=waterurl.substring(0, waterurl.indexOf('\",'));
  254. if(origin_src!=undefined && origin_src!='')
  255. ts.attr('src',origin_src);
  256. }
  257. })
  258.  
  259. $(this).removeAttr('width');
  260. $(this).removeAttr('height');
  261. $(this).removeAttr('style');
  262. $(this).addClass('origin');
  263. $(this).wrap('<a href="'+pic_page+'" target="_blank"></a>');
  264. }
  265. });
  266. },3000);
  267. }
  268. else //吧内首页
  269. {
  270. //吧内首页变宽
  271. $('#content_wrap').width($('.forum_content').width());
  272.  
  273. //图片变大
  274. $('.media_disp').width($('.forum_content').width() - 120);
  275.  
  276. setTimeout(function(){
  277. if($('.card_title_fname').length>0)
  278. {
  279. let card_title_fname=$('.card_title_fname').attr('href');
  280. /*let barname=card_title_fname.substring(card_title_fname.lastIndexOf('?')+1);*/
  281. let barname=card_title_fname.match(/(?<=kw=)(.*?)(?=&)/)[0];
  282.  
  283. //图片变清晰
  284. $('img.j_retract').each(function(){
  285. if(!$(this).hasClass('origin'))
  286. {
  287. let tid=$(this).closest('li.j_thread_list').attr('data-tid');
  288. let pic_src=$(this).attr('src');
  289. let pic_id=pic_src.substring(pic_src.lastIndexOf('/')+1, pic_src.lastIndexOf('.'));
  290. let pic_page="https://tieba.baidu.com/photo/p?kw="+barname+"&flux=1&tid="+tid+"&pic_id="+pic_id+"&pn=1&fp=2&see_lz=1";
  291. let ts=$(this);
  292.  
  293. $.ajax({
  294. url:pic_page,
  295. method:'get',
  296. success:function (res) {
  297. let waterurl=res.substring(res.indexOf('waterurl')+11);
  298. let origin_src=waterurl.substring(0, waterurl.indexOf('\",'));
  299. if(origin_src!=undefined)
  300. ts.attr('src',origin_src);
  301. }
  302. })
  303.  
  304. $(this).css('max-width', '875px;')
  305. $(this).removeAttr('width');
  306. $(this).removeAttr('height');
  307. $(this).addClass('origin');
  308. //$(this).wrap('<div>');
  309. }
  310. });
  311. }
  312. },3000);
  313.  
  314. //发表回复变宽
  315. if( !$('html').hasClass('tb-ueditor-fullscreen')) //正常状态
  316. {
  317. $('.poster_head').width($('.forum_content').width() - 40);
  318. $('.j_title_wrap').width($('.forum_content').width() - 40);
  319. $('.editor_title').width($('.forum_content').width() - 130);
  320. $('.old_style_wrapper').width($('.forum_content').width() - 40);
  321. $('.old_style_wrapper .edui-container').width($('.forum_content').width() - 40);
  322. $('.edui-toolbar').width($('.forum_content').width() - 70);
  323. $('.edui-editor-body').width($('.forum_content').width() - 42);
  324. $('#ueditor_replace').width($('.old_style_wrapper .edui-editor-body').width() - 20);
  325. }
  326. else //全屏模式
  327. {
  328. $('.poster_head').removeAttr('style');
  329. $('.j_title_wrap').removeAttr('style');
  330. $('.editor_title').removeAttr('style');
  331. $('.old_style_wrapper').removeAttr('style');
  332. $('.old_style_wrapper .edui-container').removeAttr('style');
  333. $('.edui-toolbar').removeAttr('style');
  334. $('.edui-editor-body').removeAttr('style');
  335. }
  336. }
  337.  
  338. $('.j_thread_list a.j_th_tit').each(function(){
  339. if(!$(this).hasClass('replace'))
  340. {
  341. let title=$(this).text();
  342. if(title.indexOf('[lbk]') > -1)
  343. title=title.replace(/\[lbk\]/g, '[');
  344. if(title.indexOf('[rbk]') > -1)
  345. title=title.replace(/\[rbk\]/g, ']');
  346. $(this).text(title);
  347. $(this).addClass('replace')
  348. }
  349. })
  350.  
  351. $('.threadlist_abs.threadlist_abs_onlyline ').each(function(){
  352. if(!$(this).hasClass('replace'))
  353. {
  354. let title=$(this).text();
  355. if(title.indexOf('[lbk]') > -1)
  356. title=title.replace(/\[lbk\]/g, '[');
  357. if(title.indexOf('[rbk]') > -1)
  358. title=title.replace(/\[rbk\]/g, ']');
  359. $(this).text(title);
  360. $(this).addClass('replace')
  361. }
  362. })
  363.  
  364. $('.feed_rich img').each(function(){
  365. if(!$(this).hasClass('done'))
  366. {
  367. let url=$(this).attr('url');
  368. if((url.indexOf('image_emoticon') > -1 || url.indexOf('i_f') > -1))
  369. {
  370. url=url.substring(url.lastIndexOf('/'), url.indexOf('.png'));
  371. let num = url.replace(/[^\d]/g, " ");
  372. if(num<125)
  373. {
  374. $(this).hide();
  375. $(this).attr('onerror'," ");
  376. $(this).attr('src'," ");
  377. let emotion=$('<div class="emotion" href="javascript:void(0)">&nbsp;</div>');
  378. $(this).after(emotion);
  379. if(num==66)
  380. {
  381. $(this).next().css('cssText','display:inline-block;background:url("https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/client/image_emoticon66.png");background-position: left 0px;');
  382. }
  383. else
  384. {
  385. $(this).next().css('cssText','display:inline-block;background-position: left '+(-30*(num-1))+'px;');
  386. }
  387. }
  388. }
  389. $(this).addClass('done');
  390. }
  391. })
  392.  
  393. $('.ec-tuiguang').closest('.thread_item_box').hide();
  394. $('.ec-tuiguang').closest('.l_post').hide();
  395.  
  396. $('div[id*=pagelet_live]').hide();
  397.  
  398. $('.pull_right.label_text').closest('li').hide();
  399. $('.label_text').closest('.l_post').hide();
  400. $('.hover_btn').closest('.clearfix').hide();
  401. },500);
  402.  
  403. })();