CSDN|简书优化

支持手机端和PC端

当前为 2022-05-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name CSDN|简书优化
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.9
  5. // @description 支持手机端和PC端
  6. // @author MT-戒酒的李白染
  7. // @include http*://www.csdn.net/*
  8. // @include http*://bbs.csdn.net/*
  9. // @include http*://www.jianshu.com/*
  10. // @include http*://*blog.csdn.net/*
  11. // @include http*://download.csdn.net/*
  12. // @grant GM_addStyle
  13. // @grant GM_registerMenuCommand
  14. // @grant GM_unregisterMenuCommand
  15. // @grant GM_getValue
  16. // @grant GM_setValue
  17. // @grant GM_deleteValue
  18. // @grant GM_listValues
  19. // @run-at document-start
  20. // @require http://cdn.staticfile.org/jquery/2.1.4/jquery.min.js
  21. // ==/UserScript==
  22.  
  23. (function () {
  24. 'use strict';
  25. var GM_menus = [
  26. ["menu_showRedirect", "手机csdn显示Redirect", true],
  27. ["menu_thistab", "手机csdn新页面打开", true]
  28. ]
  29.  
  30. function change_normal_menu() {
  31. //修改菜单默认值
  32. console.log(GM_listValues())
  33. for (let i = 0; i < GM_menus.length; i++) {
  34. let get_GM_value = GM_getValue(GM_menus[i][0]);
  35. if (get_GM_value) {
  36.  
  37. } else {
  38. console.log("修改菜单值");
  39. GM_menus[i][2] = false;
  40. }
  41. console.log(GM_menus);
  42. }
  43. }
  44.  
  45. function register_GM_Menu() {
  46. //注册油猴菜单
  47. for (let i = 0; i < GM_menus.length; i++) {
  48. let current_v = GM_menus[i][0];
  49. let current_name = GM_menus[i][1];
  50. let current_status = GM_menus[i][2];
  51. GM_registerMenuCommand(`[${current_status?"√":"×"}]${current_name}`, function () {
  52. if (current_status) {
  53. console.log("关闭");
  54. GM_deleteValue(current_v);
  55. } else {
  56. console.log("开启");
  57. GM_setValue(current_v, "1");
  58. }
  59. window.location.reload();
  60. })
  61. }
  62.  
  63. }
  64. change_normal_menu();
  65. register_GM_Menu();
  66. var usa = navigator.userAgent.match('Windows');
  67.  
  68. if (usa !== null) { //电脑
  69. GM_addStyle(`
  70. .ecommend-item-box.recommend-recommend-box,
  71. .login-mark,
  72. .opt-box.text-center,
  73. .leftPop,
  74. #csdn-shop-window,
  75. #passportbox,
  76. .passport-login-container,
  77. .toolbar-advert{
  78. display:none !important;
  79. }
  80. .comment-list-box{
  81. max-height:none !important;
  82. }
  83. .blog_container_aside,#nav{
  84. margin-left:-45px;
  85. }
  86. .recommend-right.align-items-stretch.clearfix,.dl_right_fixed{
  87. margin-left:45px;
  88. }
  89.  
  90. `)
  91.  
  92. } else { //手机
  93. if (location.href.match(/csdn.net/g)) {
  94. var Flag_Title_css = `
  95. .component-box .praise {
  96. padding-right: 20px;
  97. background: #ff5722;
  98. text-indent: 1em;
  99. border-top-left-radius: 50px;
  100. border-top-right-radius: 50px;
  101. border-bottom-left-radius: 50px;
  102. border-bottom-right-radius: 50px;
  103. background: -webkit-linear-gradient(left,#ff5722,#f78d6b);
  104. background: -o-linear-gradient(right,#ff5722,#f78d6b);
  105. background: -moz-linear-gradient(right,#ff5722,#f78d6b);
  106. background: linear-gradient(to right,#ff5722,#f78d6b);
  107. }
  108. .component-box .praise,.component-box .share {
  109. /*width: 110px;
  110. height: 34px;
  111. line-height: 34px;*/
  112. height:auto;line-height:normal;color: #fff;
  113. }
  114. .component-box a {
  115. display: inline-block;
  116. font-size: 14px;
  117. }
  118. .component-box {
  119. /*margin: 0 auto;
  120. text-align: center;
  121. display: inline;*/
  122. display: flex;
  123. margin: 0;
  124. text-align: left;
  125. font-size: 0;
  126. position: relative;
  127. width: 260px;
  128. }
  129. `
  130.  
  131. function replace_all_commend() { //替换所有的推荐
  132. var commend_list = $(".container-fluid");
  133. console.log(commend_list)
  134. for (var coml = 0; coml < commend_list.length; coml++) {
  135. let current_commend_className = commend_list[coml].getAttribute("class");
  136. let current_commend_url = "";
  137. let current_commend_title = "";
  138. let current_commend_content = "";
  139. let current_commend_img = "";
  140. console.log(current_commend_className)
  141. if (commend_list[coml].getAttribute("data-url")) {
  142. //有data-url 就有recommend_title
  143. console.log("有 data-url");
  144. current_commend_url = commend_list[coml].getAttribute("data-url");
  145. current_commend_title = $(commend_list[coml]).find(".recommend_title").html();
  146. current_commend_content = $(commend_list[coml]).find(".text").html();
  147. // current_commend_title = commend_list[coml].getElementsByClassName("recommend_title")[0].innerHTML;
  148. // current_commend_content = commend_list[coml].getElementsByClassName("text active")[0].innerHTML;
  149. let current_commend_img_dom = $(commend_list[coml]).find(".recommend-img");
  150. if (current_commend_img_dom.length) {
  151. for (var imgs = 0; imgs < current_commend_img_dom.length; imgs++) {
  152. current_commend_img = current_commend_img + current_commend_img_dom[imgs].innerHTML;
  153. }
  154. }
  155.  
  156.  
  157. } else {
  158. console.log("没有data-url");
  159. current_commend_url = commend_list[coml].getElementsByTagName("a")[0].href;
  160. current_commend_title = commend_list[coml].getElementsByTagName("a")[0].innerHTML;
  161. current_commend_content = commend_list[coml].getElementsByClassName("text")[0].innerHTML;
  162. current_commend_img = "";
  163. }
  164. console.log("真实url:", current_commend_url);
  165. if (GM_menus[0][2]) {
  166. current_commend_title = current_commend_title + `<div class="GM-csdn-Redirect">Redirect</div>`;
  167. }
  168. if (current_commend_url.match(/http(s|):\/\/(download.csdn.net|www.iteye.com\/resource)/g)) {
  169. console.log("该链接为csdn资源下载,标识");
  170. current_commend_title = current_commend_title + `<div class="component-box"><a class="praise" href="javascript:;">CSDN下载</a></div>`;
  171. } else if (current_commend_url.match(/edu.csdn.net/g)) {
  172. console.log("该链接为csdn学院下载,标识");
  173. current_commend_title = current_commend_title + `<div class="component-box"><a class="csdn-edu-title" href="javascript:;">CSDN学院</a></div>`;
  174. }
  175. commend_list[coml].className = "GM-csdn-dl";
  176. commend_list[coml].setAttribute("data-url", current_commend_url);
  177. commend_list[coml].innerHTML =
  178. `<div class="GM-csdn-title">` + current_commend_title + "</div>" +
  179. `<div class="GM-csdn-content">` + current_commend_content + "</div>" +
  180. `<div class="GM-csdn-img">` + current_commend_img + "</div>"
  181. $("#recommend").find(".recommend_list").before($("#first_recommend_list").find("dl").parent().html())
  182. $("#first_recommend_list").remove();
  183.  
  184. }
  185. }
  186.  
  187. function new_commend_event() { //新的推荐跳转事件
  188. $(".GM-csdn-dl").bind("click", function (e) {
  189. let current_click_url = e.currentTarget.dataset.url;
  190. if (GM_menus[1][2]) {
  191. window.open(current_click_url);
  192. } else {
  193. window.location.href = current_click_url;
  194. }
  195.  
  196. })
  197. }
  198.  
  199. function auto_review() {
  200. //自动展开
  201. $(".article_content").removeAttr("style");
  202. $(".readall_box").show().addClass("readall_box_nobg");
  203. $(".readall_box").hide().addClass("readall_box_nobg");
  204. $(".detail-open-app-isshow").css("display", "block");
  205. $(".isshow-mask-lock-box").show();
  206. }
  207. GM_addStyle(`
  208. #mainBox {
  209. width: auto;
  210. }
  211. #operate,.feed-Sign-span,
  212. .view_comment_box,
  213. .weixin-shadowbox.wap-shadowbox,
  214. .feed-Sign-span{
  215. display:none !important;
  216. }
  217. .GM-csdn-dl{
  218. padding: .24rem .32rem;
  219. width: 100%;
  220. justify-content: space-between;
  221. -webkit-box-pack: justify;
  222. border-bottom: 1px solid #F5F6F7!important;
  223.  
  224. }
  225. .GM-csdn-title{
  226. font-size: .3rem;
  227. color: #222226;
  228. letter-spacing: 0;
  229. line-height: .44rem;
  230. font-weight: 600;
  231. //max-height: .88rem;
  232. word-break: break-all;
  233. overflow: hidden;
  234. display: -webkit-box;
  235. -webkit-box-orient: vertical;
  236. -webkit-line-clamp: 2
  237. }
  238. .GM-csdn-title a{
  239. word-break: break-all;
  240. color: #222226;
  241. font-weight: 600;
  242. }
  243. .GM-csdn-title em,.GM-csdn-content em{
  244. font-style: normal;
  245. color: #fc5531
  246. }
  247. .GM-csdn-content{
  248. //max-width: 5.58rem;
  249. overflow: hidden;
  250. text-overflow: ellipsis;
  251. display: -webkit-box;
  252. -webkit-line-clamp: 1;
  253. -webkit-box-orient: vertical;
  254. color: #555666;
  255. font-size: .24rem;
  256. line-height: .34rem;
  257. max-height: .34rem;
  258. word-break: break-all;
  259. -webkit-box-flex: 1;
  260. -ms-flex: 1;
  261. flex: 1;
  262. margin-top: .16rem;
  263. }
  264. .GM-csdn-img img{
  265. width: 2.18rem;
  266. height: 1.58rem;
  267. //margin-left: .16rem
  268. }
  269. .GM-csdn-Redirect{
  270. color: #555;
  271. background-color: #fcfcfc;
  272. font-family: sans-serif;
  273. margin: auto 2px;
  274. border: 2px solid #ccc;
  275. border-radius: 4px;
  276. padding: 0px 3px;
  277. font-size: xx-small;
  278. display: inline;
  279. white-space:nowrap;
  280. }
  281. .component-box .praise {
  282. background: #ff5722;
  283. border-radius: 5px;
  284. padding: 0px 8px;
  285. height: auto;
  286. }
  287. .component-box .praise,.component-box .share {
  288. color: #fff;
  289. }
  290. .component-box a {
  291. display: inline-block;
  292. font-size:xx-small;
  293. }
  294. .component-box {
  295. display: inline;
  296. margin: 0;
  297. position: relative;
  298. white-space:nowrap;
  299. }
  300. .csdn-edu-title{
  301. background: #4d6de1;
  302. border-radius: 5px;
  303. padding: 0px 8px;
  304. height: auto;
  305. color: #fff !important;
  306. }
  307. #comment{
  308. max-height: none !important;
  309. }
  310. .comment_read_more_box,
  311. #content_views pre.set-code-hide .hide-preCode-box,
  312. .hljs-button[data-title="登录后复制"]{
  313. display:none !important;
  314. }
  315. #content_views pre,
  316. #content_views pre code{
  317. webkit-touch-callout: text !important;
  318. -webkit-user-select: text !important;
  319. -khtml-user-select: text !important;
  320. -moz-user-select: text !important;
  321. -ms-user-select: text !important;
  322. user-select: text !important;
  323. }
  324. #content_views pre.set-code-hide{
  325. height: 100% !important;
  326. overflow-y: auto !important;
  327. }
  328. `)
  329.  
  330. $(document).ready(function () {
  331. console.log("mobile csdn");
  332. var csdn_interval_runum = 0;
  333. var csdn_interval = setInterval(function () {
  334. csdn_interval_runum = csdn_interval_runum + 1;
  335. console.log("展开");
  336. if (csdn_interval_runum <= 5) {
  337. try {
  338. auto_review();
  339. } catch (err) {
  340. console.log("自动展开全文失败", err)
  341. }
  342. } else {
  343. clearInterval(csdn_interval)
  344. }
  345.  
  346. }, 200)
  347. var loding_comment_dom_num = 0
  348. var loding_comment_dom = setInterval(function () {
  349. console.log(loding_comment_dom_num)
  350. loding_comment_dom_num = loding_comment_dom_num + 1;
  351. if (loding_comment_dom_num <= 5) {
  352. try {
  353. replace_all_commend();
  354. } catch (err) {
  355. console.log("替换底部链接失败", err);
  356. }
  357.  
  358. } else {
  359. clearInterval(loding_comment_dom);
  360. new_commend_event();
  361. }
  362. }, 500)
  363.  
  364.  
  365. });
  366. } else if (location.href.match(/jianshu.com/g)) {
  367. console.log("简书");
  368. GM_addStyle(`
  369. .download-app-guidance,
  370. .call-app-btn,
  371. .collapse-tips,
  372. .note-graceful-button,
  373. .app-open,
  374. .header-wrap{
  375. display:none !important;
  376. }
  377. body.reader-day-mode.normal-size {
  378. overflow: auto !important;
  379. }
  380. .collapse-free-content{
  381. height:auto !important;
  382. }
  383. .copyright{
  384. color:#000 !important;
  385. }
  386. #note-show .content .show-content-free .collapse-free-content:after{
  387. background-image:none !important;
  388. }
  389. `)
  390. }
  391. }
  392. })();