Allen's Magic

Allen's magic casting to internet

目前为 2020-05-25 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Allen's Magic
  3. // @namespace https://tampermonkey.net/
  4. // @version 4.0.2
  5. // @description Allen's magic casting to internet
  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.  
  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.  
  40. // content_purge(main_ele)
  41.  
  42. console.timeEnd("allen_web_time_count");
  43. } catch(err) {
  44. //console.log(err.name,' ',err.message);
  45. console.log(err.message);
  46. }
  47. }
  48.  
  49. // white list check
  50. function exclude_check(hostname_param) {
  51. // 不执行脚本的网站白名单
  52. let exclude_list = [
  53. "www.youtube.com",
  54. "demo.mycodes.net",
  55. "kiwivm.64clouds.com",
  56. "www.instagram.com",
  57. "www.h-ui.net",
  58. "www.layui.com",
  59. "www.kixeye.com",
  60. "pan.baidu.com",
  61. "www.rishiqing.com",
  62. "wx.qq.com",
  63. "mail.126.com",
  64. "twitter.com",
  65. "reactjs.org",
  66. "codepen.io",
  67. "free.modao.cc",
  68. "lanhuapp.com",
  69. "developers.weixin.qq.com",
  70. // "jira.vankeservice.com",
  71. "www.tapd.cn",
  72. "modao.cc",
  73. "element-cn.eleme.io",
  74. "github.com",
  75. ""
  76. ]
  77. return exclude_list.includes(hostname_param)
  78. }
  79.  
  80. // 自定义样式调整
  81. function customer_rule(hostname) {
  82. let rules = [
  83. {
  84. rule: "default",
  85. hostname: "ip",
  86. regexp: "",
  87. action: () => {}
  88. },
  89. {
  90. rule: "default",
  91. hostname: "ikkedu.com",
  92. regexp: "",
  93. action: async () => {
  94. // if (!parseQuery()['download']) {
  95. // return
  96. // }
  97. const TYPE = parseQuery()['type'] || 'default'
  98. // // use MutationObserver instead of waiting react-based-rending elments complete
  99. const MO = new MutationObserverClass({window: window})
  100.  
  101. if (['RA'].includes(TYPE)) {
  102. const RA_HOT = []
  103.  
  104. MO.start({
  105. // element: document.getElementById('app'),
  106. selector: '.essayText.dictionary-word',
  107. fn: async function (){
  108. await sleep(500)
  109. const title = _$('#topinfosTitle').innerText
  110. const id = _$('.tip-span.tip0').innerText
  111. const text = _$('.essayText.dictionary-word').innerText
  112. console.table({title, id, text})
  113. if (title && id && text) {
  114. RA_HOT.push({title, id, text})
  115. } else {
  116. alert(id)
  117. }
  118. const next_button = Array.from(document.querySelectorAll('.v-tooltip.v-tooltip--top button')).find(ele => ele.innerText == '下一题')
  119.  
  120. if (next_button) {
  121. next_button.click()
  122. } else {
  123. const handler = (acc, cur) => {
  124. return `${acc}\r\n\r\n${cur.id } ${cur.title}\r\n${cur.text}`
  125. }
  126. window.RA_HOT = RA_HOT
  127. // .reduce(handler, '')
  128. }
  129. }
  130. });
  131. }
  132.  
  133. if (['RL', 'SST'].includes(TYPE)) {
  134. MO.start({
  135. // element: document.getElementById('app'),
  136. selector: '.tip-span.tip0',
  137. fn: async function (ele){
  138. console.log('control_btn ele', ele)
  139. // const control_btn = document.querySelector('.control-btn')
  140. // console.log('control_btn ', control_btn)
  141. // control_btn && control_btn.click()
  142. await sleep(1000)
  143. const play_icon = document.querySelector('.play-ctr-btn .material-icons')
  144. console.log('play_icon ', play_icon)
  145. play_icon && play_icon.click()
  146. }
  147. });
  148. MO.start({
  149. // element: document.getElementById('app'),
  150. selector: '.v-snack__content',
  151. fn: async function (ele){
  152. console.log('v-snack__content ele', ele)
  153. const next_button = Array.from(document.querySelectorAll('.v-tooltip.v-tooltip--top button')).find(ele => ele.innerText == '下一题')
  154. ele && next_button && next_button.click()
  155. }
  156. });
  157. MO.start({
  158. // element: document.getElementById('app'),
  159. selector: '.waveform audio',
  160. fn: async function (){
  161. const audio_mp3 = document.querySelector('.waveform audio')
  162. console.log('audio_mp3', audio_mp3)
  163. if (audio_mp3) {
  164. audio_mp3.preload = 'none'
  165. // console.log('audio_mp3', audio_mp3)
  166. const RS_mp3_id = document.querySelector('.tip-span.tip0').innerText
  167. // console.log('RS_mp3_id', RS_mp3_id)
  168. const src = audio_mp3.src
  169. downloadFile({ filePath: src, fileName: RS_mp3_id})
  170. await sleep(4 * 1000)
  171. }
  172. const next_button = Array.from(document.querySelectorAll('.v-tooltip.v-tooltip--top button')).find(ele => ele.innerText == '下一题')
  173. next_button && next_button.click()
  174. }
  175. });
  176. }
  177.  
  178. (['RS', 'ASQ'].includes(TYPE)) && MO.start({
  179. // element: document.getElementById('app'),
  180. selector: '.waveform audio',
  181. fn: async function (){
  182. const audio_mp3 = document.querySelector('.waveform audio')
  183. console.log('audio_mp3', audio_mp3)
  184. if (audio_mp3) {
  185. audio_mp3.preload = 'none'
  186. // console.log('audio_mp3', audio_mp3)
  187. const RS_mp3_id = document.querySelector('.tip-span.tip0').innerText
  188. // console.log('RS_mp3_id', RS_mp3_id)
  189. const src = audio_mp3.src
  190. downloadFile({ filePath: src, fileName: RS_mp3_id})
  191. await sleep(1000)
  192. }
  193. const next_button = Array.from(document.querySelectorAll('.v-tooltip.v-tooltip--top button')).find(ele => ele.innerText == '下一题')
  194. next_button && next_button.click()
  195. }
  196. });
  197.  
  198. let interval_id = setInterval(() => {
  199. if (window.frames.length) {
  200. // window.frames[0].style.display = 'none'
  201. document.getElementsByTagName('iframe')[0].style.display = 'none'
  202. // clearInterval(interval_id)
  203. }
  204. }, 500)
  205. }
  206. },
  207. {
  208. rule: "default",
  209. hostname: "jira.vankeservice.com",
  210. regexp: "",
  211. action: () => {
  212. if (window.location.href !== 'http://jira.vankeservice.com/browse/COST-677') {
  213. // if (window.location.href !== 'http://jira.vankeservice.com/browse/COST-863') {
  214. console.log('不是项目页,不能填工时')
  215. return
  216. }
  217. // await sleep(3000)
  218. console.clear()
  219. async function log_time() {
  220. try {
  221. const workInfoRes = await getData('http://jira.vankeservice.com/rest/tempo-time-activities/1/issue/42572/?page=1&size=5&activityType=all&currentUser=true')
  222. console.log('getData res', workInfoRes)
  223. const {activities = []} = workInfoRes || {}
  224. const time_list = activities.map(e => e.dateTime.slice(0, 10))
  225. const now = new Date()
  226. const time_now_string = `${now.getFullYear()}-${('0' + (now.getMonth() + 1)).slice(-2)}-${now.getDate()}`
  227. const today_not_log = !time_list.includes(time_now_string)
  228. const today_should_log = isWorkDay()
  229. const can_log_work_time = today_should_log && today_not_log
  230. if (can_log_work_time){
  231. const begin_time = `${getFormatDate(Date.now())}T09:00:27.792`
  232. const data = {
  233. attributes: {},
  234. billableSeconds: '',
  235. worker: 'xiecy08',
  236. comment: '修复客户端新增施工项目的UI及交互问题',
  237. started: begin_time,
  238. timeSpentSeconds: 28800,
  239. originTaskId: '42572',
  240. remainingEstimate: 0,
  241. endDate: null,
  242. includeNonWorkingDays: false
  243. }
  244. postData('http://jira.vankeservice.com/rest/tempo-timesheets/4/worklogs/', data)
  245. setTimeout(() => {
  246. window.location.href = window.location.href
  247. }, 3 * 1000)
  248. /*
  249. console.log('button', _$_('[name=logTimeBtn]', "return_one"))
  250. const begin_time = `${getFormatDate(Date.now())}T09:00:27.792`
  251. const end_time = `${getFormatDate(Date.now())}T11:00:27.792`
  252. const data = {
  253. "attributes":{},
  254. "billableSeconds":"",
  255. "worker":"xiecy08",
  256. "comment":"编写代码",
  257. "started":begin_time,
  258. "timeSpentSeconds":28800,
  259. "originTaskId":"43581",
  260. "remainingEstimate":0,
  261. "endDate":end_time
  262. }
  263. */
  264. return true
  265. }
  266. return false
  267. } catch (e) {
  268. window.location.href = window.location.href
  269. }
  270. }
  271. log_time()
  272. window.intervalId = setInterval(log_time, 1 * 3600 * 1000)
  273. }
  274. },
  275. {
  276. rule: "default",
  277. hostname: "wc-kx-vip.sjc.kixeye.com",
  278. regexp: "",
  279. action: () => {
  280. _$_('#above-game-message', 'remove_one');
  281. _$_('#kxp-footer-bar', 'remove_one');
  282. _$_('#topnavbar_back', 'remove_one');
  283. }
  284. },
  285. {
  286. rule: "default",
  287. hostname: ["www.baidu.com", "zhidao.baidu.com"],
  288. regexp: "",
  289. action: () => {
  290. let interval_id = setInterval( () => {
  291. const right_list_length = 5
  292. _$_("#content_right", 'remove_all');
  293. var zhidao_body = _$_("#body", "return_one");
  294. var container = _$_("#container", "return_one");
  295. var head = _$_("#head", "return_one");
  296. var pad = _$_("#s_tab", "return_one");
  297. _$_("#rs", "remove_all")
  298. var u = _$_("#u", "return_one");
  299. container.style.cssText = "display:block;width:100%;position:relative;"
  300. head && (() => {
  301. head.style.position = 'relative';
  302. head.style.width = window.innerWidth - 100 + 'px';
  303. head.style['min-width'] = 0;
  304. })();
  305. pad && (() => {
  306. pad.style.padding = '0 0 0 121px'
  307. })();
  308. u && (() => {
  309. u.style.display = 'none'
  310. })();
  311. zhidao_body && (() => {
  312. zhidao_body.style.left = "50px"
  313. })();
  314.  
  315. let origin_length = document.getElementById("content_left").children.length
  316.  
  317. if (origin_length > 6) {
  318. // console.log(content_list)
  319. let right_list = Array.prototype.slice.call(_$_(".result", "return_all"),-1 - right_list_length, -1)
  320. let container_r = document.createElement("div")
  321. container_r.style.cssText += "display:block;position:absolute;top:40px;left:740px;width:600px;"
  322. // let str = Array.prototype.reduce.call(right_list, (html_str, item ,index , right_list) => (item.innerHTML + html_str), '')
  323. Array.prototype.forEach.call(right_list, item => {
  324. item.style.cssText += "padding:10px 0;"
  325. container_r.appendChild(item)
  326. })
  327. let container_r_dom = container.appendChild(container_r)
  328. let page_indic = _$_("#page", "return_one")
  329. page_indic.style.cssText = "position:absolute;top:0px;left:660px;margin:-60px 0 0 0;z-index:300"
  330. }
  331.  
  332. },300)
  333. }
  334. },
  335. {
  336. rule: "default",
  337. hostname: ["i.taobao.com", "trade.taobao.com", "rate.taobao.com", "buyertrade.taobao.com"],
  338. regexp: "",
  339. action: () => {
  340. _$_(".m-guess-you-like", "remove_one");
  341. _$_(".m-someone-like-you", 'remove_one');
  342. _$_("#p4p_ad", 'remove_one');
  343. _$_(".J_guess-you-like", 'remove_one');
  344. }
  345. },
  346. {
  347. rule: "default",
  348. hostname: "login.m.taobao.com",
  349. regexp: "",
  350. action: () => {
  351. setInterval(() => {
  352. document.querySelector('button[type=submit]').click()
  353. }, 1 * 1000)
  354. }
  355. },
  356. {
  357. rule: "default",
  358. hostname: "main.m.taobao.com",
  359. regexp: "",
  360. action: () => {
  361. autoRefresh(5)
  362. }
  363. },
  364. {
  365. rule: "default",
  366. hostname: "h5.m.taobao.com",
  367. regexp: "",
  368. action: () => {
  369. console.log(1)
  370. const path = window.location.pathname
  371. if (path === "/trip/rx-flight-onsale/listing/index.html") {
  372. setTimeout(() => {
  373. window.location.href = window.location.href
  374. }, 5 * 60 * 60 * 1000)
  375. setTimeout(() => {
  376. var btn = Array.from(_$_('span','return_all')).filter(e => e.innerText == '搜索')[0].parentNode;
  377. console.log('btn', btn)
  378. var event = document.createEvent('Events');
  379. event.initEvent('tap', true, true);
  380. btn.dispatchEvent(event);
  381. }, 1000)
  382. }
  383. }
  384. },
  385. {
  386. rule: "default",
  387. hostname: "m.ctrip.com",
  388. regexp: "",
  389. action: () => {
  390.  
  391. window.setIntervalId = setInterval(() => {
  392. let Iknow = document.querySelector('.pop-button-ghost')
  393. if (Iknow) {
  394. Iknow.click()
  395. clearInterval(window.setIntervalId)
  396. }
  397. }, 1 * 1000)
  398. }
  399. },
  400. {
  401. rule: "default",
  402. hostname: "iot.asmiot.com",
  403. regexp: "",
  404. action: () => {
  405. autoRefresh(5)
  406. window.clickIntervalId = setInterval(() => {
  407. let btn = _$_('#znjc')[0]
  408. console.log(btn)
  409. if (btn) {
  410. btn.click()
  411. clearInterval(window.clickIntervalId)
  412. }
  413. },5000)
  414. }
  415. },
  416. {
  417. rule: "default",
  418. hostname: "mail.126.com",
  419. regexp: "",
  420. action: () => {
  421. autoRefresh(5)
  422. }
  423. },
  424. {
  425. rule: "default",
  426. hostname: ["www.cnblogs.com", "blog.csdn.net"],
  427. regexp: "",
  428. action: () => {
  429. _$_('.btn-close', 'return_one').click();
  430. _$_('#btn-readmore', 'return_one').click();
  431. _$_('.recommend-box', 'remove_one')
  432. let main = _$_('main', 'return_one')
  433. document.body.style.backgroundImage = 'none';
  434. document.body.style.color = '#fff'
  435. document.body.innerHTML = ''
  436. // document.body.style.cssText = 'background-image: "none" ;'
  437. document.body.appendChild(main)
  438. main.style.cssText = 'width: 900px; float: left; margin: 0 auto 0 120px;'
  439.  
  440. console.log('dasdasda is ', _$_('p', 'return_all'))
  441. Array.from(_$_('p', 'return_all')).forEach(e => e.style.color = '#fff')
  442.  
  443. /*
  444. setTimeout(() => {
  445. _$_('aside', 'remove_one')
  446. _$_(".adblock", "remove_one");
  447. },2000)
  448.  
  449. var content = _$_("#content", "return_one");
  450. _$_("#sidebar", "remove_one");
  451. _$_("#side", 'remove_one');
  452.  
  453. content && (() => {
  454. content.style["margin-right"] = "10";
  455. content.style.width = window.innerWidth - 100 + 'px';
  456. })();
  457.  
  458. let article = _$_("#article_content", "return_one");
  459. article && (() => {
  460. article.style.height = "100%";
  461. article.style.overflow = "visible";
  462. })()
  463. _$_(".recommend-item-box", "remove_all");
  464. _$_(".hide-article-box", "remove_one");
  465. _$_("aside", "remove_one");
  466. let main = _$_("main", "return_one")
  467. if (main) main.style.float = "left";
  468. setTimeout(() => {
  469. _$_(".adblock", "remove_one");
  470. },
  471. 3000)
  472. _$_(".pulllog-box", "remove_one");
  473. */
  474. }
  475. },
  476. {
  477. rule: "default",
  478. hostname: "www.xyzssr.xyz",
  479. regexp: "",
  480. action: () => {
  481. setTimeout(() => {
  482. let check = document.getElementById('checkin')
  483. console.log('check', check)
  484. if (check) {
  485. check.click()
  486. window.open('https://www.google.com')
  487. }
  488. // window.open("about:blank","_self").close()
  489.  
  490. }, 3000)
  491.  
  492.  
  493. }
  494. },
  495. {
  496. rule: "default",
  497. hostname: "www.w3school.com.cn",
  498. regexp: "",
  499. action: () => {
  500. _$_("#navsecond", 'hide_one');
  501. }
  502. },
  503. {
  504. rule: "default",
  505. hostname: "wallstreetcn.com",
  506. regexp: "",
  507. action: () => {
  508. setInterval(() => {
  509. _$_('.news-item__cover', 'remove_all');
  510. _$_('.qn-img', 'remove_all');
  511. // console.log(new Date() - 0)
  512. change_style();
  513. },
  514. 500);
  515.  
  516. let main = _$_('main', 'return_one');
  517. document.body.innerHTML = '';
  518. document.body.appendChild(main);
  519.  
  520. _$_('.left-bar', 'remove_one');
  521. }
  522. },
  523. {
  524. rule: "default",
  525. hostname: "www.merriam-webster.com",
  526. regexp: "",
  527. action: () => {
  528. _$_(".right-rail", 'hide_one');
  529. _$_("#recirc-bar-footer", 'hide_one');
  530. _$_(".wgt-related-to.jc-card-box.clearfix", 'hide_one');
  531. }
  532. },
  533. {
  534. rule: "default",
  535. hostname: "blog.sina.com.cn",
  536. regexp: "",
  537. action: () => {
  538. _$_("#column_1", 'hide_one');
  539. }
  540. },
  541. {
  542. rule: "default",
  543. hostname: ["blog.jobbole.com", "web.jobbole.com"],
  544. regexp: "",
  545. action: () => {
  546. _$_("#sidebar", 'hide_one');
  547. var grid = _$_(".grid-8", 'return_one');
  548. grid && (() => {
  549. grid.style.width = "100%"
  550. })();
  551. }
  552. },
  553. {
  554. rule: "default",
  555. hostname: "juejin.im",
  556. regexp: "",
  557. action: () => {
  558. var interval_id = setInterval(() => {
  559. var a = _$_(".show-full", 'return_one');
  560. var b = _$_(".show-full-block", 'return_one');
  561. _$_(".show-full-btn", 'remove_one');
  562. _$_('.columen-view-aside', 'hide_one');
  563.  
  564. if (a) a.style.height = "auto";
  565. a && a.setAttribute('style', 'height:auto')
  566. if (b) {
  567. clearInterval(interval_id);
  568. b.setAttribute('style', 'height:auto')
  569. }
  570. },
  571. 100);
  572. setInterval(change_style, 300)
  573. }
  574. },
  575. {
  576. rule: "default",
  577. hostname: "www.cnblogs.com",
  578. regexp: "",
  579. action: () => {
  580. _$_("#sideBar", 'hide_one');
  581. _$_("#vid", 'hide_one');
  582. _$_("#left", 'hide_one');
  583. _$_("#right_content", 'hide_one');
  584. _$_("#leftcontent", 'hide_one');
  585. var a = _$_("#centercontent", 'return_one');
  586. if (a) {
  587. a.style['padding-left'] = 0;
  588. }
  589. }
  590. },
  591. {
  592. rule: "default",
  593. hostname: "github.com",
  594. regexp: "",
  595. action: () => {
  596. document.body.style.minWidth = '100px';
  597. var github_pad = document.querySelector('.column.three-fourths.codesearch-results.pr-6');
  598. if (github_pad) {
  599. github_pad.style.padding = '10px 0 10px 30px';
  600. }
  601. }
  602. },
  603. {
  604. rule: "default",
  605. hostname: "wiki.jikexueyuan.com",
  606. regexp: "",
  607. action: () => {
  608. _$_(".detail-left", 'hide_one');
  609. var a = _$_(".detail-main", 'no_option', 'one');
  610. a.style['margin-left'] = '0px';
  611. a.style.width = document.body.clientWidth + 'px';
  612. }
  613. },
  614. {
  615. rule: "default",
  616. hostname: "www.cssmoban.com",
  617. regexp: "",
  618. action: () => {
  619. var a = _$_(".wide-main.col-media-main.clearfix", 'return_one');
  620. a.style.width = document.body.clientWidth + 'px';
  621. }
  622. },
  623. {
  624. rule: "default",
  625. hostname: "www.kancloud.cn",
  626. regexp: "",
  627. action: () => {
  628. var interval_id = setInterval(() => {
  629. var a = _$_(".sidebar", 'return_one');
  630. if (a) {
  631. _$_(".workspace", 'return_one').style.left = "180px";
  632. a.style.width = '180px';
  633. change_style(a);
  634. clearInterval(interval_id);
  635. }
  636. },
  637. 100);
  638. }
  639. },
  640. {
  641. rule: "default",
  642. hostname: "php.net",
  643. regexp: "",
  644. action: () => {
  645. _$_('.layout-menu', 'remove_one');
  646. if (_$_(".sect1", 'return_one')) _$_(".sect1", 'return_one').style.width = document.body.clientWidth - 50 + "px";
  647. if (_$_("#usernotes", 'return_one')) _$_("#usernotes", 'return_one').style.width = document.body.clientWidth - 50 + "px";
  648. }
  649. },
  650. {
  651. rule: "default",
  652. hostname: "www.zhihu.com",
  653. regexp: "",
  654. action: () => {
  655. _$_('.Question-sideColumn.Question-sideColumn--sticky', 'remove_one');
  656. _$_('.AdblockBanner-inner', 'remove_one');
  657. _$_('.QuestionHeader-side', 'remove_all');
  658. _$_('.AppHeader-userInfo', 'remove_all');
  659.  
  660. var browser_width = document.body.clientWidth - 50 + "px";
  661. _$_('.QuestionHeader-content', 'return_one').style.width = browser_width;
  662.  
  663. setInterval(() => {
  664. _$_('.HitQrcode', 'remove_one');
  665. },
  666. 100);
  667. }
  668. },
  669. {
  670. rule: "default",
  671. hostname: "www.letscorp.net",
  672. regexp: "",
  673. action: () => {
  674. _$_('#commentlist', 'remove_one');
  675. _$_('#sidebar', 'remove_one');
  676. _$_('#header', 'remove_one');
  677.  
  678. var browser_width = document.body.clientWidth - 50 + "px";
  679. _$_('#container', 'return_one').style.width = browser_width;
  680. _$_('#main', 'return_one').style.height = "auto";
  681. var p_ele = _$_('p', 'return_all');
  682. Array.prototype.forEach.call(p_ele,
  683. function(e) {
  684. e.style["font-size"] = "16px";
  685. });
  686. }
  687. },
  688. {
  689. rule: "default",
  690. hostname: "segmentfault.com",
  691. regexp: "",
  692. action: () => {
  693. _$_("#loginBanner", "remove_one");
  694. }
  695. },
  696. {
  697. rule: "default",
  698. hostname: "huziketang.mangojuice.top",
  699. regexp: "",
  700. action: () => {
  701. for (var i = 0; i < 10000; i++) {
  702. clearInterval(i);
  703. }-
  704. _$_("div", "return_all").forEach(function(ele) {
  705. if (ele.id && ele.id !== "wrapper" && ele.id !== "uyan_frame" && ele.id !== "donate-mask") {
  706. ele.parentNode.removeChild(ele);
  707. }
  708. });
  709. }
  710. },
  711. {
  712. rule: "default",
  713. hostname: "jandan.net",
  714. regexp: "",
  715. action: () => {
  716. // html 调色
  717. let _html = _$_('html', 'return_one')
  718. let _body = _$_('body', 'return_one')
  719. _html.style.backgroundColor = '#333'
  720. _body.style.backgroundColor = '#333'
  721. // 去掉某些ID的发图
  722. let title_list = document.querySelectorAll("[title^=防伪码]")
  723. let block_user_list = ["42c968079f1cc3495692a053f432e105142a3142"]
  724. Array.prototype.forEach.call(title_list, (titleDOM) => {
  725. let author_id = titleDOM.title.replace(/[\u4e00-\u9fa5]{3}:/, '') // 装B正则
  726. if (block_user_list.includes(author_id)) {
  727. let remove_div = titleDOM.parentNode.parentNode.parentNode.parentNode
  728. remove_div.parentNode.removeChild(remove_div)
  729. }
  730. })
  731. }
  732. },
  733. {
  734. rule: "default",
  735. hostname: "www.sogou.com",
  736. regexp: "",
  737. action: () => {
  738. // html 调色
  739. console.log('sdasdasda')
  740. let id;
  741. id = setInterval(() => {
  742. let right = _$_("#right", "return_one");
  743. if (right) {
  744. _$_("#right", "remove_one");
  745. clearInterval(id)
  746. }
  747. }, 300);
  748. }
  749. },
  750. {
  751. rule: "default",
  752. hostname: "10.0.74.227",
  753. regexp: "",
  754. action: () => {
  755. setTimeout( _ => {
  756. let title_list = document.querySelectorAll(".opblock-tag")
  757. Array.prototype.forEach.call(title_list, (titleDOM) => {
  758. titleDOM.click()
  759. })
  760. }, 10 * 1000)
  761. }
  762. },
  763. ]
  764.  
  765.  
  766. let matched_rule = rules.filter( rule_item => rule_item.hostname instanceof Array
  767. ? rule_item.hostname.includes(hostname)
  768. : rule_item.hostname === hostname
  769. )[0]
  770.  
  771. return matched_rule
  772. }
  773.  
  774.  
  775.  
  776. // --------------------- DOM function --------------------------------
  777. //寻找页面的主要内容
  778. function main_ele_searcher() {
  779. let article = document.getElementsByTagName('article')
  780. let main = document.getElementsByTagName('main')
  781. let content = (article.length && article[0]) || (main.length && main[0]) || false
  782. if (content) {
  783. return {
  784. main_ele: content,
  785. body_width: content.style.width,
  786. body_height: content.style.height
  787. };
  788. }
  789.  
  790. var ele = document.querySelectorAll("*");
  791. var arr = [];
  792. //var arr_index = [];
  793. var w, h;
  794.  
  795. var body_width = document.body.clientWidth;
  796. var body_height = document.body.clientHeight;
  797.  
  798. if (!body_height) {
  799. var max_width = 0, max_height = 0;
  800. document.documentElement.style.height = '100%';
  801. document.body.style.height = '100%';
  802.  
  803. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  804. w = ele[i].clientWidth;
  805. h = ele[i].clientHeight;
  806. if (w > max_width) { max_width = w; }
  807. if (h > max_height) { max_height = h; }
  808. w = null;
  809. h = null;
  810. }
  811. body_width = max_width;
  812. body_height = max_height;
  813. }
  814.  
  815.  
  816. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  817. w = ele[i].clientWidth;
  818. h = ele[i].clientHeight;
  819. //console.log(h);
  820.  
  821. if (w && h && w > body_width / 2 && h > body_height / 5 && w < body_width && h < body_height) {
  822. arr[w * h] = ele[i];
  823. //console.log(ele[i]);
  824. //arr_index.push(w * h);
  825. }
  826. w = null;
  827. h = null;
  828. }
  829. var main_ele = arr[arr.length - 1] || document.body;
  830. return {
  831. main_ele,
  832. body_width,
  833. body_height
  834. };
  835. }
  836.  
  837. function content_purge() {
  838. let article = document.getElementsByTagName('article')
  839. let main = document.getElementsByTagName('main')
  840. let content = (article.length && article[0]) || (main.length && main[0]) || false;
  841. if (content) {
  842. main.style.cssText = 'width: 900px;margin: 40px 0 0 120px;float: left; ';
  843. document.body.innerHTML = '';
  844. document.body.appendChild(main);
  845. }
  846.  
  847. // main.parentNode.removeChild(main)
  848. // Array.from(document.body.children)
  849. // document.body.insertBefore(main, document.body.firstChild);
  850.  
  851. }
  852.  
  853. //去除侧边栏这样“狭长”的内容
  854. function ele_remover(obj) {
  855. var w, h;
  856. var { main_ele, body_width, body_height } = obj;
  857. var ele = document.querySelectorAll("*");
  858. //console.log(main_ele,body_width, body_height )
  859. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  860. w = ele[i].clientWidth;
  861. h = ele[i].clientHeight;
  862. // main_ele.parentNode.children
  863. 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) {
  864. //content_adjust(ele[i]);
  865. console.log("---------element removed ------------");
  866. console.log(ele[i]);
  867. console.log("---------element removed ------------");
  868.  
  869. ele[i].parentNode.removeChild(ele[i]);
  870. }
  871. w = null;
  872. h = null;
  873. }
  874. }
  875.  
  876. //去除被移除元素的兄弟元素的padding margin
  877. function content_adjust(ele) {
  878. var siblings = ele.parentNode.children;
  879. ele.parentNode.style.position = "relative";
  880. // console.log(ele);
  881. for (let i = 0, ele_length = siblings.length; i < ele_length; i++) {
  882. //console.log(siblings[i]);
  883. siblings[i].setAttribute('style', 'position:relative;padding:20px;margin:0px;overflow:visible;');
  884. }
  885. }
  886.  
  887. //调整主要内容的样式
  888. function main_content_adjust(main_ele) {
  889. //var a = [{x,y,top,right,bottom,left,width}]=main_ele.getClientRects();
  890. main_ele.parentNode.style.position = "relative";
  891. main_ele.style.cssText = "position:absolute; top:0;right:0; bottom:0;left:0;"
  892. // main_ele.setAttribute('style','position:relative;padding:20px 20px 20px 40px;margin:auto;clear:both;overflow:visible;');
  893. var ratio = 0.9 * (window.innerWidth) / main_ele.clientWidth;
  894. var ele = main_ele.querySelectorAll('*');
  895. // console.log(ele);
  896. for (let i = 0, ele_length = ele.length; i < ele_length; i++) {
  897. ele[i].style.width = ele[i].clientWidth * ratio + "px";
  898. ele[i].style.overflow = 'visible';
  899. //console.log(i);
  900. }
  901.  
  902. }
  903.  
  904. // body 全屏
  905. function full_body() {
  906. let root = document.body
  907. root.style.cssText = "position:absolute; top:0;right:0; bottom:0;left:0;"
  908.  
  909. }
  910.  
  911. //背景调色
  912. function change_style(DOM_node = document.body) {
  913. return
  914. // 执行速度 : for 循环 > forEach > 尾递归 >递归 (迭代)
  915. let background_base_color = 50;
  916. let background_offset = 20;
  917. let font_base_color = 230;
  918. let font_offset = 20;
  919. var all = (DOM_node || document).querySelectorAll('*');
  920. for (let i = 0, ele_length = all.length; i < ele_length; i++) {
  921. let item = all[i]
  922. let item_style = item.style
  923. let tag_exclude_check = !('script,style,img').includes(item.nodeName.toLowerCase())
  924. if(tag_exclude_check && !item_style.backgroundColor){
  925. item_style.backgroundColor = random_color(background_base_color,background_offset);
  926. item_style.color = random_color(font_base_color,font_offset);
  927. }
  928. }
  929. }
  930.  
  931. function random_color(base_color, offset, ratio=1){
  932. base_color = (base_color & 255) === (~~base_color) ? ~~base_color : 255;
  933. offset = ~~offset
  934. offset = (base_color+offset > 0 && base_color+offset < 256)? offset : 0
  935. return `rgba(${(base_color + offset*Math.random())&255},${(base_color + offset*Math.random())&255},${(base_color + offset*Math.random())&255},0.8)`;
  936. }
  937.  
  938. function ele_hide(e) {
  939. // if (document.body.hasChildNodes(e)) e.style.display = "none";
  940. document.body.hasChildNodes(e) && e.length !== 0 && e.style.setAttribute('display', "none");
  941. }
  942. function ele_hide_all(all) {
  943. Array.prototype.forEach.call(all, function (e) { e.style.display = "none"; });
  944. }
  945. function ele_remove(e) {
  946. // if (document.body.hasChildNodes(e)) e.parentNode.removeChild(e);
  947. e = e.length ? e[0] : e
  948. document.body.hasChildNodes(e) && e.length !== 0 && e.parentNode.removeChild(e);
  949. }
  950. function ele_remove_all(all) {
  951. if (all) {
  952. all = Array.from(all)
  953. }
  954. if (!all.length) {
  955. return
  956. }
  957. Array.prototype.forEach.call(all, function (e) {
  958. e instanceof Object && e.parentNode.removeChild(e);
  959. });
  960. }
  961.  
  962. function _$_(selector, operation_code) {
  963. // operation_code : return_one return_all remove_one remove_all hide_one hide_all
  964. function get(selector) {
  965. if((/^#[^.#]+$/).test(selector)) {
  966. return [document.getElementById(selector.slice(1, selector.length))]
  967. }
  968. if((/^\.[^.#]+$/).test(selector)) {
  969. return document.getElementsByClassName(selector.slice(1, selector.length))
  970. }
  971. if((/^[^.#\[\]=]+$/).test(selector)) {
  972. return document.getElementsByTagName(selector)
  973. }
  974. return document.querySelectorAll(selector)
  975. }
  976. switch (operation_code) {
  977. case 'return_one': //return_one
  978. // return document.querySelector(selector);
  979. return get(selector)[0];
  980. case 'return_all':// return_all
  981. // return document.querySelectorAll(selector);
  982. return get(selector);
  983. case 'remove_one': //remove_one
  984. // ele_remove(document.querySelector(selector));
  985. ele_remove(get(selector));
  986. break;
  987. case 'remove_all': //remove_all
  988. // ele_remove_all(document.querySelectorAll(selector));
  989. ele_remove_all(get(selector));
  990. break;
  991. case 'hide_one': //hide_one
  992. // ele_hide(document.querySelector(selector));
  993. ele_hide(get(selector));
  994. break;
  995. case 'hide_all':// hide_all
  996. // ele_hide_all(document.querySelectorAll(selector));
  997. ele_hide_all(get(selector));
  998. break;
  999.  
  1000. default:
  1001. // JQuery like
  1002. var result = get(selector);
  1003. result.remove = function(){ele_remove(this)} // ele_remove() only delete one or the first of the list
  1004. return result
  1005. // return result.length > 1 ? result : result[0];
  1006. }
  1007. }
  1008.  
  1009. function _$() {
  1010. return document.querySelector.apply(document, arguments)
  1011. }
  1012. function _$$() {
  1013. return document.querySelectorAll.apply(document, arguments)
  1014. }
  1015.  
  1016. function _CSS(DOM_ele, pseudo_class) {
  1017. return pseudo_class ? window.getComputedStyle(DOM_ele, pseudo_class) : window.getComputedStyle(DOM_ele)
  1018. }
  1019.  
  1020. function revert_color(color) {
  1021. const [red, blue, green, alpha] = color.match(/\d{1,3}/g);
  1022. return Number(alpha) ? `rgba(${255 - red}, ${255 - blue}, ${255 - green}, ${alpha})` : `rgb(${255 - red}, ${255 - blue}, ${255 - green})`;
  1023. }
  1024.  
  1025. function remove_div_padding_margin(ele) {
  1026. if (ele) {
  1027. ele.setAttribute('style', 'overflow:visible;position:relative;padding:0px;margin:0px;left:0px;');
  1028. }
  1029. if (ele && ele.children.length > 0) {
  1030. Array.prototype.forEach.call(ele.children, (function (e) {
  1031. remove_div_padding_margin(e);
  1032. }));
  1033. }
  1034. }
  1035.  
  1036. // ----------------------- utils -------------------------------
  1037. function sleep(ms = 1500) {
  1038. return new Promise(resolve => setTimeout(_ => resolve(), ~~ms))
  1039. }
  1040.  
  1041. function autoRefresh(minute = 5) {
  1042. let time = parseFloat(minute) || 5
  1043. window.setTimeOutId = ''
  1044. window.addEventListener('offline', function(e) { clearTimeout(window.setTimeOutId); });
  1045. window.addEventListener('online', function(e) {
  1046. window.location.href = window.location.href;
  1047. });
  1048. window.setTimeOutId = setTimeout(() => {
  1049. if (window.navigator.onLine) {
  1050. window.location.href = window.location.href
  1051. }
  1052. }, time * 60 * 1000)
  1053. }
  1054.  
  1055. function getFormatDate(date) {
  1056. let year = new Date(date).getFullYear()
  1057. let month = new Date(date).getMonth() + 1
  1058. let day = new Date(date).getDate()
  1059. month = month < 10 ? '0' + month : month
  1060. day = day < 10 ? '0' + day : day
  1061. return [year, month, day].join('-')
  1062. }
  1063.  
  1064. function isWorkDay(){
  1065. // should update national_holiday national_workday every year after official notice
  1066. const national_holiday = [
  1067. '2020-04-04',
  1068. '2020-04-05',
  1069. '2020-04-06',
  1070. '2020-05-01',
  1071. '2020-05-02',
  1072. '2020-05-03',
  1073. '2020-05-04',
  1074. '2020-05-05',
  1075. '2020-06-25',
  1076. '2020-06-26',
  1077. '2020-06-27',
  1078. '2020-10-01',
  1079. '2020-10-02',
  1080. '2020-10-03',
  1081. '2020-10-04',
  1082. '2020-10-05',
  1083. '2020-10-06',
  1084. '2020-10-07',
  1085. '2020-10-08'
  1086. ]
  1087. const national_workday = [
  1088. '2020-04-26',
  1089. '2020-05-09',
  1090. '2020-06-28',
  1091. '2020-09-27',
  1092. '2020-10-10'
  1093. ]
  1094. if (national_holiday.includes(getFormatDate(Date.now()))) {
  1095. return false
  1096. }
  1097. if (national_workday.includes(getFormatDate(Date.now()))) {
  1098. return true
  1099. }
  1100. const day_week = new Date(Date.now()).getDay()
  1101. if (day_week === 0 || day_week === 6) {
  1102. return false
  1103. } else {
  1104. return true
  1105. }
  1106. }
  1107.  
  1108. function postData(url, data) {
  1109. const opts = {
  1110. method: 'POST', // 请求方法
  1111. body: JSON.stringify(data), // 请求体
  1112. headers: {
  1113. accept: 'application/json',
  1114. 'content-type': 'application/json'
  1115. },
  1116. mode: 'cors'
  1117. }
  1118. return fetch(url, opts)
  1119. .then(response => {
  1120. return response.json()
  1121. })
  1122. .then(resp => {
  1123. return resp
  1124. // return Promise.reject(resp)
  1125. })
  1126. }
  1127.  
  1128. function getData(url) {
  1129. const opts = {
  1130. method: 'GET', // 请求方法
  1131. mode: 'cors'
  1132. }
  1133. return fetch(url, opts)
  1134. .then(response => {
  1135. return response.json()
  1136. })
  1137. .then(resp => {
  1138. return resp
  1139. // return Promise.reject(resp)
  1140. })
  1141. }
  1142.  
  1143. function content_get() {
  1144. var ajax = new XMLHttpRequest();
  1145. ajax.open('get', '/');
  1146. ajax.send();
  1147. ajax.onreadystatechange = function () {
  1148. if (ajax.readyState == 4 && ajax.status == 200) {
  1149. content_new = ajax.responseText;
  1150. //console.log(content_new);
  1151. content_old = content_old || content_new;
  1152. if (content_new !== content_old) {
  1153. location.reload();
  1154. }
  1155. }
  1156. };
  1157.  
  1158. setTimeout(content_get, 1000);
  1159. }
  1160.  
  1161. function downloadFile(paramObj){
  1162. let {filePath, fileName} = paramObj instanceof Object ? paramObj : {}
  1163. if (!filePath) return;
  1164. const randomName = Math.random().toString(32).slice(2);
  1165. const matchArr = filePath.match(/[^./?]+\.[a-zA-Z0-9]+(?=$|\?.*)/g) || []
  1166. const defaultName = matchArr[0]
  1167. fetch(filePath).then(res => res.blob()).then(blob => {
  1168. const a = document.createElement('a');
  1169. document.body.appendChild(a)
  1170. a.style.display = 'none'
  1171. // 使用获取到的blob对象创建的url
  1172. const url = window.URL.createObjectURL(blob);
  1173. a.href = url;
  1174. // 指定下载的文件名
  1175. a.download = fileName || defaultName || randomName;
  1176. a.click();
  1177. document.body.removeChild(a)
  1178. // 移除blob对象的url
  1179. window.URL.revokeObjectURL(url);
  1180. });
  1181. }
  1182. function parseQuery () {
  1183. const hastPare = window.location.hash.match(/[^?&=]+\=[^?&=]+/g) || []
  1184. return hastPare.reduce((acc, ele) => {
  1185. const [key, val] = ele.split('=')
  1186. acc[key] = val
  1187. return acc
  1188. }, {})
  1189. }
  1190.  
  1191. function openConsole () {
  1192. var event = document.createEvent('Events');
  1193. event.keyCode = 100;
  1194. event.initEvent('keypress', true, true);
  1195. $0.dispatchEvent(event);
  1196. }
  1197.  
  1198. class MutationObserverClass {
  1199. constructor({window}) {
  1200. this.window = window
  1201. this.listeners = [];
  1202. this.observer = undefined
  1203. }
  1204.  
  1205. start({element, selector, fn}) {
  1206. // 储存选择器和回调函数
  1207. this.listeners.push({
  1208. element,
  1209. selector,
  1210. fn
  1211. });
  1212. if(!this.observer){
  1213. // 监听document变化
  1214. let MutationObserver = this.window.MutationObserver || this.window.WebKitMutationObserver;
  1215. let check = this.check.bind(this)
  1216. this.observer = new MutationObserver(check);
  1217. this.observer.observe(this.window.document.documentElement, {
  1218. childList: true,
  1219. subtree: true
  1220. });
  1221. }
  1222. // 检查该节点是否已经在DOM中
  1223. this.check();
  1224. }
  1225.  
  1226. check(){
  1227. // console.log('check this', this)
  1228. // 检查是否匹配已储存的节点
  1229. this.listeners.forEach(listener => {
  1230. // 检查指定节点是否有匹配
  1231. let element = listener.element || this.window.document.querySelector(listener.selector)
  1232. let isSelf = element instanceof HTMLElement && element === this.window.document.querySelector(listener.selector)
  1233. console.log('isSelf', isSelf)
  1234. // console.log('element', element)
  1235. // console.log('this.window.document.querySelector(listener.selector)', this.window.document.querySelector(listener.selector))
  1236. if (isSelf) {
  1237. const called = ele => ele.called = true
  1238. element instanceof HTMLElement && !element.called && called(element) && listener.fn.call(element, element);
  1239. } else {
  1240. element instanceof HTMLElement && called(element) && listener.fn.call(element, element);
  1241. }
  1242.  
  1243. })
  1244. // for(let i = 0; i < this.listeners.length; i++){
  1245.  
  1246. // // let listener = this.listeners[i];
  1247. // // // 检查指定节点是否有匹配
  1248. // // let element = listener.element || this.window.document.querySelector(listener.selector)
  1249. // // if (!element) {
  1250. // // return
  1251. // // }
  1252. // // element instanceof HTMLDivElement && listener.fn.call(element, element);
  1253. // // console.log('elements', elements)
  1254. // // for(let j = 0; j < elements.length; j++){
  1255. // // let element = elements[j];
  1256. // // console.log('element', element)
  1257. // // // 确保回调函数只会对该元素调用一次
  1258. // // if(!element.ready){
  1259. // // element.ready = true;
  1260. // // // 对该节点调用回调函数
  1261. // // listener.fn.call(element, element);
  1262. // // }
  1263. // // }
  1264. // }
  1265. }
  1266. }
  1267.  
  1268.  
  1269.  
  1270.  
  1271. // ---------------------------------- main -------------------------------------
  1272.  
  1273. main()