Programer's Web Friend

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

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

  1. // ==UserScript==
  2. // @name Programer's Web Friend
  3. // @namespace https://tampermonkey.net/
  4. // @version 2.3.3
  5. // @description change Programer's Web style to mobile device friendly ,and more readble
  6. // @author @Amormaid
  7. // @run-at document-end
  8. // @match http://*/*
  9. // @include http://*
  10. // @include https://*
  11. // @exclude http://localhost*
  12. // @license MIT License
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16.  
  17. main()
  18.  
  19. function main() {
  20. // var root = document.body;
  21. // var hostname = /\d+\.\d+\.\d+\.\d+/.test(window.location.hostname) ? "ip": window.location.hostname;
  22. var hostname = window.location.hostname;
  23.  
  24. if (exclude_check(hostname)) {
  25. return
  26. }
  27.  
  28. // console.clear();
  29.  
  30. try {
  31. console.time("allen_web_time_count");
  32. // customer change
  33. let rules = customer_rules()
  34. let matched_rule = rules.filter( rule_item => rule_item.hostname instanceof Array
  35. ? rule_item.hostname.includes(hostname)
  36. : rule_item.hostname === hostname
  37. )[0]
  38. matched_rule.action()
  39. // main_content_adjust(obj.main_ele);
  40. var main_content = main_ele_searcher();
  41. ele_remover(main_content);
  42. // full window
  43. // document.body.style.cssText = "position:absolute; top:0;right:0; bottom:0;left:0;"
  44. // document.body.style.width = window.innerWidth
  45. // document.body.style.height = window.innerHeight
  46. change_style();
  47. console.timeEnd("allen_web_time_count");
  48. } catch(err) {
  49. //console.log(err.name,' ',err.message);
  50. console.log(err.message);
  51. }
  52. }
  53.  
  54. // white list check
  55. function exclude_check(hostname_param) {
  56. // 不执行脚本的网站白名单
  57. let exclude_list = [
  58. "www.youtube.com",
  59. "demo.mycodes.net",
  60. "kiwivm.64clouds.com",
  61. "www.instagram.com",
  62. "www.h-ui.net",
  63. "www.layui.com",
  64. "www.kixeye.com",
  65. "pan.baidu.com",
  66. "www.rishiqing.com",
  67. "wx.qq.com",
  68. "mail.126.com",
  69. "twitter.com",
  70. "reactjs.org",
  71. "codepen.io",
  72. "free.modao.cc",
  73. "lanhuapp.com",
  74. "developers.weixin.qq.com",
  75. "jira.vankeservice.com",
  76. "www.tapd.cn",
  77. "10.0.74.227",
  78. "modao.cc",
  79. "element-cn.eleme.io",
  80. ""
  81. ]
  82. return exclude_list.includes(hostname_param)
  83. }
  84.  
  85. // 自定义样式调整
  86. function customer_rules() {
  87. let rules = [
  88. {
  89. rule: "default",
  90. hostname: "ip",
  91. regexp: "",
  92. action: () => {}
  93. },
  94. {
  95. rule: "default",
  96. hostname: "wc-kx-vip.sjc.kixeye.com",
  97. regexp: "",
  98. action: () => {
  99. $$('#above-game-message', 'remove_one');
  100. $$('#kxp-footer-bar', 'remove_one');
  101. $$('#topnavbar_back', 'remove_one');
  102. }
  103. },
  104. {
  105. rule: "default",
  106. hostname: ["www.baidu.com", "zhidao.baidu.com"],
  107. regexp: "",
  108. action: () => {
  109. let interval_id = setInterval( () => {
  110. const right_list_length = 5
  111. $$("#content_right", 'remove_all');
  112. var zhidao_body = $$("#body", "return_one");
  113. var container = $$("#container", "return_one");
  114. var head = $$("#head", "return_one");
  115. var pad = $$("#s_tab", "return_one");
  116. $$("#rs", "remove_all")
  117. var u = $$("#u", "return_one");
  118. container.style.cssText = "display:block;width:100%;position:relative;"
  119. head && (() => {
  120. head.style.position = 'relative';
  121. head.style.width = window.innerWidth - 100 + 'px';
  122. head.style['min-width'] = 0;
  123. })();
  124. pad && (() => {
  125. pad.style.padding = '0 0 0 121px'
  126. })();
  127. u && (() => {
  128. u.style.display = 'none'
  129. })();
  130. zhidao_body && (() => {
  131. zhidao_body.style.left = "50px"
  132. })();
  133.  
  134. let origin_length = document.getElementById("content_left").children.length
  135.  
  136. if (origin_length > 6) {
  137. // console.log(content_list)
  138. let right_list = Array.prototype.slice.call($$(".result", "return_all"),-1 - right_list_length, -1)
  139. let container_r = document.createElement("div")
  140. container_r.style.cssText += "display:block;position:absolute;top:40px;left:740px;width:600px;"
  141. // let str = Array.prototype.reduce.call(right_list, (html_str, item ,index , right_list) => (item.innerHTML + html_str), '')
  142. Array.prototype.forEach.call(right_list, item => {
  143. item.style.cssText += "padding:10px 0;"
  144. container_r.appendChild(item)
  145. })
  146. let container_r_dom = container.appendChild(container_r)
  147. let page_indic = $$("#page", "return_one")
  148. page_indic.style.cssText = "position:absolute;top:0px;left:660px;margin:-60px 0 0 0;z-index:300"
  149. }
  150.  
  151. },300)
  152. }
  153. },
  154. {
  155. rule: "default",
  156. hostname: ["i.taobao.com", "trade.taobao.com", "rate.taobao.com", "buyertrade.taobao.com"],
  157. regexp: "",
  158. action: () => {
  159. $$(".m-guess-you-like", "remove_one");
  160. $$(".m-someone-like-you", 'remove_one');
  161. $$("#p4p_ad", 'remove_one');
  162. $$(".J_guess-you-like", 'remove_one');
  163. }
  164. },
  165. {
  166. rule: "default",
  167. hostname: ["www.cnblogs.com", "blog.csdn.net"],
  168. regexp: "",
  169. action: () => {
  170. var content = $$("#content", "return_one");
  171. $$("#sidebar", "remove_one");
  172. $$("#side", 'remove_one');
  173.  
  174. content && (() => {
  175. content.style["margin-right"] = "10";
  176. content.style.width = window.innerWidth - 100 + 'px';
  177. })();
  178.  
  179. let article = $$("#article_content", "return_one");
  180. article && (() => {
  181. article.style.height = "100%";
  182. article.style.overflow = "visible";
  183. })()
  184. $$(".recommend-item-box", "remove_all");
  185. $$(".hide-article-box", "remove_one");
  186. $$("aside", "remove_one");
  187. let main = $$("main", "return_one")
  188. if (main) main.style.float = "left";
  189. setTimeout(() => {
  190. $$(".adblock", "remove_one");
  191. },
  192. 3000)
  193. $$(".pulllog-box", "remove_one");
  194. }
  195. },
  196. {
  197. rule: "default",
  198. hostname: "www.w3school.com.cn",
  199. regexp: "",
  200. action: () => {
  201. $$("#navsecond", 'hide_one');
  202. }
  203. },
  204. {
  205. rule: "default",
  206. hostname: "wallstreetcn.com",
  207. regexp: "",
  208. action: () => {
  209. setInterval(() => {
  210. $$('.news-item__cover', 'remove_all');
  211. $$('.qn-img', 'remove_all');
  212. // console.log(new Date() - 0)
  213. change_style();
  214. },
  215. 500);
  216.  
  217. $$('.left-bar', 'remove_one');
  218. }
  219. },
  220. {
  221. rule: "default",
  222. hostname: "www.merriam-webster.com",
  223. regexp: "",
  224. action: () => {
  225. $$(".right-rail", 'hide_one');
  226. $$("#recirc-bar-footer", 'hide_one');
  227. $$(".wgt-related-to.jc-card-box.clearfix", 'hide_one');
  228. }
  229. },
  230. {
  231. rule: "default",
  232. hostname: "blog.sina.com.cn",
  233. regexp: "",
  234. action: () => {
  235. $$("#column_1", 'hide_one');
  236. }
  237. },
  238. {
  239. rule: "default",
  240. hostname: ["blog.jobbole.com", "web.jobbole.com"],
  241. regexp: "",
  242. action: () => {
  243. $$("#sidebar", 'hide_one');
  244. var grid = $$(".grid-8", 'return_one');
  245. grid && (() => {
  246. grid.style.width = "100%"
  247. })();
  248. }
  249. },
  250. {
  251. rule: "default",
  252. hostname: "juejin.im",
  253. regexp: "",
  254. action: () => {
  255. var interval_id = setInterval(() => {
  256. var a = $$(".show-full", 'return_one');
  257. var b = $$(".show-full-block", 'return_one');
  258. $$(".show-full-btn", 'remove_one');
  259. $$('.columen-view-aside', 'hide_one');
  260.  
  261. if (a) a.style.height = "auto";
  262. a && a.setAttribute('style', 'height:auto')
  263. if (b) {
  264. clearInterval(interval_id);
  265. b.setAttribute('style', 'height:auto')
  266. }
  267. },
  268. 100);
  269. setInterval(change_style, 300)
  270. }
  271. },
  272. {
  273. rule: "default",
  274. hostname: "www.cnblogs.com",
  275. regexp: "",
  276. action: () => {
  277. $$("#sideBar", 'hide_one');
  278. $$("#vid", 'hide_one');
  279. $$("#left", 'hide_one');
  280. $$("#right_content", 'hide_one');
  281. $$("#leftcontent", 'hide_one');
  282. var a = $$("#centercontent", 'return_one');
  283. if (a) {
  284. a.style['padding-left'] = 0;
  285. }
  286. }
  287. },
  288. {
  289. rule: "default",
  290. hostname: "github.com",
  291. regexp: "",
  292. action: () => {
  293. document.body.style.minWidth = '100px';
  294. var github_pad = document.querySelector('.column.three-fourths.codesearch-results.pr-6');
  295. if (github_pad) {
  296. github_pad.style.padding = '10px 0 10px 30px';
  297. }
  298. }
  299. },
  300. {
  301. rule: "default",
  302. hostname: "wiki.jikexueyuan.com",
  303. regexp: "",
  304. action: () => {
  305. $$(".detail-left", 'hide_one');
  306. var a = $$(".detail-main", 'no_option', 'one');
  307. a.style['margin-left'] = '0px';
  308. a.style.width = document.body.clientWidth + 'px';
  309. }
  310. },
  311. {
  312. rule: "default",
  313. hostname: "www.cssmoban.com",
  314. regexp: "",
  315. action: () => {
  316. var a = $$(".wide-main.col-media-main.clearfix", 'return_one');
  317. a.style.width = document.body.clientWidth + 'px';
  318. }
  319. },
  320. {
  321. rule: "default",
  322. hostname: "www.kancloud.cn",
  323. regexp: "",
  324. action: () => {
  325. var interval_id = setInterval(() => {
  326. var a = $$(".sidebar", 'return_one');
  327. if (a) {
  328. $$(".workspace", 'return_one').style.left = "180px";
  329. a.style.width = '180px';
  330. change_style(a);
  331. clearInterval(interval_id);
  332. }
  333. },
  334. 100);
  335. }
  336. },
  337. {
  338. rule: "default",
  339. hostname: "php.net",
  340. regexp: "",
  341. action: () => {
  342. $$('.layout-menu', 'remove_one');
  343. if ($$(".sect1", 'return_one')) $$(".sect1", 'return_one').style.width = document.body.clientWidth - 50 + "px";
  344. if ($$("#usernotes", 'return_one')) $$("#usernotes", 'return_one').style.width = document.body.clientWidth - 50 + "px";
  345. }
  346. },
  347. {
  348. rule: "default",
  349. hostname: "www.zhihu.com",
  350. regexp: "",
  351. action: () => {
  352. $$('.Question-sideColumn.Question-sideColumn--sticky', 'remove_one');
  353. $$('.AdblockBanner-inner', 'remove_one');
  354. $$('.QuestionHeader-side', 'remove_all');
  355. $$('.AppHeader-userInfo', 'remove_all');
  356.  
  357. var browser_width = document.body.clientWidth - 50 + "px";
  358. $$('.QuestionHeader-content', 'return_one').style.width = browser_width;
  359.  
  360. setInterval(() => {
  361. $$('.HitQrcode', 'remove_one');
  362. },
  363. 100);
  364. }
  365. },
  366. {
  367. rule: "default",
  368. hostname: "www.letscorp.net",
  369. regexp: "",
  370. action: () => {
  371. $$('#commentlist', 'remove_one');
  372. $$('#sidebar', 'remove_one');
  373. $$('#header', 'remove_one');
  374.  
  375. var browser_width = document.body.clientWidth - 50 + "px";
  376. $$('#container', 'return_one').style.width = browser_width;
  377. $$('#main', 'return_one').style.height = "auto";
  378. var p_ele = $$('p', 'return_all');
  379. Array.prototype.forEach.call(p_ele,
  380. function(e) {
  381. e.style["font-size"] = "16px";
  382. });
  383. }
  384. },
  385. {
  386. rule: "default",
  387. hostname: "segmentfault.com",
  388. regexp: "",
  389. action: () => {
  390. $$("#loginBanner", "remove_one");
  391. }
  392. },
  393. {
  394. rule: "default",
  395. hostname: "huziketang.mangojuice.top",
  396. regexp: "",
  397. action: () => {
  398. for (var i = 0; i < 10000; i++) {
  399. clearInterval(i);
  400. }-
  401. $$("div", "return_all").forEach(function(ele) {
  402. if (ele.id && ele.id !== "wrapper" && ele.id !== "uyan_frame" && ele.id !== "donate-mask") {
  403. ele.parentNode.removeChild(ele);
  404. }
  405. });
  406. }
  407. },
  408. {
  409. rule: "default",
  410. hostname: "lvv2.com",
  411. regexp: "",
  412. action: () => {
  413. if ($$(".link.show", "return_all")) {
  414. $$(".link.show", "return_all").forEach(function(ele) {
  415. if (ele.querySelector('a.title')) {
  416. // console.log(ele.querySelector('a.title').innerHTML)
  417. ele.querySelector('a.title').style.fontSize = '16px'
  418. var title = ele.querySelector('a.title').innerHTML
  419. var porn_list = ['日', '勾引', '野外', '肏', '抽插', '公厕', '舔', '茎', '肛', '奴', '约炮', '母狗', '调教', '草', '鸡巴', '小受', '口爆', '野战', 'SM', 'sm', '贱货', '被虐', '淫', '内裤', '屁眼', '蕾丝', '姿势', '体位', '色情', '骚', '屌', '淫荡', '射', '艹', '丝袜', '情色', '调情', '做爱', '操', '捆绑', '挑逗', '绿帽', '潮喷', '援交', 'jj', 'JJ', '潮吹', '3p', '3P', '腰', '臀', '肉棒', '啪啪', '圣水']
  420. var politic_list = ['中共', '土共', '民主', '法治', '天安门', '老兵', '自由', '殴打', '近平', '奴隶', '道德', '强拆', '法律', '监狱', '城管', '土匪', '毛腊肉', '老毛', '专制', '社会主义', '党中央', '统治', '酷刑', '党员', '人民', '民族', 'P2P', '普京', '英雄', '纳税', '维权', '执法', '警察', '独裁', '政府', '郭文贵', '文革', '武装', '共产', '垬', '毛泽东', '政权', '枪', '举报', '恐怖', '宗教', '卖国', '死', '软禁']
  421. var key_word_list = porn_list.concat(politic_list)
  422. var porn_detection = key_word_list.some(function(ele) {
  423. return title.indexOf(ele) > -1
  424. })
  425. porn_detection && ele.parentNode.removeChild(ele)
  426. // ele.parentNode.removeChild(ele);
  427. }
  428. });
  429. }
  430. }
  431. },
  432. {
  433. rule: "default",
  434. hostname: "",
  435. regexp: "",
  436. action: () => {
  437.  
  438. }
  439. },
  440.  
  441. ]
  442.  
  443. return rules
  444. }
  445.  
  446. //window.frames
  447. //Array.prototype.slice.call(ele)
  448.  
  449. //寻找页面的主要内容
  450. function main_ele_searcher() {
  451. var ele = document.querySelectorAll("*");
  452. var arr = [];
  453. //var arr_index = [];
  454. var w, h;
  455.  
  456. var body_width = document.body.clientWidth;
  457. var body_height = document.body.clientHeight;
  458.  
  459. if (!body_height) {
  460. var max_width = 0, max_height = 0;
  461. document.documentElement.style.height = '100%';
  462. document.body.style.height = '100%';
  463.  
  464. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  465. w = ele[i].clientWidth;
  466. h = ele[i].clientHeight;
  467. if (w > max_width) { max_width = w; }
  468. if (h > max_height) { max_height = h; }
  469. w = null;
  470. h = null;
  471. }
  472. body_width = max_width;
  473. body_height = max_height;
  474. }
  475.  
  476.  
  477. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  478. w = ele[i].clientWidth;
  479. h = ele[i].clientHeight;
  480. //console.log(h);
  481.  
  482. if (w && h && w > body_width / 2 && h > body_height / 5 && w < body_width && h < body_height) {
  483. arr[w * h] = ele[i];
  484. //console.log(ele[i]);
  485. //arr_index.push(w * h);
  486. }
  487. w = null;
  488. h = null;
  489. }
  490. var main_ele = arr[arr.length - 1] || document.body;
  491. return {
  492. main_ele,
  493. body_width,
  494. body_height
  495. };
  496. }
  497.  
  498. //去除侧边栏这样“狭长”的内容
  499. function ele_remover(obj) {
  500. var w, h;
  501. var { main_ele, body_width, body_height } = obj;
  502. var ele = document.querySelectorAll("*");
  503. //console.log(main_ele,body_width, body_height )
  504. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  505. w = ele[i].clientWidth;
  506. h = ele[i].clientHeight;
  507. // main_ele.parentNode.children
  508. 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) {
  509. //content_adjust(ele[i]);
  510. console.log("---------element removed ------------");
  511. console.log(ele[i]);
  512. console.log("---------element removed ------------");
  513.  
  514. ele[i].parentNode.removeChild(ele[i]);
  515. }
  516. w = null;
  517. h = null;
  518. }
  519. }
  520.  
  521. //去除被移除元素的兄弟元素的padding margin
  522. function content_adjust(ele) {
  523. var siblings = ele.parentNode.children;
  524. ele.parentNode.style.position = "relative";
  525. // console.log(ele);
  526. for (let i = 0, ele_length = siblings.length; i < ele_length; i++) {
  527. //console.log(siblings[i]);
  528. siblings[i].setAttribute('style', 'position:relative;padding:20px;margin:0px;overflow:visible;');
  529. }
  530. }
  531.  
  532.  
  533. //调整主要内容的样式
  534. function main_content_adjust(main_ele) {
  535. //var a = [{x,y,top,right,bottom,left,width}]=main_ele.getClientRects();
  536. main_ele.parentNode.style.position = "relative";
  537. main_ele.style.cssText = "position:absolute; top:0;right:0; bottom:0;left:0;"
  538. // main_ele.setAttribute('style','position:relative;padding:20px 20px 20px 40px;margin:auto;clear:both;overflow:visible;');
  539. var ratio = 0.9 * (window.innerWidth) / main_ele.clientWidth;
  540. var ele = main_ele.querySelectorAll('*');
  541. // console.log(ele);
  542. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  543. ele[i].style.width = ele[i].clientWidth * ratio + "px";
  544. ele[i].style.overflow = 'visible';
  545. //console.log(i);
  546. }
  547.  
  548. }
  549.  
  550.  
  551.  
  552. // body 全屏
  553. function full_body() {
  554. let root = document.body
  555. root.style.cssText = "position:absolute; top:0;right:0; bottom:0;left:0;"
  556. }
  557. //背景调色
  558. function change_style(DOM_node = document.body) {
  559. // 执行速度 : for 循环 > forEach > 尾递归 >递归 (迭代)
  560. let background_base_color = 50;
  561. let background_offset = 20;
  562. let font_base_color = 230;
  563. let font_offset = 20;
  564. var all = (DOM_node || document).querySelectorAll('*');
  565. for (let i = 0, ele_length = all.length; i < ele_length; i++) {
  566. let item = all[i]
  567. let item_style = item.style
  568. let tag_exclude_check = !('script,style,img').includes(item.nodeName.toLowerCase())
  569. if(tag_exclude_check && !item_style.backgroundColor){
  570. item_style.backgroundColor = random_color(background_base_color,background_offset);
  571. item_style.color = random_color(font_base_color,font_offset);
  572. }
  573. }
  574. /*
  575. let background_base_color = 40;
  576. let background_offset = 20;
  577. let font_base_color = 200;
  578. let font_offset = 50;
  579. let html_str = DOM_node.innerHTML ;
  580. // 匹配速度 string.indexOf > string.match
  581. // let html_str = DOM_node.innerHTML.replace(/\&/g,'') ;
  582. // var all = (new DOMParser()).parseFromString(html_str, "text/xml");
  583. let html_str_arr = html_str.split(">");
  584. let new_html_str_arr = html_str_arr.map((item, index) => {
  585. if(item.indexOf('</') > 0) {return item }
  586. if(!item.match(/\<div|\<form|\<table|\<dl|\<ol|\<ul|\<pre|\<h|\<a|\<p|\<code|\<em|\<span|\<td|\<th|\<input|\<textarea/i)) {return item }
  587. let font_color_str = ";color:"+random_color(font_base_color,font_offset);
  588. if(item.indexOf('background-color') > 0) {
  589. let reg = /background-color\s*\:\s*[\w\,\(\)\#]+/;
  590. let str = 'background-color:' + random_color(background_base_color,background_offset) + font_color_str;
  591. return item.replace(reg, str)
  592. }
  593. if(item.indexOf('background') > 0) {
  594. let reg = /\#[^\s]+|rgb[^\)]+\)/;
  595. let str = random_color(background_base_color,background_offset);
  596. return item.replace(reg, str).replace(/(style=(["'])[^'"]+)\2/,"$1" + font_color_str + "$2")
  597. }
  598. return `${item} style="background-color:${random_color(background_base_color,background_offset)}${font_color_str}"`;
  599. })
  600.  
  601. DOM_node.innerHTML = new_html_str_arr.join(">")
  602. DOM_node.style.backgroundColor = random_color(background_base_color,background_offset);
  603. */
  604. }
  605.  
  606. function random_color(base_color, offset, ratio=1){
  607. base_color = (base_color & 255) === (~~base_color) ? ~~base_color : 255;
  608. offset = ~~offset
  609. offset = (base_color+offset > 0 && base_color+offset < 256)? offset : 0
  610. return `rgba(${(base_color + offset*Math.random())&255},${(base_color + offset*Math.random())&255},${(base_color + offset*Math.random())&255},0.8)`;
  611. }
  612.  
  613.  
  614. function ele_hide(e) {
  615. // if (document.body.hasChildNodes(e)) e.style.display = "none";
  616. document.body.hasChildNodes(e) && e.length !== 0 && e.style.setAttribute('display', "none");
  617. }
  618. function ele_hide_all(all) {
  619. Array.prototype.forEach.call(all, function (e) { e.style.display = "none"; });
  620. }
  621. function ele_remove(e) {
  622. // if (document.body.hasChildNodes(e)) e.parentNode.removeChild(e);
  623. document.body.hasChildNodes(e) && e.length !== 0 && e.parentNode.removeChild(e);
  624. }
  625. function ele_remove_all(all) {
  626. if (all) {
  627. all = Array.from(all)
  628. }
  629. if (!all.length) {
  630. return
  631. }
  632. Array.prototype.forEach.call(all, function (e) {
  633. e instanceof Object && e.parentNode.removeChild(e);
  634. });
  635. }
  636.  
  637.  
  638. function $$(selector, operation_code) {
  639. // operation_code : return_one return_all remove_one remove_all hide_one hide_all
  640. function get(selector) {
  641. if((/^#[^.#]+$/).test(selector)) {
  642. return [document.getElementById(selector.slice(1, selector.length))]
  643. }
  644. if((/^\.[^.#]+$/).test(selector)) {
  645. return document.getElementsByClassName(selector.slice(1, selector.length))
  646. }
  647. if((/^[^.#]+$/).test(selector)) {
  648. return document.getElementsByTagName(selector)
  649. }
  650. }
  651. switch (operation_code) {
  652. case 'return_one': //return_one
  653. // return document.querySelector(selector);
  654. return get(selector)[0];
  655. case 'return_all':// return_all
  656. // return document.querySelectorAll(selector);
  657. return get(selector);
  658. case 'remove_one': //remove_one
  659. // ele_remove(document.querySelector(selector));
  660. ele_remove(get(selector));
  661. break;
  662. case 'remove_all': //remove_all
  663. // ele_remove_all(document.querySelectorAll(selector));
  664. ele_remove_all(get(selector));
  665. break;
  666. case 'hide_one': //hide_one
  667. // ele_hide(document.querySelector(selector));
  668. ele_hide(get(selector));
  669. break;
  670. case 'hide_all':// hide_all
  671. // ele_hide_all(document.querySelectorAll(selector));
  672. ele_hide_all(get(selector));
  673. break;
  674.  
  675. default:
  676. // var result = document.querySelectorAll(selector);
  677. var result = get(selector);
  678. return result.length > 1 ? result : result[0];
  679. }
  680. }
  681.  
  682.  
  683. function remove_div_padding_margin(ele) {
  684. if (ele) {
  685. ele.setAttribute('style', 'overflow:visible;position:relative;padding:0px;margin:0px;left:0px;');
  686. }
  687. if (ele && ele.children.length > 0) {
  688. Array.prototype.forEach.call(ele.children, (function (e) {
  689. remove_div_padding_margin(e);
  690. }));
  691. }
  692. }
  693.  
  694. function content_get() {
  695. var ajax = new XMLHttpRequest();
  696. ajax.open('get', '/');
  697. ajax.send();
  698. ajax.onreadystatechange = function () {
  699. if (ajax.readyState == 4 && ajax.status == 200) {
  700. content_new = ajax.responseText;
  701. //console.log(content_new);
  702. content_old = content_old || content_new;
  703. if (content_new !== content_old) {
  704. location.reload();
  705. }
  706. }
  707. };
  708.  
  709. setTimeout(content_get, 1000);
  710. }