Programer's Web Friend

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

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

  1. // ==UserScript==
  2. // @name Programer's Web Friend
  3. // @namespace https://tampermonkey.net/
  4. // @version 1.8.3
  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.  
  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. var DEBUG = true;
  63.  
  64.  
  65. try{
  66.  
  67. console.time("allen_web_time_count");
  68.  
  69.  
  70.  
  71. switch(links){
  72.  
  73. case "ip":
  74. //content_get();
  75. break;
  76.  
  77. case "wc-kx-vip.sjc.kixeye.com":
  78. $$('#above-game-message','remove_one');
  79. $$('#kxp-footer-bar','remove_one');
  80. $$('#topnavbar_back','remove_one');
  81. break;
  82.  
  83. case "www.baidu.com":
  84.  
  85. var head = document.getElementById("head");
  86. var pad = document.getElementById("s_tab");
  87. var u = document.getElementById("u");
  88. var setInterval_id;
  89.  
  90. document.getElementById("container").style.width = "700px";
  91. head.style.position = 'relative';
  92. head.style.width = window.innerWidth-100+'px';
  93. head.style['min-width'] = 0;
  94. pad.style.padding = '0 0 0 121px';
  95. u.style.display = 'none';
  96. document.body.style['min-width'] = '10px';
  97.  
  98.  
  99. setInterval_id = setInterval(function(){
  100. if(document.querySelector("#content_right") ){
  101. $$("#content_right",'remove_all');
  102. //clearInterval(setInterval_id);
  103. }
  104. },100);
  105.  
  106.  
  107. change_style();
  108. break;
  109.  
  110. case "www.cnblogs.com":
  111. if(typeof sidebar !== "undefined")window.sidebar.style.display = "none";
  112. if(typeof content !== "undefined")window.content.style["margin-right"] = "10";
  113. if(typeof content !== "undefined")window.content.style.width = window.innerWidth-100+'px';
  114. change_style();
  115. break;
  116. case "blog.csdn.net":
  117.  
  118. if($$("#side",'return_one'))$$("#side",'hide_one');
  119. var CSDN_style_obj = {
  120. 'max-width':document.body.clientWidth-16+'px',
  121. 'min-width':'2px'
  122. };
  123.  
  124. change_style();
  125. break;
  126.  
  127. case "www.w3school.com.cn":
  128. $$("#navsecond",'hide_one');
  129. change_style();
  130. break;
  131.  
  132. case "www.jquery123.com":
  133. $$("#sidebar",'hide_one');
  134. //var a = $$("#content",'hide_one');
  135. $$(".content-right #content","return_one").style.cssText = "float:left;width:100%;";
  136. if(a) a.style.width = "100%";
  137. change_style();
  138. break;
  139.  
  140. case "wallstreetcn.com":
  141.  
  142. setInterval(function(){
  143. $$('.news-item__cover','remove_all');
  144. change_style();
  145. },500);
  146.  
  147. if($$('.left-bar','return_one'))$$('.left-bar','remove_one');
  148. //$$('.news-right','remove_one');
  149.  
  150. break;
  151.  
  152. case "zhidao.baidu.com":
  153. var a =document.getElementById("body");
  154. if(a) a.style.left = "50px";
  155. change_style();
  156. break;
  157.  
  158. case "www.merriam-webster.com":
  159. $$(".right-rail",'hide_one');
  160. $$("#recirc-bar-footer",'hide_one');
  161. if(a) a.elem.style.width = "100%";
  162. $$(".wgt-related-to.jc-card-box.clearfix",'hide_one');
  163. change_style();
  164. break;
  165.  
  166. case "blog.sina.com.cn":
  167. $$("#column_1",'hide_one');
  168. change_style();
  169. break;
  170.  
  171. case "blog.jobbole.com":
  172. case "web.jobbole.com":
  173. $$("#sidebar",'hide_one');
  174. var a = $$(".grid-8",'return_one');
  175. if (a) a.style.width = "100%";
  176.  
  177. change_style();
  178. break;
  179.  
  180. case "juejin.im":
  181. var interval_id = setInterval(function(){
  182. var a = document.getElementsByClassName("show-full")[0];
  183. var b = document.getElementsByClassName("show-full-block")[0];
  184. var c = document.getElementsByClassName(" show-full-btn")[0];
  185.  
  186. $$('.columen-view-aside','hide_one');
  187.  
  188. if(a)a.style.height = "auto";
  189. if(b){
  190. clearInterval(interval_id);
  191. b.style.height = "auto";
  192. }
  193. if(c)c.style.display = "none";
  194.  
  195. },100);
  196.  
  197. change_style();
  198. break;
  199.  
  200. case "www.cnblogs.com":
  201. change_style();
  202. $$("#sideBar",'hide_one');
  203. $$("#vid",'hide_one');
  204. $$("#left",'hide_one');
  205. $$("#right_content",'hide_one');
  206. $$("#leftcontent",'hide_one');
  207. var a = $$("#centercontent",'return_one');
  208. if(a){a.style['padding-left'] = 0;}
  209. break;
  210.  
  211. case "github.com":
  212. document.body.style.minWidth = '100px';
  213. var github_pad = document.querySelector('.column.three-fourths.codesearch-results.pr-6') ;
  214. if(github_pad ){
  215. github_pad.style.padding = '10px 0 10px 30px';
  216. }
  217. //change_style(,{'max-width':document.body.clientWidth+'px'});
  218. change_style();
  219. break;
  220.  
  221. case "wiki.jikexueyuan.com":
  222. $$(".detail-left",'hide_one');
  223. var a = $$(".detail-main",'no_option','one');
  224. a.style['margin-left'] = '0px';
  225. a.style.width = document.body.clientWidth+'px';
  226. change_style();
  227. break;
  228.  
  229. case "www.cssmoban.com":
  230. var a = $$(".wide-main.col-media-main.clearfix",'return_one');
  231. a.style.width = document.body.clientWidth+'px';
  232. change_style();
  233. break;
  234.  
  235. case "www.kancloud.cn":
  236. var interval_id = setInterval(function(){
  237. if(document.querySelector(".sidebar")){
  238. var a = document.querySelector(".sidebar");
  239. document.querySelector(".workspace").style.left = "180px";
  240. a.style.width = '180px';
  241. change_style(a);
  242. clearInterval(interval_id);
  243. }
  244. },100);
  245.  
  246. change_style();
  247. break;
  248.  
  249. case "php.net":
  250. $$('.layout-menu','remove_one');
  251. if($$(".sect1",'return_one'))$$(".sect1",'return_one').style.width = document.body.clientWidth-50+"px";
  252. if($$("#usernotes",'return_one'))$$("#usernotes",'return_one').style.width = document.body.clientWidth-50+"px";
  253.  
  254. change_style();
  255. break;
  256.  
  257. case "www.zhihu.com":
  258. $$('.Question-sideColumn.Question-sideColumn--sticky','remove_one');
  259. $$('.AdblockBanner-inner','remove_one');
  260. $$('.QuestionHeader-side','remove_all');
  261. $$('.AppHeader-userInfo','remove_all');
  262.  
  263. var browser_width = document.body.clientWidth -50+"px";
  264. $$('.QuestionHeader-content','return_one').style.width = browser_width;
  265.  
  266. setInterval(function(){
  267. if(document.querySelector(".HitQrcode")){
  268. $$('.HitQrcode','remove_one');
  269. }
  270. },100);
  271. change_style();
  272. break;
  273.  
  274. case "www.letscorp.net":
  275. $$('#commentlist','remove_one');
  276. $$('#sidebar','remove_one');
  277. $$('#header','remove_one');
  278.  
  279. var browser_width = document.body.clientWidth -50+"px";
  280. $$('#container','return_one').style.width = browser_width;
  281. $$('#main','return_one').style.height = "auto";
  282. var p_ele = $$('p','return_all');
  283. Array.prototype.forEach.call(p_ele,function(e){
  284. e.style["font-size"] = "16px";
  285. });
  286.  
  287.  
  288. change_style();
  289. break;
  290.  
  291. case "segmentfault.com":
  292. $$("#loginBanner","remove_one");
  293. change_style();
  294. break;
  295. case "huziketang.mangojuice.top":
  296. for(var i=0 ;i<10000 ;i++){
  297. clearInterval(i);
  298. }
  299. $$("div","return_all").forEach(function(ele){
  300. if(ele.id && ele.id!=="wrapper" && ele.id!=="uyan_frame" && ele.id!=="donate-mask" ){
  301. ele.parentNode.removeChild(ele);
  302. }
  303. });
  304.  
  305. change_style();
  306. break;
  307. case "www.liepin.com":
  308. case "c.liepin.com":
  309.  
  310. if($$(".btn-apply","return_one")){
  311. $$(".btn-apply","return_one").click();
  312. }
  313.  
  314. setInterval(function(){
  315. //dlg-actions
  316. if($$(".dlg-actions","return_one")){
  317. $$(".dlg-actions input","return_one").click();
  318. setTimeout(function(){
  319. window.opener=null;
  320. window.open('','_self');
  321. window.close();
  322. },3000);
  323.  
  324. if(document.querySelectorAll(".job-info")){
  325. var info_array = document.querySelectorAll(".job-info");
  326. var info_length = info_array.length;
  327. for(var i = 0;i<info_length;i++){
  328. if(info_array[i].querySelector("p a").innerHTML.match(/深圳-福田/)){
  329. info_array[i].querySelector("a").click();
  330. }
  331. }
  332. }
  333.  
  334. }
  335. },300);
  336.  
  337. if(document.querySelectorAll(".job-info")){
  338. var info_array = document.querySelectorAll(".job-info");
  339. var info_length = info_array.length;
  340. for(var i = 0;i<info_length;i++){
  341. if(info_array[i].querySelector("p a").innerHTML.match(/深圳-福田/)){
  342. info_array[i].querySelector("a").click();
  343. }
  344. }
  345. }
  346. //change_style();
  347. break;
  348.  
  349. default:
  350. var obj = main_ele_searcher();
  351. ele_remover(obj);
  352. //main_content_adjust(obj.main_ele);
  353. change_style();
  354. }
  355.  
  356. console.timeEnd("allen_web_time_count");
  357.  
  358. }catch(err){
  359. //console.log(err.name,' ',err.message);
  360. console.log(err.stack);
  361. }
  362.  
  363.  
  364.  
  365. //window.frames
  366. //Array.prototype.slice.call(ele)
  367.  
  368. //寻找页面的主要内容
  369. function main_ele_searcher() {
  370. var ele = document.querySelectorAll("*");
  371. var arr = [];
  372. //var arr_index = [];
  373. var w,h;
  374.  
  375. var body_width = document.body.clientWidth;
  376. var body_height = document.body.clientHeight;
  377.  
  378. if(!body_height){
  379. var max_width = 0,max_height = 0;
  380. document.documentElement.style.height = '100%';
  381. document.body.style.height = '100%';
  382.  
  383. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  384. w = ele[i].clientWidth;
  385. h = ele[i].clientHeight;
  386. if ( w > max_width) {max_width = w;}
  387. if ( h > max_height) {max_height = h;}
  388. w=null;
  389. h =null;
  390. }
  391. body_width = max_width ;
  392. body_height = max_height;
  393. }
  394.  
  395.  
  396. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  397. w = ele[i].clientWidth;
  398. h = ele[i].clientHeight;
  399. //console.log(h);
  400.  
  401. if ( w && h && w >body_width/2 && h> body_height/5 && w <body_width && h< body_height) {
  402. arr[w * h] = ele[i];
  403. //console.log(ele[i]);
  404. //arr_index.push(w * h);
  405. }
  406. w=null;
  407. h =null;
  408. }
  409. var main_ele = arr[arr.length-1] || document.body;
  410. return {
  411. main_ele,
  412. body_width,
  413. body_height
  414. };
  415. }
  416.  
  417. //去除侧边栏这样“狭长”的内容
  418. function ele_remover(obj){
  419. var w,h;
  420. var {main_ele,body_width, body_height }= obj;
  421. var ele = document.querySelectorAll("*");
  422. //console.log(main_ele,body_width, body_height )
  423. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  424. w = ele[i].clientWidth;
  425. h = ele[i].clientHeight;
  426. // main_ele.parentNode.children
  427. 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 ) {
  428. //content_adjust(ele[i]);
  429. console.log("---------element removed ------------");
  430. console.log(ele[i]);
  431. console.log("---------element removed ------------");
  432.  
  433. ele[i].parentNode.removeChild(ele[i]);
  434. }
  435. w=null;
  436. h =null;
  437. }
  438. }
  439.  
  440. //去除被移除元素的兄弟元素的padding margin
  441. function content_adjust(ele){
  442. var siblings = ele.parentNode.children;
  443. ele.parentNode.style.position = "relative";
  444. // console.log(ele);
  445. for (let i = 0, ele_length = siblings.length; i < ele_length; i++) {
  446. //console.log(siblings[i]);
  447. siblings[i].setAttribute('style','position:relative;padding:20px;margin:0px;overflow:visible;');
  448. }
  449. }
  450.  
  451.  
  452. //调整主要内容的样式
  453. function main_content_adjust(main_ele){
  454. //var a = [{x,y,top,right,bottom,left,width}]=main_ele.getClientRects();
  455. //main_ele.parentNode.style.position = "relative";
  456. //main_ele.setAttribute('style','position:relative;padding:20px 20px 20px 40px;margin:auto;clear:both;overflow:visible;');
  457. var ratio =0.9 * (window.innerWidth ) /main_ele.clientWidth;
  458. var ele = main_ele.querySelectorAll('*');
  459. // console.log(ele);
  460. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  461. ele[i].style.width = ele[i].clientWidth* ratio +"px";
  462. ele[i].style.overflow = 'visible';
  463. //console.log(i);
  464. }
  465.  
  466. }
  467.  
  468. //背景调色
  469. function change_style (arr){
  470. // 执行速度 : for 循环 > forEach > 尾递归 >递归 (迭代)
  471. var all = arr || document.querySelectorAll('*');
  472. for (let i = 0, ele_length = all.length; i < ele_length; i++) {
  473. if(!all[i].style.backgroundColor){
  474. 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)" ;
  475. }
  476. }
  477.  
  478.  
  479. DEBUG || console.clear();
  480. }
  481.  
  482.  
  483. function ele_hide(e){
  484. if(e)e.style.display = "none" ;
  485. }
  486. function ele_hide_all(all){
  487. Array.prototype.forEach.call(all,function(e){e.style.display = "none";});
  488. }
  489. function ele_remove(e){
  490. if(e) e.parentNode.removeChild(e);
  491. }
  492. function ele_remove_all(all){
  493. Array.prototype.forEach.call(all,function(e){e.parentNode.removeChild(e);});
  494. }
  495.  
  496.  
  497. function $$(selector,operation_code){
  498. // operation_code : return_one return_all remove_one remove_all hide_one hide_all
  499.  
  500. switch(operation_code){
  501. case 'return_one': //return_one
  502. return document.querySelector(selector) ;
  503. case 'return_all':// return_all
  504. return document.querySelectorAll(selector);
  505. case 'remove_one': //remove_one
  506. ele_remove(document.querySelector(selector));
  507. break;
  508. case 'remove_all': //remove_all
  509. ele_remove_all(document.querySelectorAll(selector));
  510. break;
  511. case 'hide_one': //hide_one
  512. ele_hide(document.querySelector(selector));
  513. break;
  514. case 'hide_all':// hide_all
  515. ele_hide_all(document.querySelectorAll(selector));
  516. break;
  517.  
  518. default:
  519. var result = document.querySelectorAll(selector);
  520. return result.length >1 ? result : result[0] ;
  521. }
  522. }
  523.  
  524.  
  525. function remove_div_padding_margin(ele){
  526. if( ele ){
  527. ele.setAttribute('style','overflow:visible;position:relative;padding:0px;margin:0px;left:0px;');
  528. }
  529. if(ele && ele.children.length > 0){
  530. Array.prototype.forEach.call(ele.children,(function(e){
  531. remove_div_padding_margin(e);
  532. }));
  533. }
  534. }
  535.  
  536. function content_get() {
  537. var ajax = new XMLHttpRequest();
  538. ajax.open('get', '/');
  539. ajax.send();
  540. ajax.onreadystatechange = function() {
  541. if (ajax.readyState == 4 && ajax.status == 200) {
  542. content_new = ajax.responseText;
  543. //console.log(content_new);
  544. content_old = content_old || content_new;
  545. if(content_new !== content_old){
  546. location.reload() ;
  547. }
  548. }
  549. };
  550.  
  551. setTimeout(content_get,1000);
  552. }
  553.  
  554.  
  555.  
  556.  
  557.  
  558. /* jshint ignore:start */
  559. //]]></>).toString();
  560. //var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });
  561. //eval(c.code);
  562. /* jshint ignore:end */