CSDN|简书优化

支持手机端和PC端

当前为 2021-06-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name CSDN|简书优化
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.4
  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. display:none !important;
  76. }
  77. .comment-list-box{
  78. max-height:none !important;
  79. }
  80. .blog_container_aside,#nav{
  81. margin-left:-45px;
  82. }
  83. .recommend-right.align-items-stretch.clearfix,.dl_right_fixed{
  84. margin-left:45px;
  85. }
  86.  
  87. `)
  88. } else { //手机
  89. if (location.href.match(/csdn.net/g)) {
  90. var Flag_Title_css = `.component-box .praise {
  91. padding-right: 20px;
  92. background: #ff5722;
  93. text-indent: 1em;
  94. border-top-left-radius: 50px;
  95. border-top-right-radius: 50px;
  96. border-bottom-left-radius: 50px;
  97. border-bottom-right-radius: 50px;
  98. background: -webkit-linear-gradient(left,#ff5722,#f78d6b);
  99. background: -o-linear-gradient(right,#ff5722,#f78d6b);
  100. background: -moz-linear-gradient(right,#ff5722,#f78d6b);
  101. background: linear-gradient(to right,#ff5722,#f78d6b);
  102. }
  103. .component-box .praise,.component-box .share {
  104. /*width: 110px;
  105. height: 34px;
  106. line-height: 34px;*/
  107. height:auto;line-height:normal;color: #fff;
  108. }
  109. .component-box a {
  110. display: inline-block;
  111. font-size: 14px;
  112. }
  113. .component-box {
  114. /*margin: 0 auto;
  115. text-align: center;
  116. display: inline;*/
  117. display: flex;
  118. margin: 0;
  119. text-align: left;
  120. font-size: 0;
  121. position: relative;
  122. width: 260px;
  123. }
  124. `
  125.  
  126. function replace_all_commend() { //替换所有的推荐
  127. var commend_list = $(".container-fluid");
  128. console.log(commend_list)
  129. for (var coml = 0; coml < commend_list.length; coml++) {
  130. let current_commend_className = commend_list[coml].getAttribute("class");
  131. let current_commend_url = "";
  132. let current_commend_title = "";
  133. let current_commend_content = "";
  134. let current_commend_img = "";
  135. console.log(current_commend_className)
  136. if (commend_list[coml].getAttribute("data-url")) {
  137. //有data-url 就有recommend_title
  138. console.log("有 data-url");
  139. current_commend_url = commend_list[coml].getAttribute("data-url");
  140. current_commend_title = $(commend_list[coml]).find(".recommend_title").html();
  141. current_commend_content = $(commend_list[coml]).find(".text").html();
  142. // current_commend_title = commend_list[coml].getElementsByClassName("recommend_title")[0].innerHTML;
  143. // current_commend_content = commend_list[coml].getElementsByClassName("text active")[0].innerHTML;
  144. let current_commend_img_dom = $(commend_list[coml]).find(".recommend-img");
  145. if (current_commend_img_dom.length) {
  146. for (var imgs = 0; imgs < current_commend_img_dom.length; imgs++) {
  147. current_commend_img = current_commend_img + current_commend_img_dom[imgs].innerHTML;
  148. }
  149. }
  150.  
  151.  
  152. } else {
  153. console.log("没有data-url");
  154. current_commend_url = commend_list[coml].getElementsByTagName("a")[0].href;
  155. current_commend_title = commend_list[coml].getElementsByTagName("a")[0].innerHTML;
  156. current_commend_content = commend_list[coml].getElementsByClassName("text")[0].innerHTML;
  157. current_commend_img = "";
  158. }
  159. console.log("真实url:", current_commend_url);
  160. if (GM_menus[0][2]) {
  161. current_commend_title = current_commend_title + `<div class="GM-csdn-Redirect">Redirect</div>`;
  162. }
  163. if (current_commend_url.match(/http(s|):\/\/(download.csdn.net|www.iteye.com\/resource)/g)) {
  164. console.log("该链接为csdn资源下载,标识");
  165. current_commend_title = current_commend_title + `<div class="component-box"><a class="praise" href="javascript:;">CSDN下载</a></div>`;
  166. }else if(current_commend_url.match(/edu.csdn.net/g)){
  167. console.log("该链接为csdn学院下载,标识");
  168. current_commend_title = current_commend_title + `<div class="component-box"><a class="csdn-edu-title" href="javascript:;">CSDN学院</a></div>`;
  169. }
  170. commend_list[coml].className = "GM-csdn-dl";
  171. commend_list[coml].setAttribute("data-url", current_commend_url);
  172. commend_list[coml].innerHTML =
  173. `<div class="GM-csdn-title">` + current_commend_title + "</div>" +
  174. `<div class="GM-csdn-content">` + current_commend_content + "</div>" +
  175. `<div class="GM-csdn-img">` + current_commend_img + "</div>"
  176. $("#recommend").find(".recommend_list").before($("#first_recommend_list").find("dl").parent().html())
  177. $("#first_recommend_list").remove();
  178.  
  179. }
  180. }
  181.  
  182. function new_commend_event() { //新的推荐跳转事件
  183. $(".GM-csdn-dl").bind("click", function (e) {
  184. let current_click_url = e.currentTarget.dataset.url;
  185. if (GM_menus[1][2]) {
  186. window.open(current_click_url);
  187. } else {
  188. window.location.href = current_click_url;
  189. }
  190.  
  191. })
  192. }
  193.  
  194. function auto_review() {
  195. //自动展开
  196. $(".article_content").removeAttr("style");
  197. $(".readall_box").show().addClass("readall_box_nobg");
  198. $(".readall_box").hide().addClass("readall_box_nobg");
  199. $(".detail-open-app-isshow").css("display", "block");
  200. $(".isshow-mask-lock-box").show();
  201. }
  202. GM_addStyle(`
  203. #mainBox {
  204. width: auto;
  205. }
  206. #operate,.feed-Sign-span,.view_comment_box, .weixin-shadowbox.wap-shadowbox,.feed-Sign-span{
  207. display:none !important;
  208. }
  209. .GM-csdn-dl{
  210. padding: .24rem .32rem;
  211. width: 100%;
  212. justify-content: space-between;
  213. -webkit-box-pack: justify;
  214. border-bottom: 1px solid #F5F6F7!important;
  215.  
  216. }
  217. .GM-csdn-title{
  218. font-size: .3rem;
  219. color: #222226;
  220. letter-spacing: 0;
  221. line-height: .44rem;
  222. font-weight: 600;
  223. //max-height: .88rem;
  224. word-break: break-all;
  225. overflow: hidden;
  226. display: -webkit-box;
  227. -webkit-box-orient: vertical;
  228. -webkit-line-clamp: 2
  229. }
  230. .GM-csdn-title a{
  231. word-break: break-all;
  232. color: #222226;
  233. font-weight: 600;
  234. }
  235. .GM-csdn-title em,.GM-csdn-content em{
  236. font-style: normal;
  237. color: #fc5531
  238. }
  239. .GM-csdn-content{
  240.  
  241. //max-width: 5.58rem;
  242. overflow: hidden;
  243. text-overflow: ellipsis;
  244. display: -webkit-box;
  245. -webkit-line-clamp: 1;
  246. -webkit-box-orient: vertical;
  247. color: #555666;
  248. font-size: .24rem;
  249. line-height: .34rem;
  250. max-height: .34rem;
  251. word-break: break-all;
  252. -webkit-box-flex: 1;
  253. -ms-flex: 1;
  254. flex: 1;
  255. margin-top: .16rem;
  256.  
  257. }
  258. .GM-csdn-img img{
  259. width: 2.18rem;
  260. height: 1.58rem;
  261. //margin-left: .16rem
  262. }
  263. .GM-csdn-Redirect{
  264. color: #555;
  265. background-color: #fcfcfc;
  266. font-family: sans-serif;
  267. margin: auto 2px;
  268. border: 2px solid #ccc;
  269. border-radius: 4px;
  270. padding: 0px 3px;
  271. font-size: xx-small;
  272. display: inline;
  273. }
  274. .component-box .praise {
  275. background: #ff5722;
  276. border-radius: 5px;
  277. padding: 0px 8px;
  278. height: auto;
  279. }
  280. .component-box .praise,.component-box .share {
  281. color: #fff;
  282. }
  283. .component-box a {
  284. display: inline-block;
  285. font-size:xx-small;
  286. }
  287. .component-box {
  288. display: inline;
  289. margin: 0;
  290. position: relative;
  291. }
  292. .csdn-edu-title{
  293. background: #4d6de1;
  294. border-radius: 5px;
  295. padding: 0px 8px;
  296. height: auto;
  297. color: #fff !important;
  298. }
  299.  
  300. `)
  301.  
  302. $(document).ready(function () {
  303. console.log("mobile csdn");
  304. var csdn_interval_runum = 0;
  305. var csdn_interval = setInterval(function () {
  306. csdn_interval_runum = csdn_interval_runum + 1;
  307. console.log("展开");
  308. if (csdn_interval_runum <= 5) {
  309. try {
  310. auto_review();
  311. } catch (err) {
  312. console.log("自动展开全文失败", err)
  313. }
  314. } else {
  315. clearInterval(csdn_interval)
  316. }
  317.  
  318. }, 200)
  319.  
  320. var loding_comment_dom_num = 0
  321. var loding_comment_dom = setInterval(function () {
  322. console.log(loding_comment_dom_num)
  323. loding_comment_dom_num = loding_comment_dom_num + 1;
  324. if (loding_comment_dom_num <= 5) {
  325. try {
  326. replace_all_commend();
  327. } catch (err) {
  328. console.log("替换底部链接失败", err);
  329. }
  330.  
  331. } else {
  332. clearInterval(loding_comment_dom);
  333. new_commend_event();
  334. }
  335. }, 500)
  336.  
  337.  
  338. });
  339. } else if (location.href.match(/jianshu.com/g)) {
  340. console.log("简书");
  341. GM_addStyle(`
  342. .download-app-guidance,
  343. .call-app-btn,
  344. .collapse-tips,
  345. .note-graceful-button,
  346. .header-wrap{
  347. display:none !important;
  348. }
  349. .collapse-free-content{
  350. height:auto !important;
  351. }
  352. .copyright{
  353. color:#000 !important;
  354. }
  355. #note-show .content .show-content-free .collapse-free-content:after{
  356. background-image:none !important;
  357. }
  358. `)
  359. }
  360. }
  361.  
  362.  
  363.  
  364. })();