Greasy Fork is available in English.

Programer's Web Friend

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

Per 10-04-2020. Zie de nieuwste versie.

  1. // ==UserScript==
  2. // @name Programer's Web Friend
  3. // @namespace https://tampermonkey.net/
  4. // @version 3.1.8
  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. // console.log('document.cookie', document.cookie)
  21. // document.cookie = document.cookie + 'hhhhhhhhhhhhhhhhhhhhhhh';
  22. // console.log('document.cookie after', document.cookie)
  23. // var root = document.body;
  24. // var hostname = /\d+\.\d+\.\d+\.\d+/.test(window.location.hostname) ? "ip": window.location.hostname;
  25. var hostname = window.location.hostname;
  26.  
  27. if (exclude_check(hostname)) {
  28. return
  29. }
  30.  
  31. // console.clear();
  32.  
  33. try {
  34. console.time("allen_web_time_count");
  35.  
  36. // customer change
  37. let rule = customer_rule(hostname)
  38. rule && rule.action()
  39. // main_content_adjust(obj.main_ele);
  40. // var {main_ele} = main_ele_searcher();
  41. content_purge(main_ele)
  42. // ele_remover(main_content);
  43. // full window
  44. // document.body.style.cssText = "position:absolute; top:0;right:0; bottom:0;left:0;"
  45. // document.body.style.width = window.innerWidth
  46. // document.body.style.height = window.innerHeight
  47. // change_style();
  48. console.timeEnd("allen_web_time_count");
  49. } catch(err) {
  50. //console.log(err.name,' ',err.message);
  51. console.log(err.message);
  52. }
  53. }
  54.  
  55. // white list check
  56. function exclude_check(hostname_param) {
  57. // 不执行脚本的网站白名单
  58. let exclude_list = [
  59. "www.youtube.com",
  60. "demo.mycodes.net",
  61. "kiwivm.64clouds.com",
  62. "www.instagram.com",
  63. "www.h-ui.net",
  64. "www.layui.com",
  65. "www.kixeye.com",
  66. "pan.baidu.com",
  67. "www.rishiqing.com",
  68. "wx.qq.com",
  69. "mail.126.com",
  70. "twitter.com",
  71. "reactjs.org",
  72. "codepen.io",
  73. "free.modao.cc",
  74. "lanhuapp.com",
  75. "developers.weixin.qq.com",
  76. // "jira.vankeservice.com",
  77. "www.tapd.cn",
  78. "modao.cc",
  79. "element-cn.eleme.io",
  80. "github.com",
  81. ""
  82. ]
  83. return exclude_list.includes(hostname_param)
  84. }
  85.  
  86. // 自定义样式调整
  87. function customer_rule(hostname) {
  88. let rules = [
  89. {
  90. rule: "default",
  91. hostname: "ip",
  92. regexp: "",
  93. action: () => {}
  94. },
  95. {
  96. rule: "default",
  97. hostname: "jira.vankeservice.com",
  98. regexp: "",
  99. action: async () => {
  100. if (window.location.href !== 'http://jira.vankeservice.com/browse/COST-677') {
  101. // if (window.location.href !== 'http://jira.vankeservice.com/browse/COST-863') {
  102. console.log('不是项目页,不能填工时')
  103. return
  104. }
  105. await sleep(1000)
  106. const my_data_radio = Array.from(_$('input[type=radio]', "return_all")).find(e => e.parentNode.innerText === 'Only My Data')
  107. console.log('my_data_radio', my_data_radio)
  108. if (!my_data_radio.checked) {
  109. my_data_radio.click()
  110. }
  111. const time_list = Array.from(_$('.sc-hZSUBg.imwLHE', "return_all")).map(e => e.innerText) // .find(e => e.parentNode.innerText === 'Only My Data')
  112. console.log('time_list', time_list)
  113. const now = new Date()
  114. const time_now_string = `${now.getFullYear()}-${('0' + (now.getMonth() + 1)).slice(-2)}-${now.getDate()}`
  115. const today_not_log = !time_list.includes(time_now_string)
  116. // $$('input[type=radio]')
  117. // console.log('button', _$('[name=logTimeBtn]', "return_one"))
  118. // _$('[name=logTimeBtn]', "return_one").click()
  119. // await sleep(1000)
  120. // console.log('button',_$('#from'))
  121.  
  122. // jjjj
  123. const today_should_log = () => {
  124. const national_holiday = [
  125. '2020-04-04',
  126. '2020-04-05',
  127. '2020-04-06',
  128. '2020-05-01',
  129. '2020-05-02',
  130. '2020-05-03',
  131. '2020-05-04',
  132. '2020-05-05',
  133. '2020-06-25',
  134. '2020-06-26',
  135. '2020-06-27',
  136. '2020-10-01',
  137. '2020-10-02',
  138. '2020-10-03',
  139. '2020-10-04',
  140. '2020-10-05',
  141. '2020-10-06',
  142. '2020-10-07',
  143. '2020-10-08'
  144. ]
  145. const national_workday = [
  146. '2020-04-26',
  147. '2020-05-09',
  148. '2020-06-28',
  149. '2020-09-27',
  150. '2020-10-10'
  151. ]
  152. if (national_holiday.includes(getFormatDate(Date.now()))) {
  153. return false
  154. }
  155. if (national_workday.includes(getFormatDate(Date.now()))) {
  156. return true
  157. }
  158. const day_week = new Date(Date.now()).getDay()
  159. if (day_week === 0 || day_week === 6) {
  160. return false
  161. } else {
  162. return true
  163. }
  164. }
  165. const can_log_work_time = today_should_log && today_not_log
  166. if (can_log_work_time){
  167. const begin_time = `${getFormatDate(Date.now())}T09:00:27.792`
  168. const data = {
  169. attributes: {},
  170. billableSeconds: '',
  171. worker: 'xiecy08',
  172. comment: '修复客户端UI及交互的问题',
  173. started: begin_time,
  174. timeSpentSeconds: 28800,
  175. originTaskId: '42572',
  176. remainingEstimate: 0,
  177. endDate: null,
  178. includeNonWorkingDays: false
  179. }
  180. postData('http://jira.vankeservice.com/rest/tempo-timesheets/4/worklogs/', data)
  181. setTimeout(() => {
  182. window.location.href = window.location.href
  183. }, 3 * 1000)
  184. /*
  185. console.log('button', _$('[name=logTimeBtn]', "return_one"))
  186. const begin_time = `${getFormatDate(Date.now())}T09:00:27.792`
  187. const end_time = `${getFormatDate(Date.now())}T11:00:27.792`
  188. const data = {
  189. "attributes":{},
  190. "billableSeconds":"",
  191. "worker":"xiecy08",
  192. "comment":"编写代码",
  193. "started":begin_time,
  194. "timeSpentSeconds":28800,
  195. "originTaskId":"43581",
  196. "remainingEstimate":0,
  197. "endDate":end_time
  198. }
  199. */
  200. /*
  201. const begin_time = `${getFormatDate(Date.now())} 09:00:24.000`
  202. const update_time = `${getFormatDate(Date.now())} 09:01:24.000`
  203. const data = [{
  204. timeSpent: '1d',
  205. billableSeconds: 28800,
  206. issue: {
  207. estimatedRemainingSeconds: 0,
  208. components: [],
  209. versions: [],
  210. summary: '开发类-2018立项朴韵自营装修项目-朴韵自营装修系统-朴韵自营装修-v2.0',
  211. iconUrl: '/secure/viewavatar?size=xsmall&avatarId=10314&avatarType=issuetype',
  212. projectId: 11200,
  213. projectKey: 'COST',
  214. issueType: 'Time',
  215. issueStatus: 'To Do',
  216. internalIssue: false,
  217. reporterKey: 'adminjira',
  218. key: 'COST-677',
  219. id: 42572
  220. },
  221. timeSpentSeconds: 28800,
  222. comment: '解决客户端BUG',
  223. tempoWorklogId: 180361,
  224. attributes: {},
  225. worker: 'xiecy08',
  226. updater: 'xiecy08',
  227. started: begin_time,
  228. dateCreated: update_time,
  229. dateUpdated: update_time,
  230. originTaskId: 42572,
  231. originId: 180361
  232. }]
  233. postData('http://jira.vankeservice.com/rest/tempo-timesheets/4/worklogs/', data)
  234. setTimeout(() => {
  235. // window.location.href = window.location.href
  236. }, 3 * 1000)
  237. */
  238. }
  239. setTimeout(() => {
  240. window.location.href = window.location.href
  241. }, 1 * 3600 * 1000)
  242. }
  243. },
  244. {
  245. rule: "default",
  246. hostname: "qyapi.weixin.qq.com",
  247. regexp: "",
  248. action: () => {
  249. // test
  250. const poster = (word) => {
  251. fetch('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=dfe3c5f9-1c8e-4498-883d-4c4a721e7957', {
  252. method: 'POST',
  253. body: JSON.stringify({
  254. "msgtype": "text",
  255. "text": {
  256. "content": word
  257. }
  258. }),
  259. headers: {
  260. accept: 'application/json',
  261. 'content-type': 'application/json'
  262. },
  263. mode: 'cors'
  264. })
  265. }
  266. poster('hello world')
  267. }
  268. },
  269. {
  270. rule: "default",
  271. hostname: "wc-kx-vip.sjc.kixeye.com",
  272. regexp: "",
  273. action: () => {
  274. _$('#above-game-message', 'remove_one');
  275. _$('#kxp-footer-bar', 'remove_one');
  276. _$('#topnavbar_back', 'remove_one');
  277. }
  278. },
  279. {
  280. rule: "default",
  281. hostname: ["www.baidu.com", "zhidao.baidu.com"],
  282. regexp: "",
  283. action: () => {
  284. let interval_id = setInterval( () => {
  285. const right_list_length = 5
  286. _$("#content_right", 'remove_all');
  287. var zhidao_body = _$("#body", "return_one");
  288. var container = _$("#container", "return_one");
  289. var head = _$("#head", "return_one");
  290. var pad = _$("#s_tab", "return_one");
  291. _$("#rs", "remove_all")
  292. var u = _$("#u", "return_one");
  293. container.style.cssText = "display:block;width:100%;position:relative;"
  294. head && (() => {
  295. head.style.position = 'relative';
  296. head.style.width = window.innerWidth - 100 + 'px';
  297. head.style['min-width'] = 0;
  298. })();
  299. pad && (() => {
  300. pad.style.padding = '0 0 0 121px'
  301. })();
  302. u && (() => {
  303. u.style.display = 'none'
  304. })();
  305. zhidao_body && (() => {
  306. zhidao_body.style.left = "50px"
  307. })();
  308.  
  309. let origin_length = document.getElementById("content_left").children.length
  310.  
  311. if (origin_length > 6) {
  312. // console.log(content_list)
  313. let right_list = Array.prototype.slice.call(_$(".result", "return_all"),-1 - right_list_length, -1)
  314. let container_r = document.createElement("div")
  315. container_r.style.cssText += "display:block;position:absolute;top:40px;left:740px;width:600px;"
  316. // let str = Array.prototype.reduce.call(right_list, (html_str, item ,index , right_list) => (item.innerHTML + html_str), '')
  317. Array.prototype.forEach.call(right_list, item => {
  318. item.style.cssText += "padding:10px 0;"
  319. container_r.appendChild(item)
  320. })
  321. let container_r_dom = container.appendChild(container_r)
  322. let page_indic = _$("#page", "return_one")
  323. page_indic.style.cssText = "position:absolute;top:0px;left:660px;margin:-60px 0 0 0;z-index:300"
  324. }
  325.  
  326. },300)
  327. }
  328. },
  329. {
  330. rule: "default",
  331. hostname: ["i.taobao.com", "trade.taobao.com", "rate.taobao.com", "buyertrade.taobao.com"],
  332. regexp: "",
  333. action: () => {
  334. _$(".m-guess-you-like", "remove_one");
  335. _$(".m-someone-like-you", 'remove_one');
  336. _$("#p4p_ad", 'remove_one');
  337. _$(".J_guess-you-like", 'remove_one');
  338. }
  339. },
  340. {
  341. rule: "default",
  342. hostname: ["www.cnblogs.com", "blog.csdn.net"],
  343. regexp: "",
  344. action: () => {
  345. _$('.btn-close', 'return_one').click();
  346. _$('#btn-readmore', 'return_one').click();
  347. _$('.recommend-box', 'remove_one')
  348. let main = _$('main', 'return_one')
  349. document.body.style.backgroundImage = 'none';
  350. document.body.style.color = '#fff'
  351. document.body.innerHTML = ''
  352. // document.body.style.cssText = 'background-image: "none" ;'
  353. document.body.appendChild(main)
  354. main.style.cssText = 'width: 900px; float: left; margin: 0 auto 0 120px;'
  355.  
  356. console.log('dasdasda is ', _$('p', 'return_all'))
  357. Array.from(_$('p', 'return_all')).forEach(e => e.style.color = '#fff')
  358.  
  359. /*
  360. setTimeout(() => {
  361. _$('aside', 'remove_one')
  362. _$(".adblock", "remove_one");
  363. },2000)
  364.  
  365. var content = _$("#content", "return_one");
  366. _$("#sidebar", "remove_one");
  367. _$("#side", 'remove_one');
  368.  
  369. content && (() => {
  370. content.style["margin-right"] = "10";
  371. content.style.width = window.innerWidth - 100 + 'px';
  372. })();
  373.  
  374. let article = _$("#article_content", "return_one");
  375. article && (() => {
  376. article.style.height = "100%";
  377. article.style.overflow = "visible";
  378. })()
  379. _$(".recommend-item-box", "remove_all");
  380. _$(".hide-article-box", "remove_one");
  381. _$("aside", "remove_one");
  382. let main = _$("main", "return_one")
  383. if (main) main.style.float = "left";
  384. setTimeout(() => {
  385. _$(".adblock", "remove_one");
  386. },
  387. 3000)
  388. _$(".pulllog-box", "remove_one");
  389. */
  390. }
  391. },
  392. {
  393. rule: "default",
  394. hostname: "www.w3school.com.cn",
  395. regexp: "",
  396. action: () => {
  397. _$("#navsecond", 'hide_one');
  398. }
  399. },
  400. {
  401. rule: "default",
  402. hostname: "wallstreetcn.com",
  403. regexp: "",
  404. action: () => {
  405. setInterval(() => {
  406. _$('.news-item__cover', 'remove_all');
  407. _$('.qn-img', 'remove_all');
  408. // console.log(new Date() - 0)
  409. change_style();
  410. },
  411. 500);
  412.  
  413. let main = _$('main', 'return_one');
  414. document.body.innerHTML = '';
  415. document.body.appendChild(main);
  416.  
  417. _$('.left-bar', 'remove_one');
  418. }
  419. },
  420. {
  421. rule: "default",
  422. hostname: "www.merriam-webster.com",
  423. regexp: "",
  424. action: () => {
  425. _$(".right-rail", 'hide_one');
  426. _$("#recirc-bar-footer", 'hide_one');
  427. _$(".wgt-related-to.jc-card-box.clearfix", 'hide_one');
  428. }
  429. },
  430. {
  431. rule: "default",
  432. hostname: "blog.sina.com.cn",
  433. regexp: "",
  434. action: () => {
  435. _$("#column_1", 'hide_one');
  436. }
  437. },
  438. {
  439. rule: "default",
  440. hostname: ["blog.jobbole.com", "web.jobbole.com"],
  441. regexp: "",
  442. action: () => {
  443. _$("#sidebar", 'hide_one');
  444. var grid = _$(".grid-8", 'return_one');
  445. grid && (() => {
  446. grid.style.width = "100%"
  447. })();
  448. }
  449. },
  450. {
  451. rule: "default",
  452. hostname: "juejin.im",
  453. regexp: "",
  454. action: () => {
  455. var interval_id = setInterval(() => {
  456. var a = _$(".show-full", 'return_one');
  457. var b = _$(".show-full-block", 'return_one');
  458. _$(".show-full-btn", 'remove_one');
  459. _$('.columen-view-aside', 'hide_one');
  460.  
  461. if (a) a.style.height = "auto";
  462. a && a.setAttribute('style', 'height:auto')
  463. if (b) {
  464. clearInterval(interval_id);
  465. b.setAttribute('style', 'height:auto')
  466. }
  467. },
  468. 100);
  469. setInterval(change_style, 300)
  470. }
  471. },
  472. {
  473. rule: "default",
  474. hostname: "www.cnblogs.com",
  475. regexp: "",
  476. action: () => {
  477. _$("#sideBar", 'hide_one');
  478. _$("#vid", 'hide_one');
  479. _$("#left", 'hide_one');
  480. _$("#right_content", 'hide_one');
  481. _$("#leftcontent", 'hide_one');
  482. var a = _$("#centercontent", 'return_one');
  483. if (a) {
  484. a.style['padding-left'] = 0;
  485. }
  486. }
  487. },
  488. {
  489. rule: "default",
  490. hostname: "github.com",
  491. regexp: "",
  492. action: () => {
  493. document.body.style.minWidth = '100px';
  494. var github_pad = document.querySelector('.column.three-fourths.codesearch-results.pr-6');
  495. if (github_pad) {
  496. github_pad.style.padding = '10px 0 10px 30px';
  497. }
  498. }
  499. },
  500. {
  501. rule: "default",
  502. hostname: "wiki.jikexueyuan.com",
  503. regexp: "",
  504. action: () => {
  505. _$(".detail-left", 'hide_one');
  506. var a = _$(".detail-main", 'no_option', 'one');
  507. a.style['margin-left'] = '0px';
  508. a.style.width = document.body.clientWidth + 'px';
  509. }
  510. },
  511. {
  512. rule: "default",
  513. hostname: "www.cssmoban.com",
  514. regexp: "",
  515. action: () => {
  516. var a = _$(".wide-main.col-media-main.clearfix", 'return_one');
  517. a.style.width = document.body.clientWidth + 'px';
  518. }
  519. },
  520. {
  521. rule: "default",
  522. hostname: "www.kancloud.cn",
  523. regexp: "",
  524. action: () => {
  525. var interval_id = setInterval(() => {
  526. var a = _$(".sidebar", 'return_one');
  527. if (a) {
  528. _$(".workspace", 'return_one').style.left = "180px";
  529. a.style.width = '180px';
  530. change_style(a);
  531. clearInterval(interval_id);
  532. }
  533. },
  534. 100);
  535. }
  536. },
  537. {
  538. rule: "default",
  539. hostname: "php.net",
  540. regexp: "",
  541. action: () => {
  542. _$('.layout-menu', 'remove_one');
  543. if (_$(".sect1", 'return_one')) _$(".sect1", 'return_one').style.width = document.body.clientWidth - 50 + "px";
  544. if (_$("#usernotes", 'return_one')) _$("#usernotes", 'return_one').style.width = document.body.clientWidth - 50 + "px";
  545. }
  546. },
  547. {
  548. rule: "default",
  549. hostname: "www.zhihu.com",
  550. regexp: "",
  551. action: () => {
  552. _$('.Question-sideColumn.Question-sideColumn--sticky', 'remove_one');
  553. _$('.AdblockBanner-inner', 'remove_one');
  554. _$('.QuestionHeader-side', 'remove_all');
  555. _$('.AppHeader-userInfo', 'remove_all');
  556.  
  557. var browser_width = document.body.clientWidth - 50 + "px";
  558. _$('.QuestionHeader-content', 'return_one').style.width = browser_width;
  559.  
  560. setInterval(() => {
  561. _$('.HitQrcode', 'remove_one');
  562. },
  563. 100);
  564. }
  565. },
  566. {
  567. rule: "default",
  568. hostname: "www.letscorp.net",
  569. regexp: "",
  570. action: () => {
  571. _$('#commentlist', 'remove_one');
  572. _$('#sidebar', 'remove_one');
  573. _$('#header', 'remove_one');
  574.  
  575. var browser_width = document.body.clientWidth - 50 + "px";
  576. _$('#container', 'return_one').style.width = browser_width;
  577. _$('#main', 'return_one').style.height = "auto";
  578. var p_ele = _$('p', 'return_all');
  579. Array.prototype.forEach.call(p_ele,
  580. function(e) {
  581. e.style["font-size"] = "16px";
  582. });
  583. }
  584. },
  585. {
  586. rule: "default",
  587. hostname: "segmentfault.com",
  588. regexp: "",
  589. action: () => {
  590. _$("#loginBanner", "remove_one");
  591. }
  592. },
  593. {
  594. rule: "default",
  595. hostname: "huziketang.mangojuice.top",
  596. regexp: "",
  597. action: () => {
  598. for (var i = 0; i < 10000; i++) {
  599. clearInterval(i);
  600. }-
  601. _$("div", "return_all").forEach(function(ele) {
  602. if (ele.id && ele.id !== "wrapper" && ele.id !== "uyan_frame" && ele.id !== "donate-mask") {
  603. ele.parentNode.removeChild(ele);
  604. }
  605. });
  606. }
  607. },
  608. {
  609. rule: "default",
  610. hostname: "lvv2.com",
  611. regexp: "",
  612. action: () => {
  613. if (_$(".link.show", "return_all")) {
  614. _$(".link.show", "return_all").forEach(function(ele) {
  615. if (ele.querySelector('a.title')) {
  616. // console.log(ele.querySelector('a.title').innerHTML)
  617. ele.querySelector('a.title').style.fontSize = '16px'
  618. var title = ele.querySelector('a.title').innerHTML
  619. var porn_list = ['日', '勾引', '野外', '肏', '抽插', '公厕', '舔', '茎', '肛', '奴', '约炮', '母狗', '调教', '草', '鸡巴', '小受', '口爆', '野战', 'SM', 'sm', '贱货', '被虐', '淫', '内裤', '屁眼', '蕾丝', '姿势', '体位', '色情', '骚', '屌', '淫荡', '射', '艹', '丝袜', '情色', '调情', '做爱', '操', '捆绑', '挑逗', '绿帽', '潮喷', '援交', 'jj', 'JJ', '潮吹', '3p', '3P', '腰', '臀', '肉棒', '啪啪', '圣水']
  620. var politic_list = ['中共', '土共', '民主', '法治', '天安门', '老兵', '自由', '殴打', '近平', '奴隶', '道德', '强拆', '法律', '监狱', '城管', '土匪', '毛腊肉', '老毛', '专制', '社会主义', '党中央', '统治', '酷刑', '党员', '人民', '民族', 'P2P', '普京', '英雄', '纳税', '维权', '执法', '警察', '独裁', '政府', '郭文贵', '文革', '武装', '共产', '垬', '毛泽东', '政权', '枪', '举报', '恐怖', '宗教', '卖国', '死', '软禁']
  621. var key_word_list = porn_list.concat(politic_list)
  622. var porn_detection = key_word_list.some(function(ele) {
  623. return title.indexOf(ele) > -1
  624. })
  625. porn_detection && ele.parentNode.removeChild(ele)
  626. // ele.parentNode.removeChild(ele);
  627. }
  628. });
  629. }
  630. }
  631. },
  632. {
  633. rule: "default",
  634. hostname: "jandan.net",
  635. regexp: "",
  636. action: () => {
  637. // html 调色
  638. let _html = _$('html', 'return_one')
  639. let _body = _$('body', 'return_one')
  640. _html.style.backgroundColor = '#333'
  641. _body.style.backgroundColor = '#333'
  642. // 去掉某些ID的发图
  643. let title_list = document.querySelectorAll("[title^=防伪码]")
  644. let block_user_list = ["42c968079f1cc3495692a053f432e105142a3142"]
  645. Array.prototype.forEach.call(title_list, (titleDOM) => {
  646. let author_id = titleDOM.title.replace(/[\u4e00-\u9fa5]{3}:/, '') // 装B正则
  647. if (block_user_list.includes(author_id)) {
  648. let remove_div = titleDOM.parentNode.parentNode.parentNode.parentNode
  649. remove_div.parentNode.removeChild(remove_div)
  650. }
  651. })
  652. }
  653. },
  654. {
  655. rule: "default",
  656. hostname: "www.sogou.com",
  657. regexp: "",
  658. action: () => {
  659. // html 调色
  660. console.log('sdasdasda')
  661. let id;
  662. id = setInterval(() => {
  663. let right = _$("#right", "return_one");
  664. if (right) {
  665. _$("#right", "remove_one");
  666. clearInterval(id)
  667. }
  668. }, 300);
  669. }
  670. },
  671. {
  672. rule: "default",
  673. hostname: "10.0.74.227",
  674. regexp: "",
  675. action: () => {
  676. setTimeout( _ => {
  677. let title_list = document.querySelectorAll(".opblock-tag")
  678. Array.prototype.forEach.call(title_list, (titleDOM) => {
  679. titleDOM.click()
  680. })
  681. }, 10 * 1000)
  682. }
  683. },
  684. ]
  685.  
  686.  
  687. let matched_rule = rules.filter( rule_item => rule_item.hostname instanceof Array
  688. ? rule_item.hostname.includes(hostname)
  689. : rule_item.hostname === hostname
  690. )[0]
  691.  
  692. return matched_rule
  693. }
  694.  
  695. //window.frames
  696. //Array.prototype.slice.call(ele)
  697.  
  698. function sleep(ms = 1500) {
  699. return new Promise(resolve => setTimeout(_ => resolve(), ~~ms))
  700. }
  701.  
  702. //寻找页面的主要内容
  703. function main_ele_searcher() {
  704. let article = document.getElementsByTagName('article')
  705. let main = document.getElementsByTagName('main')
  706. let content = (article.length && article[0]) || (main.length && main[0]) || false
  707. if (content) {
  708. return {
  709. main_ele: content,
  710. body_width: content.style.width,
  711. body_height: content.style.height
  712. };
  713. }
  714.  
  715. var ele = document.querySelectorAll("*");
  716. var arr = [];
  717. //var arr_index = [];
  718. var w, h;
  719.  
  720. var body_width = document.body.clientWidth;
  721. var body_height = document.body.clientHeight;
  722.  
  723. if (!body_height) {
  724. var max_width = 0, max_height = 0;
  725. document.documentElement.style.height = '100%';
  726. document.body.style.height = '100%';
  727.  
  728. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  729. w = ele[i].clientWidth;
  730. h = ele[i].clientHeight;
  731. if (w > max_width) { max_width = w; }
  732. if (h > max_height) { max_height = h; }
  733. w = null;
  734. h = null;
  735. }
  736. body_width = max_width;
  737. body_height = max_height;
  738. }
  739.  
  740.  
  741. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  742. w = ele[i].clientWidth;
  743. h = ele[i].clientHeight;
  744. //console.log(h);
  745.  
  746. if (w && h && w > body_width / 2 && h > body_height / 5 && w < body_width && h < body_height) {
  747. arr[w * h] = ele[i];
  748. //console.log(ele[i]);
  749. //arr_index.push(w * h);
  750. }
  751. w = null;
  752. h = null;
  753. }
  754. var main_ele = arr[arr.length - 1] || document.body;
  755. return {
  756. main_ele,
  757. body_width,
  758. body_height
  759. };
  760. }
  761.  
  762.  
  763. function content_purge() {
  764. let article = document.getElementsByTagName('article')
  765. let main = document.getElementsByTagName('main')
  766. let content = (article.length && article[0]) || (main.length && main[0]) || false;
  767. if (content) {
  768. main.style.cssText = 'width: 900px;margin: 40px 0 0 120px;float: left; ';
  769. document.body.innerHTML = '';
  770. document.body.appendChild(main);
  771. }
  772.  
  773. // main.parentNode.removeChild(main)
  774. // Array.from(document.body.children)
  775. // document.body.insertBefore(main, document.body.firstChild);
  776.  
  777. }
  778.  
  779. //去除侧边栏这样“狭长”的内容
  780. function ele_remover(obj) {
  781. var w, h;
  782. var { main_ele, body_width, body_height } = obj;
  783. var ele = document.querySelectorAll("*");
  784. //console.log(main_ele,body_width, body_height )
  785. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  786. w = ele[i].clientWidth;
  787. h = ele[i].clientHeight;
  788. // main_ele.parentNode.children
  789. 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) {
  790. //content_adjust(ele[i]);
  791. console.log("---------element removed ------------");
  792. console.log(ele[i]);
  793. console.log("---------element removed ------------");
  794.  
  795. ele[i].parentNode.removeChild(ele[i]);
  796. }
  797. w = null;
  798. h = null;
  799. }
  800. }
  801.  
  802. //去除被移除元素的兄弟元素的padding margin
  803. function content_adjust(ele) {
  804. var siblings = ele.parentNode.children;
  805. ele.parentNode.style.position = "relative";
  806. // console.log(ele);
  807. for (let i = 0, ele_length = siblings.length; i < ele_length; i++) {
  808. //console.log(siblings[i]);
  809. siblings[i].setAttribute('style', 'position:relative;padding:20px;margin:0px;overflow:visible;');
  810. }
  811. }
  812.  
  813.  
  814. //调整主要内容的样式
  815. function main_content_adjust(main_ele) {
  816. //var a = [{x,y,top,right,bottom,left,width}]=main_ele.getClientRects();
  817. main_ele.parentNode.style.position = "relative";
  818. main_ele.style.cssText = "position:absolute; top:0;right:0; bottom:0;left:0;"
  819. // main_ele.setAttribute('style','position:relative;padding:20px 20px 20px 40px;margin:auto;clear:both;overflow:visible;');
  820. var ratio = 0.9 * (window.innerWidth) / main_ele.clientWidth;
  821. var ele = main_ele.querySelectorAll('*');
  822. // console.log(ele);
  823. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  824. ele[i].style.width = ele[i].clientWidth * ratio + "px";
  825. ele[i].style.overflow = 'visible';
  826. //console.log(i);
  827. }
  828.  
  829. }
  830.  
  831.  
  832.  
  833. // body 全屏
  834. function full_body() {
  835. let root = document.body
  836. root.style.cssText = "position:absolute; top:0;right:0; bottom:0;left:0;"
  837.  
  838. }
  839. //背景调色
  840. function change_style(DOM_node = document.body) {
  841. return
  842. // 执行速度 : for 循环 > forEach > 尾递归 >递归 (迭代)
  843. let background_base_color = 50;
  844. let background_offset = 20;
  845. let font_base_color = 230;
  846. let font_offset = 20;
  847. var all = (DOM_node || document).querySelectorAll('*');
  848. for (let i = 0, ele_length = all.length; i < ele_length; i++) {
  849. let item = all[i]
  850. let item_style = item.style
  851. let tag_exclude_check = !('script,style,img').includes(item.nodeName.toLowerCase())
  852. if(tag_exclude_check && !item_style.backgroundColor){
  853. item_style.backgroundColor = random_color(background_base_color,background_offset);
  854. item_style.color = random_color(font_base_color,font_offset);
  855. }
  856. }
  857. /*
  858. let background_base_color = 40;
  859. let background_offset = 20;
  860. let font_base_color = 200;
  861. let font_offset = 50;
  862. let html_str = DOM_node.innerHTML ;
  863. // 匹配速度 string.indexOf > string.match
  864. // let html_str = DOM_node.innerHTML.replace(/\&/g,'') ;
  865. // var all = (new DOMParser()).parseFromString(html_str, "text/xml");
  866. let html_str_arr = html_str.split(">");
  867. let new_html_str_arr = html_str_arr.map((item, index) => {
  868. if(item.indexOf('</') > 0) {return item }
  869. if(!item.match(/\<div|\<form|\<table|\<dl|\<ol|\<ul|\<pre|\<h|\<a|\<p|\<code|\<em|\<span|\<td|\<th|\<input|\<textarea/i)) {return item }
  870. let font_color_str = ";color:"+random_color(font_base_color,font_offset);
  871. if(item.indexOf('background-color') > 0) {
  872. let reg = /background-color\s*\:\s*[\w\,\(\)\#]+/;
  873. let str = 'background-color:' + random_color(background_base_color,background_offset) + font_color_str;
  874. return item.replace(reg, str)
  875. }
  876. if(item.indexOf('background') > 0) {
  877. let reg = /\#[^\s]+|rgb[^\)]+\)/;
  878. let str = random_color(background_base_color,background_offset);
  879. return item.replace(reg, str).replace(/(style=(["'])[^'"]+)\2/,"$1" + font_color_str + "$2")
  880. }
  881. return `${item} style="background-color:${random_color(background_base_color,background_offset)}${font_color_str}"`;
  882. })
  883.  
  884. DOM_node.innerHTML = new_html_str_arr.join(">")
  885. DOM_node.style.backgroundColor = random_color(background_base_color,background_offset);
  886. */
  887. }
  888.  
  889. function random_color(base_color, offset, ratio=1){
  890. base_color = (base_color & 255) === (~~base_color) ? ~~base_color : 255;
  891. offset = ~~offset
  892. offset = (base_color+offset > 0 && base_color+offset < 256)? offset : 0
  893. return `rgba(${(base_color + offset*Math.random())&255},${(base_color + offset*Math.random())&255},${(base_color + offset*Math.random())&255},0.8)`;
  894. }
  895.  
  896.  
  897. function ele_hide(e) {
  898. // if (document.body.hasChildNodes(e)) e.style.display = "none";
  899. document.body.hasChildNodes(e) && e.length !== 0 && e.style.setAttribute('display', "none");
  900. }
  901. function ele_hide_all(all) {
  902. Array.prototype.forEach.call(all, function (e) { e.style.display = "none"; });
  903. }
  904. function ele_remove(e) {
  905. // if (document.body.hasChildNodes(e)) e.parentNode.removeChild(e);
  906. e = e.length ? e[0] : e
  907. document.body.hasChildNodes(e) && e.length !== 0 && e.parentNode.removeChild(e);
  908. }
  909. function ele_remove_all(all) {
  910. if (all) {
  911. all = Array.from(all)
  912. }
  913. if (!all.length) {
  914. return
  915. }
  916. Array.prototype.forEach.call(all, function (e) {
  917. e instanceof Object && e.parentNode.removeChild(e);
  918. });
  919. }
  920.  
  921.  
  922. function _$(selector, operation_code) {
  923. // operation_code : return_one return_all remove_one remove_all hide_one hide_all
  924. function get(selector) {
  925. if((/^#[^.#]+$/).test(selector)) {
  926. return [document.getElementById(selector.slice(1, selector.length))]
  927. }
  928. if((/^\.[^.#]+$/).test(selector)) {
  929. return document.getElementsByClassName(selector.slice(1, selector.length))
  930. }
  931. if((/^[^.#\[\]=]+$/).test(selector)) {
  932. return document.getElementsByTagName(selector)
  933. }
  934. return document.querySelectorAll(selector)
  935. }
  936. switch (operation_code) {
  937. case 'return_one': //return_one
  938. // return document.querySelector(selector);
  939. return get(selector)[0];
  940. case 'return_all':// return_all
  941. // return document.querySelectorAll(selector);
  942. return get(selector);
  943. case 'remove_one': //remove_one
  944. // ele_remove(document.querySelector(selector));
  945. ele_remove(get(selector));
  946. break;
  947. case 'remove_all': //remove_all
  948. // ele_remove_all(document.querySelectorAll(selector));
  949. ele_remove_all(get(selector));
  950. break;
  951. case 'hide_one': //hide_one
  952. // ele_hide(document.querySelector(selector));
  953. ele_hide(get(selector));
  954. break;
  955. case 'hide_all':// hide_all
  956. // ele_hide_all(document.querySelectorAll(selector));
  957. ele_hide_all(get(selector));
  958. break;
  959.  
  960. default:
  961. // var result = document.querySelectorAll(selector);
  962. var result = get(selector);
  963. return result.length > 1 ? result : result[0];
  964. }
  965. }
  966.  
  967. function _CSS(DOM_ele, pseudo_class) {
  968. return pseudo_class ? window.getComputedStyle(DOM_ele, pseudo_class) : window.getComputedStyle(DOM_ele)
  969. }
  970.  
  971. function revert_color(color) {
  972. const [red, blue, green, alpha] = color.match(/\d{1,3}/g);
  973. return Number(alpha) ? `rgba(${255 - red}, ${255 - blue}, ${255 - green}, ${alpha})` : `rgb(${255 - red}, ${255 - blue}, ${255 - green})`;
  974. }
  975.  
  976. function remove_div_padding_margin(ele) {
  977. if (ele) {
  978. ele.setAttribute('style', 'overflow:visible;position:relative;padding:0px;margin:0px;left:0px;');
  979. }
  980. if (ele && ele.children.length > 0) {
  981. Array.prototype.forEach.call(ele.children, (function (e) {
  982. remove_div_padding_margin(e);
  983. }));
  984. }
  985. }
  986.  
  987.  
  988. function getFormatDate(date) {
  989. let year = new Date(date).getFullYear()
  990. let month = new Date(date).getMonth() + 1
  991. let day = new Date(date).getDate()
  992. month = month < 10 ? '0' + month : month
  993. day = day < 10 ? '0' + day : day
  994. return [year, month, day].join('-')
  995. }
  996.  
  997. function postData(url, data) {
  998. const opts = {
  999. method: 'POST', // 请求方法
  1000. body: JSON.stringify(data), // 请求体
  1001. headers: {
  1002. accept: 'application/json',
  1003. 'content-type': 'application/json'
  1004. },
  1005. mode: 'cors'
  1006. }
  1007. return fetch(url, opts)
  1008. .then(response => {
  1009. return response.json()
  1010. })
  1011. .then(resp => {
  1012. return resp
  1013. // return Promise.reject(resp)
  1014. })
  1015. }
  1016.  
  1017. function content_get() {
  1018. var ajax = new XMLHttpRequest();
  1019. ajax.open('get', '/');
  1020. ajax.send();
  1021. ajax.onreadystatechange = function () {
  1022. if (ajax.readyState == 4 && ajax.status == 200) {
  1023. content_new = ajax.responseText;
  1024. //console.log(content_new);
  1025. content_old = content_old || content_new;
  1026. if (content_new !== content_old) {
  1027. location.reload();
  1028. }
  1029. }
  1030. };
  1031.  
  1032. setTimeout(content_get, 1000);
  1033. }