CSDN|简书优化

支持手机端和PC端

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

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

QingJ © 2025

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