// ==UserScript==
// @name Programer's Web Friend
// @namespace https://tampermonkey.net/
// @version 1.6
// @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/*
// @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;
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":
var head = document.getElementById("head");
var pad = document.getElementById("s_tab");
var u = document.getElementById("u");
var setInterval_id;
document.getElementById("container").style.width = "700px";
head.style.position = 'relative';
head.style.width = window.innerWidth-100+'px';
head.style['min-width'] = 0;
pad.style.padding = '0 0 0 121px';
u.style.display = 'none';
document.body.style['min-width'] = '10px';
setInterval_id = setInterval(function(){
if(document.querySelector("#content_right") ){
$$("#content_right",'remove_all');
//clearInterval(setInterval_id);
}
},100);
change_style();
break;
case "www.cnblogs.com":
if(typeof sidebar !== "undefined")window.sidebar.style.display = "none";
if(typeof content !== "undefined")window.content.style["margin-right"] = "10";
if(typeof content !== "undefined")window.content.style.width = window.innerWidth-100+'px';
change_style();
break;
case "blog.csdn.net":
if($$("#side",'return_one'))$$("#side",'hide_one');
var CSDN_style_obj = {
'max-width':document.body.clientWidth-16+'px',
'min-width':'2px'
};
change_style();
break;
case "www.w3school.com.cn":
$$("#navsecond",'hide_one');
change_style();
break;
case "www.jquery123.com":
$$("#sidebar",'hide_one');
//var a = $$("#content",'hide_one');
$$(".content-right #content","return_one").style.cssText = "float:left;width:100%;";
if(a) a.style.width = "100%";
change_style();
break;
case "wallstreetcn.com":
setInterval(function(){
$$('.news-item__cover','remove_all');
change_style();
},500);
if($$('.left-bar','return_one'))$$('.left-bar','remove_one');
//$$('.news-right','remove_one');
break;
case "zhidao.baidu.com":
var a =document.getElementById("body");
if(a) a.style.left = "50px";
change_style();
break;
case "www.merriam-webster.com":
$$(".right-rail",'hide_one');
$$("#recirc-bar-footer",'hide_one');
if(a) a.elem.style.width = "100%";
$$(".wgt-related-to.jc-card-box.clearfix",'hide_one');
change_style();
break;
case "blog.sina.com.cn":
$$("#column_1",'hide_one');
change_style();
break;
case "blog.jobbole.com":
case "web.jobbole.com":
$$("#sidebar",'hide_one');
var a = $$(".grid-8",'return_one');
if (a) a.style.width = "100%";
change_style();
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);
change_style();
break;
case "www.cnblogs.com":
change_style();
$$("#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'});
change_style();
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';
change_style();
break;
case "www.cssmoban.com":
var a = $$(".wide-main.col-media-main.clearfix",'return_one');
a.style.width = document.body.clientWidth+'px';
change_style();
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);
change_style();
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";
change_style();
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);
change_style();
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";
});
change_style();
break;
case "segmentfault.com":
$$("#loginBanner","remove_one");
change_style();
break;
default:
var obj = main_ele_searcher();
ele_remover(obj);
//main_content_adjust(obj.main_ele);
change_style();
}
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)" ;
}
}
console.clear();
}
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 = c(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 */