- // ==UserScript==
- // @name Programer's Web Friend
- // @namespace https://tampermonkey.net/
- // @version 1.9.13
- // @description change Programer's Web style to mobile device friendly ,and more readble
- // @author @Amormaid
- // @run-at document-end
- // /*@require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js */
- // /*@require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js */
- // @match http://*/*
-
- // @include http://*
- // @include https://*
-
- // @exclude http://localhost*
- // @exclude https://www.youtube.com/*
- // @exclude http://demo.mycodes.net/*
- // @exclude https://kiwivm.64clouds.com/*
- // @exclude https://www.instagram.com/*
- // @exclude http://www.h-ui.net/*
- // @exclude http://www.layui.com*
- // @exclude https://www.kixeye.com*
- // @exclude https://pan.baidu.com*
- // @exclude https://www.rishiqing.com*
- // @exclude https://wx.qq.com*
- // @exclude https://mail.126.com*
- // @exclude https://twitter.com*
- // @exclude https://reactjs.org*
- // @exclude https://codepen.io*
- // @exclude http://mail.wellav.com*
- // @exclude http://webserver.com/*
- // @exclude http://cr.sencore.com/*
- // @exclude https://free.modao.cc/*
-
-
- // @license MIT License
- // @grant none
- // ==/UserScript==
-
- /* jshint ignore:start */
- //var inline_src = (<><![CDATA[
- /* jshint ignore:end */
- /* jshint esnext: false */
- /* jshint esversion: 6 */
-
-
- /*
- if(typeof(jQuery) === 'undefined'){
- var jquery_script = document.createElement('script');
- jquery_script.src = 'https://code.jquery.com/jquery-3.2.1.min.js';
- document.body.append(jquery_script);
- }
- */
-
-
-
- var root= document.body;
- var links = /\d+\.\d+\.\d+\.\d+/.test(window.location.hostname) ? "ip" : window.location.hostname;
- var remove_div,elem,elem_2, arr,ad_ele,remove_ele;
- var content_old,content_new;
-
- window.change_style_flag = true;
-
-
- try{
-
- console.time("allen_web_time_count");
-
- switch(links){
-
- case "ip":
- //content_get();
- break;
-
- case "wc-kx-vip.sjc.kixeye.com":
- $$('#above-game-message','remove_one');
- $$('#kxp-footer-bar','remove_one');
- $$('#topnavbar_back','remove_one');
- break;
-
- case "www.baidu.com":
- case "zhidao.baidu.com":
- var zhidao_body = $$("#body","return_one");
- var container = $$("#container","return_one");
- var head = $$("#head","return_one");
- var pad = $$("#s_tab","return_one");
- var u = $$("#u","return_one");
- var setInterval_id;
-
- zhidao_body && (function(){zhidao_body.style.left = "50px"})();
- container && (function(){container.style.width = "700px"})();
- head && (function(){
- head.style.position = 'relative';
- head.style.width = window.innerWidth-100+'px';
- head.style['min-width'] = 0;
- })();
- pad && (function(){pad.style.padding = '0 0 0 121px'})();
- u && (function(){u.style.display = 'none'})();
-
- document.body.style['min-width'] = '10px';
-
- setInterval_id = setInterval(function(){
- if($$("#content_right",'return_all') ){
- $$("#content_right",'remove_all');
- var count = window.clear_count || 0;
- count++;
- window.clear_count = count;
- count > 99 && clearInterval(setInterval_id);
- }
- },100);
- break;
-
- case "www.cnblogs.com":
- case "blog.csdn.net":
- var content = $$("#content","return_one");
-
- $$("#sidebar","remove_one");
- $$("#side",'remove_one');
-
- content && (function(){
- content.style["margin-right"] = "10";
- content.style.width = window.innerWidth-100+'px';
- })();
-
- break;
-
- case "www.w3school.com.cn":
- $$("#navsecond",'hide_one');
-
- break;
-
- case "wallstreetcn.com":
-
- setInterval(function(){
- $$('.news-item__cover','remove_all');
- change_style();
- },500);
-
- $$('.left-bar','remove_one');
- break;
-
- case "www.merriam-webster.com":
- $$(".right-rail",'hide_one');
- $$("#recirc-bar-footer",'hide_one');
- $$(".wgt-related-to.jc-card-box.clearfix",'hide_one');
- break;
-
- case "blog.sina.com.cn":
- $$("#column_1",'hide_one');
- break;
-
- case "blog.jobbole.com":
- case "web.jobbole.com":
- $$("#sidebar",'hide_one');
- var grid = $$(".grid-8",'return_one');
- grid && (function(){grid.style.width = "100%"})();
- break;
-
- case "juejin.im":
- var interval_id = setInterval(function(){
- var a = document.getElementsByClassName("show-full")[0];
- var b = document.getElementsByClassName("show-full-block")[0];
- var c = document.getElementsByClassName(" show-full-btn")[0];
-
- $$('.columen-view-aside','hide_one');
-
- if(a)a.style.height = "auto";
- if(b){
- clearInterval(interval_id);
- b.style.height = "auto";
- }
- if(c)c.style.display = "none";
-
- },100);
- break;
-
- case "www.cnblogs.com":
-
- $$("#sideBar",'hide_one');
- $$("#vid",'hide_one');
- $$("#left",'hide_one');
- $$("#right_content",'hide_one');
- $$("#leftcontent",'hide_one');
- var a = $$("#centercontent",'return_one');
- if(a){a.style['padding-left'] = 0;}
- break;
-
- case "github.com":
- document.body.style.minWidth = '100px';
- var github_pad = document.querySelector('.column.three-fourths.codesearch-results.pr-6') ;
- if(github_pad ){
- github_pad.style.padding = '10px 0 10px 30px';
- }
- //change_style(,{'max-width':document.body.clientWidth+'px'});
- break;
-
- case "wiki.jikexueyuan.com":
- $$(".detail-left",'hide_one');
- var a = $$(".detail-main",'no_option','one');
- a.style['margin-left'] = '0px';
- a.style.width = document.body.clientWidth+'px';
- break;
-
- case "www.cssmoban.com":
- var a = $$(".wide-main.col-media-main.clearfix",'return_one');
- a.style.width = document.body.clientWidth+'px';
- break;
-
- case "www.kancloud.cn":
- var interval_id = setInterval(function(){
- if(document.querySelector(".sidebar")){
- var a = document.querySelector(".sidebar");
- document.querySelector(".workspace").style.left = "180px";
- a.style.width = '180px';
- change_style(a);
- clearInterval(interval_id);
- }
- },100);
- break;
-
- case "php.net":
- $$('.layout-menu','remove_one');
- if($$(".sect1",'return_one'))$$(".sect1",'return_one').style.width = document.body.clientWidth-50+"px";
- if($$("#usernotes",'return_one'))$$("#usernotes",'return_one').style.width = document.body.clientWidth-50+"px";
- break;
-
- case "www.zhihu.com":
- $$('.Question-sideColumn.Question-sideColumn--sticky','remove_one');
- $$('.AdblockBanner-inner','remove_one');
- $$('.QuestionHeader-side','remove_all');
- $$('.AppHeader-userInfo','remove_all');
-
- var browser_width = document.body.clientWidth -50+"px";
- $$('.QuestionHeader-content','return_one').style.width = browser_width;
-
- setInterval(function(){
- if(document.querySelector(".HitQrcode")){
- $$('.HitQrcode','remove_one');
- }
- },100);
- break;
-
- case "www.letscorp.net":
- $$('#commentlist','remove_one');
- $$('#sidebar','remove_one');
- $$('#header','remove_one');
-
- var browser_width = document.body.clientWidth -50+"px";
- $$('#container','return_one').style.width = browser_width;
- $$('#main','return_one').style.height = "auto";
- var p_ele = $$('p','return_all');
- Array.prototype.forEach.call(p_ele,function(e){
- e.style["font-size"] = "16px";
- });
- break;
-
- case "segmentfault.com":
- $$("#loginBanner","remove_one");
- break;
-
- case "huziketang.mangojuice.top":
- for(var i=0 ;i<10000 ;i++){
- clearInterval(i);
- }
- $$("div","return_all").forEach(function(ele){
- if(ele.id && ele.id!=="wrapper" && ele.id!=="uyan_frame" && ele.id!=="donate-mask" ){
- ele.parentNode.removeChild(ele);
- }
- });
- break;
-
- case "lvv2.com":
- if( $$(".link.show","return_all") ) {
- $$(".link.show","return_all").forEach(function(ele){
- if(ele.querySelector('a.title') ){
- // console.log(ele.querySelector('a.title').innerHTML)
- ele.querySelector('a.title').style.fontSize = '16px'
- var title = ele.querySelector('a.title').innerHTML
- var porn_list = ['约炮','母狗','调教','草','鸡巴','小受','口爆','野战','SM','sm','贱货','被虐','淫','内裤','屁眼','蕾丝','姿势','体位','色情','骚','屌','淫荡','射','艹','丝袜','情色','调情','做爱','操','捆绑','挑逗','绿帽','潮喷','援交','jj','JJ','潮吹','3p','3P','腰','臀','肉棒','啪啪','圣水']
- var politic_list = ['中共','土共','民主','法治','天安门','老兵','自由','殴打','近平','奴隶','道德','强拆','法律','监狱','城管','土匪','毛腊肉','老毛','专制','社会主义','党中央','统治','酷刑','党员','人民','民族','P2P','普京','英雄','纳税','维权','执法','警察','独裁','政府','郭文贵','文革','武装','共产','垬','毛泽东','政权','枪','举报','恐怖','宗教','卖国','死','软禁']
- var key_word_list = porn_list.concat( politic_list)
- var porn_detection = key_word_list.some(function(ele){
- return title.indexOf(ele) > -1
- })
- porn_detection && ele.parentNode.removeChild(ele)
- // ele.parentNode.removeChild(ele);
- }
- });
- }
- break;
-
- default:
- var obj = main_ele_searcher();
- ele_remover(obj);
- //main_content_adjust(obj.main_ele);
-
- }
-
- window.change_style_flag && change_style();
- console.clear();
- console.timeEnd("allen_web_time_count");
-
-
- }catch(err){
- //console.log(err.name,' ',err.message);
- console.log(err.stack);
- }
-
-
-
- //window.frames
- //Array.prototype.slice.call(ele)
-
- //寻找页面的主要内容
- function main_ele_searcher() {
- var ele = document.querySelectorAll("*");
- var arr = [];
- //var arr_index = [];
- var w,h;
-
- var body_width = document.body.clientWidth;
- var body_height = document.body.clientHeight;
-
- if(!body_height){
- var max_width = 0,max_height = 0;
- document.documentElement.style.height = '100%';
- document.body.style.height = '100%';
-
- for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
- w = ele[i].clientWidth;
- h = ele[i].clientHeight;
- if ( w > max_width) {max_width = w;}
- if ( h > max_height) {max_height = h;}
- w=null;
- h =null;
- }
- body_width = max_width ;
- body_height = max_height;
- }
-
-
- for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
- w = ele[i].clientWidth;
- h = ele[i].clientHeight;
- //console.log(h);
-
- if ( w && h && w >body_width/2 && h> body_height/5 && w <body_width && h< body_height) {
- arr[w * h] = ele[i];
- //console.log(ele[i]);
- //arr_index.push(w * h);
- }
- w=null;
- h =null;
- }
- var main_ele = arr[arr.length-1] || document.body;
- return {
- main_ele,
- body_width,
- body_height
- };
- }
-
- //去除侧边栏这样“狭长”的内容
- function ele_remover(obj){
- var w,h;
- var {main_ele,body_width, body_height }= obj;
- var ele = document.querySelectorAll("*");
- //console.log(main_ele,body_width, body_height )
- for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
- w = ele[i].clientWidth;
- h = ele[i].clientHeight;
- // main_ele.parentNode.children
- 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 ) {
- //content_adjust(ele[i]);
- console.log("---------element removed ------------");
- console.log(ele[i]);
- console.log("---------element removed ------------");
-
- ele[i].parentNode.removeChild(ele[i]);
- }
- w=null;
- h =null;
- }
- }
-
- //去除被移除元素的兄弟元素的padding margin
- function content_adjust(ele){
- var siblings = ele.parentNode.children;
- ele.parentNode.style.position = "relative";
- // console.log(ele);
- for (let i = 0, ele_length = siblings.length; i < ele_length; i++) {
- //console.log(siblings[i]);
- siblings[i].setAttribute('style','position:relative;padding:20px;margin:0px;overflow:visible;');
- }
- }
-
-
- //调整主要内容的样式
- function main_content_adjust(main_ele){
- //var a = [{x,y,top,right,bottom,left,width}]=main_ele.getClientRects();
- //main_ele.parentNode.style.position = "relative";
- //main_ele.setAttribute('style','position:relative;padding:20px 20px 20px 40px;margin:auto;clear:both;overflow:visible;');
- var ratio =0.9 * (window.innerWidth ) /main_ele.clientWidth;
- var ele = main_ele.querySelectorAll('*');
- // console.log(ele);
- for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
- ele[i].style.width = ele[i].clientWidth* ratio +"px";
- ele[i].style.overflow = 'visible';
- //console.log(i);
- }
-
- }
-
- //背景调色
- function change_style (arr){
- // 执行速度 : for 循环 > forEach > 尾递归 >递归 (迭代)
- var all = arr || document.querySelectorAll('*');
- for (let i = 0, ele_length = all.length; i < ele_length; i++) {
- if(!all[i].style.backgroundColor){
- 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)" ;
- }
- }
- }
-
- function do_not_change_style(){
- window.change_style_flag = false;
- }
-
- function ele_hide(e){
- if(e)e.style.display = "none" ;
- }
- function ele_hide_all(all){
- Array.prototype.forEach.call(all,function(e){e.style.display = "none";});
- }
- function ele_remove(e){
- if(e) e.parentNode.removeChild(e);
- }
- function ele_remove_all(all){
- Array.prototype.forEach.call(all,function(e){e.parentNode.removeChild(e);});
- }
-
-
- function $$(selector,operation_code){
- // operation_code : return_one return_all remove_one remove_all hide_one hide_all
-
- switch(operation_code){
- case 'return_one': //return_one
- return document.querySelector(selector) ;
- case 'return_all':// return_all
- return document.querySelectorAll(selector);
- case 'remove_one': //remove_one
- ele_remove(document.querySelector(selector));
- break;
- case 'remove_all': //remove_all
- ele_remove_all(document.querySelectorAll(selector));
- break;
- case 'hide_one': //hide_one
- ele_hide(document.querySelector(selector));
- break;
- case 'hide_all':// hide_all
- ele_hide_all(document.querySelectorAll(selector));
- break;
-
- default:
- var result = document.querySelectorAll(selector);
- return result.length >1 ? result : result[0] ;
- }
- }
-
-
- function remove_div_padding_margin(ele){
- if( ele ){
- ele.setAttribute('style','overflow:visible;position:relative;padding:0px;margin:0px;left:0px;');
- }
- if(ele && ele.children.length > 0){
- Array.prototype.forEach.call(ele.children,(function(e){
- remove_div_padding_margin(e);
- }));
- }
- }
-
- function content_get() {
- var ajax = new XMLHttpRequest();
- ajax.open('get', '/');
- ajax.send();
- ajax.onreadystatechange = function() {
- if (ajax.readyState == 4 && ajax.status == 200) {
- content_new = ajax.responseText;
- //console.log(content_new);
- content_old = content_old || content_new;
- if(content_new !== content_old){
- location.reload() ;
- }
- }
- };
-
- setTimeout(content_get,1000);
- }
-
-
-
-
-
- /* jshint ignore:start */
- //]]></>).toString();
- //var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });
- //eval(c.code);
- /* jshint ignore:end */