Greasy Fork is available in English.

Programer's Web Friend

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

Per 19-09-2018. Zie de nieuwste versie.

  1. // ==UserScript==
  2. // @name Programer's Web Friend
  3. // @namespace https://tampermonkey.net/
  4. // @version 1.9.10
  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. 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. setTimeout(function(){
  95. try{
  96. if (pad && pad instanceof Object && pad.style && pad.style.padding) {
  97. // pad.style.padding = '0 0 0 121px';
  98. }
  99. }catch(e){
  100. console.log(e.message)
  101. }
  102. },1000
  103. );
  104. u.style.display = 'none';
  105. document.body.style['min-width'] = '10px';
  106.  
  107.  
  108. setInterval_id = setInterval(function(){
  109. if(document.querySelector("#content_right") ){
  110. $$("#content_right",'remove_all');
  111. //clearInterval(setInterval_id);
  112. }
  113. },100);
  114.  
  115.  
  116. change_style();
  117. break;
  118.  
  119. case "www.cnblogs.com":
  120. if(typeof sidebar !== "undefined")window.sidebar.style.display = "none";
  121. if(typeof content !== "undefined")window.content.style["margin-right"] = "10";
  122. if(typeof content !== "undefined")window.content.style.width = window.innerWidth-100+'px';
  123. change_style();
  124. break;
  125. case "blog.csdn.net":
  126.  
  127. if($$("#side",'return_one'))$$("#side",'hide_one');
  128. var CSDN_style_obj = {
  129. 'max-width':document.body.clientWidth-16+'px',
  130. 'min-width':'2px'
  131. };
  132.  
  133. change_style();
  134. break;
  135.  
  136. case "www.w3school.com.cn":
  137. $$("#navsecond",'hide_one');
  138. change_style();
  139. break;
  140.  
  141. case "www.jquery123.com":
  142. $$("#sidebar",'hide_one');
  143. //var a = $$("#content",'hide_one');
  144. $$(".content-right #content","return_one").style.cssText = "float:left;width:100%;";
  145. if(a) a.style.width = "100%";
  146. change_style();
  147. break;
  148.  
  149. case "wallstreetcn.com":
  150.  
  151. setInterval(function(){
  152. $$('.news-item__cover','remove_all');
  153. change_style();
  154. },500);
  155.  
  156. if($$('.left-bar','return_one'))$$('.left-bar','remove_one');
  157. //$$('.news-right','remove_one');
  158.  
  159. break;
  160.  
  161. case "zhidao.baidu.com":
  162. var a =document.getElementById("body");
  163. if(a) a.style.left = "50px";
  164. change_style();
  165. break;
  166.  
  167. case "www.merriam-webster.com":
  168. $$(".right-rail",'hide_one');
  169. $$("#recirc-bar-footer",'hide_one');
  170. if(a) a.elem.style.width = "100%";
  171. $$(".wgt-related-to.jc-card-box.clearfix",'hide_one');
  172. change_style();
  173. break;
  174.  
  175. case "blog.sina.com.cn":
  176. $$("#column_1",'hide_one');
  177. change_style();
  178. break;
  179.  
  180. case "blog.jobbole.com":
  181. case "web.jobbole.com":
  182. $$("#sidebar",'hide_one');
  183. var a = $$(".grid-8",'return_one');
  184. if (a) a.style.width = "100%";
  185.  
  186. change_style();
  187. break;
  188.  
  189. case "juejin.im":
  190. var interval_id = setInterval(function(){
  191. var a = document.getElementsByClassName("show-full")[0];
  192. var b = document.getElementsByClassName("show-full-block")[0];
  193. var c = document.getElementsByClassName(" show-full-btn")[0];
  194.  
  195. $$('.columen-view-aside','hide_one');
  196.  
  197. if(a)a.style.height = "auto";
  198. if(b){
  199. clearInterval(interval_id);
  200. b.style.height = "auto";
  201. }
  202. if(c)c.style.display = "none";
  203.  
  204. },100);
  205.  
  206. change_style();
  207. break;
  208.  
  209. case "www.cnblogs.com":
  210. change_style();
  211. $$("#sideBar",'hide_one');
  212. $$("#vid",'hide_one');
  213. $$("#left",'hide_one');
  214. $$("#right_content",'hide_one');
  215. $$("#leftcontent",'hide_one');
  216. var a = $$("#centercontent",'return_one');
  217. if(a){a.style['padding-left'] = 0;}
  218. break;
  219.  
  220. case "github.com":
  221. document.body.style.minWidth = '100px';
  222. var github_pad = document.querySelector('.column.three-fourths.codesearch-results.pr-6') ;
  223. if(github_pad ){
  224. github_pad.style.padding = '10px 0 10px 30px';
  225. }
  226. //change_style(,{'max-width':document.body.clientWidth+'px'});
  227. change_style();
  228. break;
  229.  
  230. case "wiki.jikexueyuan.com":
  231. $$(".detail-left",'hide_one');
  232. var a = $$(".detail-main",'no_option','one');
  233. a.style['margin-left'] = '0px';
  234. a.style.width = document.body.clientWidth+'px';
  235. change_style();
  236. break;
  237.  
  238. case "www.cssmoban.com":
  239. var a = $$(".wide-main.col-media-main.clearfix",'return_one');
  240. a.style.width = document.body.clientWidth+'px';
  241. change_style();
  242. break;
  243.  
  244. case "www.kancloud.cn":
  245. var interval_id = setInterval(function(){
  246. if(document.querySelector(".sidebar")){
  247. var a = document.querySelector(".sidebar");
  248. document.querySelector(".workspace").style.left = "180px";
  249. a.style.width = '180px';
  250. change_style(a);
  251. clearInterval(interval_id);
  252. }
  253. },100);
  254.  
  255. change_style();
  256. break;
  257.  
  258. case "php.net":
  259. $$('.layout-menu','remove_one');
  260. if($$(".sect1",'return_one'))$$(".sect1",'return_one').style.width = document.body.clientWidth-50+"px";
  261. if($$("#usernotes",'return_one'))$$("#usernotes",'return_one').style.width = document.body.clientWidth-50+"px";
  262.  
  263. change_style();
  264. break;
  265.  
  266. case "www.zhihu.com":
  267. $$('.Question-sideColumn.Question-sideColumn--sticky','remove_one');
  268. $$('.AdblockBanner-inner','remove_one');
  269. $$('.QuestionHeader-side','remove_all');
  270. $$('.AppHeader-userInfo','remove_all');
  271.  
  272. var browser_width = document.body.clientWidth -50+"px";
  273. $$('.QuestionHeader-content','return_one').style.width = browser_width;
  274.  
  275. setInterval(function(){
  276. if(document.querySelector(".HitQrcode")){
  277. $$('.HitQrcode','remove_one');
  278. }
  279. },100);
  280. change_style();
  281. break;
  282.  
  283. case "www.letscorp.net":
  284. $$('#commentlist','remove_one');
  285. $$('#sidebar','remove_one');
  286. $$('#header','remove_one');
  287.  
  288. var browser_width = document.body.clientWidth -50+"px";
  289. $$('#container','return_one').style.width = browser_width;
  290. $$('#main','return_one').style.height = "auto";
  291. var p_ele = $$('p','return_all');
  292. Array.prototype.forEach.call(p_ele,function(e){
  293. e.style["font-size"] = "16px";
  294. });
  295.  
  296.  
  297. change_style();
  298. break;
  299.  
  300. case "segmentfault.com":
  301. $$("#loginBanner","remove_one");
  302. change_style();
  303. break;
  304. case "huziketang.mangojuice.top":
  305. for(var i=0 ;i<10000 ;i++){
  306. clearInterval(i);
  307. }
  308. $$("div","return_all").forEach(function(ele){
  309. if(ele.id && ele.id!=="wrapper" && ele.id!=="uyan_frame" && ele.id!=="donate-mask" ){
  310. ele.parentNode.removeChild(ele);
  311. }
  312. });
  313.  
  314. change_style();
  315. break;
  316.  
  317. case "lvv2.com":
  318. if( $$(".link.show","return_all") ) {
  319. $$(".link.show","return_all").forEach(function(ele){
  320. if(ele.querySelector('a.title') ){
  321. // console.log(ele.querySelector('a.title').innerHTML)
  322. ele.querySelector('a.title').style.fontSize = '16px'
  323. var title = ele.querySelector('a.title').innerHTML
  324. var porn_list = ['约炮','母狗','调教','草','鸡巴','小受','口爆','野战','SM','sm','贱货','被虐','淫','内裤','屁眼','蕾丝','姿势','体位','色情','骚','屌','淫荡','射','艹','丝袜','情色','调情','做爱','操','捆绑','挑逗','绿帽','潮喷','援交','jj','JJ','潮吹','3p','3P','腰','臀','肉棒','啪啪','圣水']
  325. var politic_list = ['中共','土共','民主','法治','天安门','老兵','自由','殴打','近平','奴隶','道德','强拆','法律','监狱','城管','土匪','毛腊肉','老毛','专制','社会主义','党中央','统治','酷刑','党员','人民','民族','P2P','普京','英雄','纳税','维权','执法','警察','独裁','政府','郭文贵','文革','武装','共产','垬','毛泽东','政权','枪','举报','恐怖','宗教','卖国','死','软禁']
  326. var key_word_list = porn_list.concat( politic_list)
  327. var porn_detection = key_word_list.some(function(ele){
  328. return title.indexOf(ele) > -1
  329. })
  330. porn_detection && ele.parentNode.removeChild(ele)
  331. // ele.parentNode.removeChild(ele);
  332. }
  333. });
  334. }
  335.  
  336.  
  337. change_style();
  338. break;
  339.  
  340. default:
  341. var obj = main_ele_searcher();
  342. ele_remover(obj);
  343. //main_content_adjust(obj.main_ele);
  344. change_style();
  345. }
  346.  
  347. console.timeEnd("allen_web_time_count");
  348.  
  349. }catch(err){
  350. //console.log(err.name,' ',err.message);
  351. console.log(err.stack);
  352. }
  353.  
  354.  
  355.  
  356. //window.frames
  357. //Array.prototype.slice.call(ele)
  358.  
  359. //寻找页面的主要内容
  360. function main_ele_searcher() {
  361. var ele = document.querySelectorAll("*");
  362. var arr = [];
  363. //var arr_index = [];
  364. var w,h;
  365.  
  366. var body_width = document.body.clientWidth;
  367. var body_height = document.body.clientHeight;
  368.  
  369. if(!body_height){
  370. var max_width = 0,max_height = 0;
  371. document.documentElement.style.height = '100%';
  372. document.body.style.height = '100%';
  373.  
  374. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  375. w = ele[i].clientWidth;
  376. h = ele[i].clientHeight;
  377. if ( w > max_width) {max_width = w;}
  378. if ( h > max_height) {max_height = h;}
  379. w=null;
  380. h =null;
  381. }
  382. body_width = max_width ;
  383. body_height = max_height;
  384. }
  385.  
  386.  
  387. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  388. w = ele[i].clientWidth;
  389. h = ele[i].clientHeight;
  390. //console.log(h);
  391.  
  392. if ( w && h && w >body_width/2 && h> body_height/5 && w <body_width && h< body_height) {
  393. arr[w * h] = ele[i];
  394. //console.log(ele[i]);
  395. //arr_index.push(w * h);
  396. }
  397. w=null;
  398. h =null;
  399. }
  400. var main_ele = arr[arr.length-1] || document.body;
  401. return {
  402. main_ele,
  403. body_width,
  404. body_height
  405. };
  406. }
  407.  
  408. //去除侧边栏这样“狭长”的内容
  409. function ele_remover(obj){
  410. var w,h;
  411. var {main_ele,body_width, body_height }= obj;
  412. var ele = document.querySelectorAll("*");
  413. //console.log(main_ele,body_width, body_height )
  414. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  415. w = ele[i].clientWidth;
  416. h = ele[i].clientHeight;
  417. // main_ele.parentNode.children
  418. 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 ) {
  419. //content_adjust(ele[i]);
  420. console.log("---------element removed ------------");
  421. console.log(ele[i]);
  422. console.log("---------element removed ------------");
  423.  
  424. ele[i].parentNode.removeChild(ele[i]);
  425. }
  426. w=null;
  427. h =null;
  428. }
  429. }
  430.  
  431. //去除被移除元素的兄弟元素的padding margin
  432. function content_adjust(ele){
  433. var siblings = ele.parentNode.children;
  434. ele.parentNode.style.position = "relative";
  435. // console.log(ele);
  436. for (let i = 0, ele_length = siblings.length; i < ele_length; i++) {
  437. //console.log(siblings[i]);
  438. siblings[i].setAttribute('style','position:relative;padding:20px;margin:0px;overflow:visible;');
  439. }
  440. }
  441.  
  442.  
  443. //调整主要内容的样式
  444. function main_content_adjust(main_ele){
  445. //var a = [{x,y,top,right,bottom,left,width}]=main_ele.getClientRects();
  446. //main_ele.parentNode.style.position = "relative";
  447. //main_ele.setAttribute('style','position:relative;padding:20px 20px 20px 40px;margin:auto;clear:both;overflow:visible;');
  448. var ratio =0.9 * (window.innerWidth ) /main_ele.clientWidth;
  449. var ele = main_ele.querySelectorAll('*');
  450. // console.log(ele);
  451. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  452. ele[i].style.width = ele[i].clientWidth* ratio +"px";
  453. ele[i].style.overflow = 'visible';
  454. //console.log(i);
  455. }
  456.  
  457. }
  458.  
  459. //背景调色
  460. function change_style (arr){
  461. // 执行速度 : for 循环 > forEach > 尾递归 >递归 (迭代)
  462. var all = arr || document.querySelectorAll('*');
  463. for (let i = 0, ele_length = all.length; i < ele_length; i++) {
  464. if(!all[i].style.backgroundColor){
  465. 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)" ;
  466. }
  467. }
  468.  
  469.  
  470. DEBUG || console.clear();
  471. }
  472.  
  473.  
  474. function ele_hide(e){
  475. if(e)e.style.display = "none" ;
  476. }
  477. function ele_hide_all(all){
  478. Array.prototype.forEach.call(all,function(e){e.style.display = "none";});
  479. }
  480. function ele_remove(e){
  481. if(e) e.parentNode.removeChild(e);
  482. }
  483. function ele_remove_all(all){
  484. Array.prototype.forEach.call(all,function(e){e.parentNode.removeChild(e);});
  485. }
  486.  
  487.  
  488. function $$(selector,operation_code){
  489. // operation_code : return_one return_all remove_one remove_all hide_one hide_all
  490.  
  491. switch(operation_code){
  492. case 'return_one': //return_one
  493. return document.querySelector(selector) ;
  494. case 'return_all':// return_all
  495. return document.querySelectorAll(selector);
  496. case 'remove_one': //remove_one
  497. ele_remove(document.querySelector(selector));
  498. break;
  499. case 'remove_all': //remove_all
  500. ele_remove_all(document.querySelectorAll(selector));
  501. break;
  502. case 'hide_one': //hide_one
  503. ele_hide(document.querySelector(selector));
  504. break;
  505. case 'hide_all':// hide_all
  506. ele_hide_all(document.querySelectorAll(selector));
  507. break;
  508.  
  509. default:
  510. var result = document.querySelectorAll(selector);
  511. return result.length >1 ? result : result[0] ;
  512. }
  513. }
  514.  
  515.  
  516. function remove_div_padding_margin(ele){
  517. if( ele ){
  518. ele.setAttribute('style','overflow:visible;position:relative;padding:0px;margin:0px;left:0px;');
  519. }
  520. if(ele && ele.children.length > 0){
  521. Array.prototype.forEach.call(ele.children,(function(e){
  522. remove_div_padding_margin(e);
  523. }));
  524. }
  525. }
  526.  
  527. function content_get() {
  528. var ajax = new XMLHttpRequest();
  529. ajax.open('get', '/');
  530. ajax.send();
  531. ajax.onreadystatechange = function() {
  532. if (ajax.readyState == 4 && ajax.status == 200) {
  533. content_new = ajax.responseText;
  534. //console.log(content_new);
  535. content_old = content_old || content_new;
  536. if(content_new !== content_old){
  537. location.reload() ;
  538. }
  539. }
  540. };
  541.  
  542. setTimeout(content_get,1000);
  543. }
  544.  
  545.  
  546.  
  547.  
  548.  
  549. /* jshint ignore:start */
  550. //]]></>).toString();
  551. //var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });
  552. //eval(c.code);
  553. /* jshint ignore:end */