Programer's Web Friend

change Programer's Web style to mobile device friendly ,and more readble

目前为 2018-09-19 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Programer's Web Friend
  3. // @namespace https://tampermonkey.net/
  4. // @version 1.9.13
  5. // @description change Programer's Web style to mobile device friendly ,and more readble
  6. // @author @Amormaid
  7. // @run-at document-end
  8. // /*@require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js */
  9. // /*@require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js */
  10. // @match http://*/*
  11.  
  12. // @include http://*
  13. // @include https://*
  14.  
  15. // @exclude http://localhost*
  16. // @exclude https://www.youtube.com/*
  17. // @exclude http://demo.mycodes.net/*
  18. // @exclude https://kiwivm.64clouds.com/*
  19. // @exclude https://www.instagram.com/*
  20. // @exclude http://www.h-ui.net/*
  21. // @exclude http://www.layui.com*
  22. // @exclude https://www.kixeye.com*
  23. // @exclude https://pan.baidu.com*
  24. // @exclude https://www.rishiqing.com*
  25. // @exclude https://wx.qq.com*
  26. // @exclude https://mail.126.com*
  27. // @exclude https://twitter.com*
  28. // @exclude https://reactjs.org*
  29. // @exclude https://codepen.io*
  30. // @exclude http://mail.wellav.com*
  31. // @exclude http://webserver.com/*
  32. // @exclude http://cr.sencore.com/*
  33. // @exclude https://free.modao.cc/*
  34.  
  35.  
  36. // @license MIT License
  37. // @grant none
  38. // ==/UserScript==
  39.  
  40. /* jshint ignore:start */
  41. //var inline_src = (<><![CDATA[
  42. /* jshint ignore:end */
  43. /* jshint esnext: false */
  44. /* jshint esversion: 6 */
  45.  
  46.  
  47. /*
  48. if(typeof(jQuery) === 'undefined'){
  49. var jquery_script = document.createElement('script');
  50. jquery_script.src = 'https://code.jquery.com/jquery-3.2.1.min.js';
  51. document.body.append(jquery_script);
  52. }
  53. */
  54.  
  55.  
  56.  
  57. var root= document.body;
  58. var links = /\d+\.\d+\.\d+\.\d+/.test(window.location.hostname) ? "ip" : window.location.hostname;
  59. var remove_div,elem,elem_2, arr,ad_ele,remove_ele;
  60. var content_old,content_new;
  61.  
  62. window.change_style_flag = true;
  63.  
  64.  
  65. try{
  66.  
  67. console.time("allen_web_time_count");
  68.  
  69. switch(links){
  70.  
  71. case "ip":
  72. //content_get();
  73. break;
  74.  
  75. case "wc-kx-vip.sjc.kixeye.com":
  76. $$('#above-game-message','remove_one');
  77. $$('#kxp-footer-bar','remove_one');
  78. $$('#topnavbar_back','remove_one');
  79. break;
  80.  
  81. case "www.baidu.com":
  82. case "zhidao.baidu.com":
  83. var zhidao_body = $$("#body","return_one");
  84. var container = $$("#container","return_one");
  85. var head = $$("#head","return_one");
  86. var pad = $$("#s_tab","return_one");
  87. var u = $$("#u","return_one");
  88. var setInterval_id;
  89.  
  90. zhidao_body && (function(){zhidao_body.style.left = "50px"})();
  91. container && (function(){container.style.width = "700px"})();
  92. head && (function(){
  93. head.style.position = 'relative';
  94. head.style.width = window.innerWidth-100+'px';
  95. head.style['min-width'] = 0;
  96. })();
  97. pad && (function(){pad.style.padding = '0 0 0 121px'})();
  98. u && (function(){u.style.display = 'none'})();
  99.  
  100. document.body.style['min-width'] = '10px';
  101.  
  102. setInterval_id = setInterval(function(){
  103. if($$("#content_right",'return_all') ){
  104. $$("#content_right",'remove_all');
  105. var count = window.clear_count || 0;
  106. count++;
  107. window.clear_count = count;
  108. count > 99 && clearInterval(setInterval_id);
  109. }
  110. },100);
  111. break;
  112.  
  113. case "www.cnblogs.com":
  114. case "blog.csdn.net":
  115. var content = $$("#content","return_one");
  116. $$("#sidebar","remove_one");
  117. $$("#side",'remove_one');
  118.  
  119. content && (function(){
  120. content.style["margin-right"] = "10";
  121. content.style.width = window.innerWidth-100+'px';
  122. })();
  123. break;
  124. case "www.w3school.com.cn":
  125. $$("#navsecond",'hide_one');
  126. break;
  127.  
  128. case "wallstreetcn.com":
  129.  
  130. setInterval(function(){
  131. $$('.news-item__cover','remove_all');
  132. change_style();
  133. },500);
  134.  
  135. $$('.left-bar','remove_one');
  136. break;
  137.  
  138. case "www.merriam-webster.com":
  139. $$(".right-rail",'hide_one');
  140. $$("#recirc-bar-footer",'hide_one');
  141. $$(".wgt-related-to.jc-card-box.clearfix",'hide_one');
  142. break;
  143.  
  144. case "blog.sina.com.cn":
  145. $$("#column_1",'hide_one');
  146. break;
  147.  
  148. case "blog.jobbole.com":
  149. case "web.jobbole.com":
  150. $$("#sidebar",'hide_one');
  151. var grid = $$(".grid-8",'return_one');
  152. grid && (function(){grid.style.width = "100%"})();
  153. break;
  154.  
  155. case "juejin.im":
  156. var interval_id = setInterval(function(){
  157. var a = document.getElementsByClassName("show-full")[0];
  158. var b = document.getElementsByClassName("show-full-block")[0];
  159. var c = document.getElementsByClassName(" show-full-btn")[0];
  160.  
  161. $$('.columen-view-aside','hide_one');
  162.  
  163. if(a)a.style.height = "auto";
  164. if(b){
  165. clearInterval(interval_id);
  166. b.style.height = "auto";
  167. }
  168. if(c)c.style.display = "none";
  169.  
  170. },100);
  171. break;
  172.  
  173. case "www.cnblogs.com":
  174. $$("#sideBar",'hide_one');
  175. $$("#vid",'hide_one');
  176. $$("#left",'hide_one');
  177. $$("#right_content",'hide_one');
  178. $$("#leftcontent",'hide_one');
  179. var a = $$("#centercontent",'return_one');
  180. if(a){a.style['padding-left'] = 0;}
  181. break;
  182.  
  183. case "github.com":
  184. document.body.style.minWidth = '100px';
  185. var github_pad = document.querySelector('.column.three-fourths.codesearch-results.pr-6') ;
  186. if(github_pad ){
  187. github_pad.style.padding = '10px 0 10px 30px';
  188. }
  189. //change_style(,{'max-width':document.body.clientWidth+'px'});
  190. break;
  191.  
  192. case "wiki.jikexueyuan.com":
  193. $$(".detail-left",'hide_one');
  194. var a = $$(".detail-main",'no_option','one');
  195. a.style['margin-left'] = '0px';
  196. a.style.width = document.body.clientWidth+'px';
  197. break;
  198.  
  199. case "www.cssmoban.com":
  200. var a = $$(".wide-main.col-media-main.clearfix",'return_one');
  201. a.style.width = document.body.clientWidth+'px';
  202. break;
  203.  
  204. case "www.kancloud.cn":
  205. var interval_id = setInterval(function(){
  206. if(document.querySelector(".sidebar")){
  207. var a = document.querySelector(".sidebar");
  208. document.querySelector(".workspace").style.left = "180px";
  209. a.style.width = '180px';
  210. change_style(a);
  211. clearInterval(interval_id);
  212. }
  213. },100);
  214. break;
  215.  
  216. case "php.net":
  217. $$('.layout-menu','remove_one');
  218. if($$(".sect1",'return_one'))$$(".sect1",'return_one').style.width = document.body.clientWidth-50+"px";
  219. if($$("#usernotes",'return_one'))$$("#usernotes",'return_one').style.width = document.body.clientWidth-50+"px";
  220. break;
  221.  
  222. case "www.zhihu.com":
  223. $$('.Question-sideColumn.Question-sideColumn--sticky','remove_one');
  224. $$('.AdblockBanner-inner','remove_one');
  225. $$('.QuestionHeader-side','remove_all');
  226. $$('.AppHeader-userInfo','remove_all');
  227.  
  228. var browser_width = document.body.clientWidth -50+"px";
  229. $$('.QuestionHeader-content','return_one').style.width = browser_width;
  230.  
  231. setInterval(function(){
  232. if(document.querySelector(".HitQrcode")){
  233. $$('.HitQrcode','remove_one');
  234. }
  235. },100);
  236. break;
  237.  
  238. case "www.letscorp.net":
  239. $$('#commentlist','remove_one');
  240. $$('#sidebar','remove_one');
  241. $$('#header','remove_one');
  242.  
  243. var browser_width = document.body.clientWidth -50+"px";
  244. $$('#container','return_one').style.width = browser_width;
  245. $$('#main','return_one').style.height = "auto";
  246. var p_ele = $$('p','return_all');
  247. Array.prototype.forEach.call(p_ele,function(e){
  248. e.style["font-size"] = "16px";
  249. });
  250. break;
  251.  
  252. case "segmentfault.com":
  253. $$("#loginBanner","remove_one");
  254. break;
  255. case "huziketang.mangojuice.top":
  256. for(var i=0 ;i<10000 ;i++){
  257. clearInterval(i);
  258. }
  259. $$("div","return_all").forEach(function(ele){
  260. if(ele.id && ele.id!=="wrapper" && ele.id!=="uyan_frame" && ele.id!=="donate-mask" ){
  261. ele.parentNode.removeChild(ele);
  262. }
  263. });
  264. break;
  265.  
  266. case "lvv2.com":
  267. if( $$(".link.show","return_all") ) {
  268. $$(".link.show","return_all").forEach(function(ele){
  269. if(ele.querySelector('a.title') ){
  270. // console.log(ele.querySelector('a.title').innerHTML)
  271. ele.querySelector('a.title').style.fontSize = '16px'
  272. var title = ele.querySelector('a.title').innerHTML
  273. var porn_list = ['约炮','母狗','调教','草','鸡巴','小受','口爆','野战','SM','sm','贱货','被虐','淫','内裤','屁眼','蕾丝','姿势','体位','色情','骚','屌','淫荡','射','艹','丝袜','情色','调情','做爱','操','捆绑','挑逗','绿帽','潮喷','援交','jj','JJ','潮吹','3p','3P','腰','臀','肉棒','啪啪','圣水']
  274. var politic_list = ['中共','土共','民主','法治','天安门','老兵','自由','殴打','近平','奴隶','道德','强拆','法律','监狱','城管','土匪','毛腊肉','老毛','专制','社会主义','党中央','统治','酷刑','党员','人民','民族','P2P','普京','英雄','纳税','维权','执法','警察','独裁','政府','郭文贵','文革','武装','共产','垬','毛泽东','政权','枪','举报','恐怖','宗教','卖国','死','软禁']
  275. var key_word_list = porn_list.concat( politic_list)
  276. var porn_detection = key_word_list.some(function(ele){
  277. return title.indexOf(ele) > -1
  278. })
  279. porn_detection && ele.parentNode.removeChild(ele)
  280. // ele.parentNode.removeChild(ele);
  281. }
  282. });
  283. }
  284. break;
  285.  
  286. default:
  287. var obj = main_ele_searcher();
  288. ele_remover(obj);
  289. //main_content_adjust(obj.main_ele);
  290. }
  291. window.change_style_flag && change_style();
  292. console.clear();
  293. console.timeEnd("allen_web_time_count");
  294.  
  295.  
  296. }catch(err){
  297. //console.log(err.name,' ',err.message);
  298. console.log(err.stack);
  299. }
  300.  
  301.  
  302.  
  303. //window.frames
  304. //Array.prototype.slice.call(ele)
  305.  
  306. //寻找页面的主要内容
  307. function main_ele_searcher() {
  308. var ele = document.querySelectorAll("*");
  309. var arr = [];
  310. //var arr_index = [];
  311. var w,h;
  312.  
  313. var body_width = document.body.clientWidth;
  314. var body_height = document.body.clientHeight;
  315.  
  316. if(!body_height){
  317. var max_width = 0,max_height = 0;
  318. document.documentElement.style.height = '100%';
  319. document.body.style.height = '100%';
  320.  
  321. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  322. w = ele[i].clientWidth;
  323. h = ele[i].clientHeight;
  324. if ( w > max_width) {max_width = w;}
  325. if ( h > max_height) {max_height = h;}
  326. w=null;
  327. h =null;
  328. }
  329. body_width = max_width ;
  330. body_height = max_height;
  331. }
  332.  
  333.  
  334. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  335. w = ele[i].clientWidth;
  336. h = ele[i].clientHeight;
  337. //console.log(h);
  338.  
  339. if ( w && h && w >body_width/2 && h> body_height/5 && w <body_width && h< body_height) {
  340. arr[w * h] = ele[i];
  341. //console.log(ele[i]);
  342. //arr_index.push(w * h);
  343. }
  344. w=null;
  345. h =null;
  346. }
  347. var main_ele = arr[arr.length-1] || document.body;
  348. return {
  349. main_ele,
  350. body_width,
  351. body_height
  352. };
  353. }
  354.  
  355. //去除侧边栏这样“狭长”的内容
  356. function ele_remover(obj){
  357. var w,h;
  358. var {main_ele,body_width, body_height }= obj;
  359. var ele = document.querySelectorAll("*");
  360. //console.log(main_ele,body_width, body_height )
  361. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  362. w = ele[i].clientWidth;
  363. h = ele[i].clientHeight;
  364. // main_ele.parentNode.children
  365. if (!ele[i].contains(main_ele) && !main_ele.contains(ele[i]) &&( ele[i] !==main_ele) && w *1.4 < h && w < body_width/2 && w > body_width/10 ) {
  366. //content_adjust(ele[i]);
  367. console.log("---------element removed ------------");
  368. console.log(ele[i]);
  369. console.log("---------element removed ------------");
  370.  
  371. ele[i].parentNode.removeChild(ele[i]);
  372. }
  373. w=null;
  374. h =null;
  375. }
  376. }
  377.  
  378. //去除被移除元素的兄弟元素的padding margin
  379. function content_adjust(ele){
  380. var siblings = ele.parentNode.children;
  381. ele.parentNode.style.position = "relative";
  382. // console.log(ele);
  383. for (let i = 0, ele_length = siblings.length; i < ele_length; i++) {
  384. //console.log(siblings[i]);
  385. siblings[i].setAttribute('style','position:relative;padding:20px;margin:0px;overflow:visible;');
  386. }
  387. }
  388.  
  389.  
  390. //调整主要内容的样式
  391. function main_content_adjust(main_ele){
  392. //var a = [{x,y,top,right,bottom,left,width}]=main_ele.getClientRects();
  393. //main_ele.parentNode.style.position = "relative";
  394. //main_ele.setAttribute('style','position:relative;padding:20px 20px 20px 40px;margin:auto;clear:both;overflow:visible;');
  395. var ratio =0.9 * (window.innerWidth ) /main_ele.clientWidth;
  396. var ele = main_ele.querySelectorAll('*');
  397. // console.log(ele);
  398. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  399. ele[i].style.width = ele[i].clientWidth* ratio +"px";
  400. ele[i].style.overflow = 'visible';
  401. //console.log(i);
  402. }
  403.  
  404. }
  405.  
  406. //背景调色
  407. function change_style (arr){
  408. // 执行速度 : for 循环 > forEach > 尾递归 >递归 (迭代)
  409. var all = arr || document.querySelectorAll('*');
  410. for (let i = 0, ele_length = all.length; i < ele_length; i++) {
  411. if(!all[i].style.backgroundColor){
  412. all[i].style.backgroundColor = "rgba("+parseInt(239*(1-0.1*Math.random()))+","+parseInt(239*(1-0.1*Math.random()))+","+parseInt(187*(1-0.1*Math.random()))+",0.8)" ;
  413. }
  414. }
  415. }
  416.  
  417. function do_not_change_style(){
  418. window.change_style_flag = false;
  419. }
  420.  
  421. function ele_hide(e){
  422. if(e)e.style.display = "none" ;
  423. }
  424. function ele_hide_all(all){
  425. Array.prototype.forEach.call(all,function(e){e.style.display = "none";});
  426. }
  427. function ele_remove(e){
  428. if(e) e.parentNode.removeChild(e);
  429. }
  430. function ele_remove_all(all){
  431. Array.prototype.forEach.call(all,function(e){e.parentNode.removeChild(e);});
  432. }
  433.  
  434.  
  435. function $$(selector,operation_code){
  436. // operation_code : return_one return_all remove_one remove_all hide_one hide_all
  437.  
  438. switch(operation_code){
  439. case 'return_one': //return_one
  440. return document.querySelector(selector) ;
  441. case 'return_all':// return_all
  442. return document.querySelectorAll(selector);
  443. case 'remove_one': //remove_one
  444. ele_remove(document.querySelector(selector));
  445. break;
  446. case 'remove_all': //remove_all
  447. ele_remove_all(document.querySelectorAll(selector));
  448. break;
  449. case 'hide_one': //hide_one
  450. ele_hide(document.querySelector(selector));
  451. break;
  452. case 'hide_all':// hide_all
  453. ele_hide_all(document.querySelectorAll(selector));
  454. break;
  455.  
  456. default:
  457. var result = document.querySelectorAll(selector);
  458. return result.length >1 ? result : result[0] ;
  459. }
  460. }
  461.  
  462.  
  463. function remove_div_padding_margin(ele){
  464. if( ele ){
  465. ele.setAttribute('style','overflow:visible;position:relative;padding:0px;margin:0px;left:0px;');
  466. }
  467. if(ele && ele.children.length > 0){
  468. Array.prototype.forEach.call(ele.children,(function(e){
  469. remove_div_padding_margin(e);
  470. }));
  471. }
  472. }
  473.  
  474. function content_get() {
  475. var ajax = new XMLHttpRequest();
  476. ajax.open('get', '/');
  477. ajax.send();
  478. ajax.onreadystatechange = function() {
  479. if (ajax.readyState == 4 && ajax.status == 200) {
  480. content_new = ajax.responseText;
  481. //console.log(content_new);
  482. content_old = content_old || content_new;
  483. if(content_new !== content_old){
  484. location.reload() ;
  485. }
  486. }
  487. };
  488.  
  489. setTimeout(content_get,1000);
  490. }
  491.  
  492.  
  493.  
  494.  
  495.  
  496. /* jshint ignore:start */
  497. //]]></>).toString();
  498. //var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });
  499. //eval(c.code);
  500. /* jshint ignore:end */