Beautify

美化<误>各网页界面

  1. // ==UserScript==
  2. // @name Beautify
  3. // @namespace https://github.com/symant233/PublicTools
  4. // @version 0.1.87
  5. // @description 美化<误>各网页界面
  6. // @author symant233
  7. // @icon https://cdn.jsdelivr.net/gh/symant233/PublicTools/Beautify/Bkela.png
  8. // @match https://*.vuejs.org/*
  9. // @match https://www.runoob.com/*
  10. // @match https://blog.csdn.net/*
  11. // @match https://es6.ruanyifeng.com/*
  12. // @match https://wenku.baidu.com/*
  13. // @match https://didi.github.io/cube-ui/*
  14. // @match https://www.bilibili.com/*
  15. // @match https://space.bilibili.com/*
  16. // @match https://cn.bing.com/search?q=*
  17. // @match https://duckduckgo.com/?q=*
  18. // @match https://baike.baidu.com/*
  19. // @match https://yz.chsi.com.cn/sytj/tj/*
  20. // @match https://www.30secondsofcode.org/*
  21. // @match https://developer.mozilla.org/*
  22. // @match https://juejin.cn/editor/drafts/*
  23. // @match https://xui.ptlogin2.qq.com/cgi-bin/xlogin*
  24. // @match https://steamcommunity.com/*
  25. // @match https://www.pixiv.net/*
  26. // @match https://live.bilibili.com/*
  27. // @match https://frontendwingman.com/*
  28. // @match https://cloud.tencent.com/developer/*
  29. // @match https://www.npmjs.com/*
  30. // @match https://www.zhihu.com/*
  31. // @match https://fanyi.baidu.com/*
  32. // @match https://jiexi.8old.cn/*
  33. // @match https://read.qidian.com/*
  34. // @match https://*.taobao.com/*
  35. // @match https://s.taobao.com/search?q=*
  36. // @match https://*.tmall.com/*
  37. // @match https://caddyserver.com/docs/*
  38. // @match https://leetcode.cn/*
  39. // @match https://mooc1.chaoxing.com/work/*
  40. // @match https://mooc1.chaoxing.com/mooc2/work/*
  41. // @match https://*sci-hub.*/*
  42. // @match https://scholar.google.com/scholar?q=*
  43. // @match https://www.dlsite.com/*
  44. // @match https://preactjs.com/*
  45. // @match https://*.react.dev/*
  46. // @match https://basarat.gitbook.io/*
  47. // @match https://www.photopea.com/*
  48. // @match https://www.phind.com/*
  49. // @match https://hd.nowcoder.com/link.html?target=*
  50. // @match *://www.cesium.xin/*
  51. // @match https://message.bilibili.com/*
  52. // @match *://pan.baidu.com/share/*
  53. // @match https://x.com/*
  54. // @match https://*.xiaoeknow.com/*
  55. // @match https://nextjs.org/*
  56. // @grant GM_getValue
  57. // @grant GM_setValue
  58. // @grant GM_addStyle
  59. // @grant GM_registerMenuCommand
  60. // @grant unsafeWindow
  61. // @license GPL-3.0
  62. // @homepageURL https://greatest.deepsurf.us/zh-CN/scripts/390421-beautify
  63. // @supportURL https://github.com/symant233/PublicTools/issues
  64. // ==/UserScript==
  65.  
  66. ;(function() {
  67. 'use strict';
  68.  
  69. const $ = {
  70. // 选择器函数
  71. $(selector) {
  72. return document.querySelectorAll(selector);
  73. },
  74. // 获取第一个匹配元素
  75. first(selector) {
  76. return document.querySelector(selector);
  77. },
  78. // 通用遍历方法
  79. each(selector, callback) {
  80. const elements = this.$(selector);
  81. for (let i = 0; i < elements.length; i++) {
  82. callback(elements[i], i);
  83. }
  84. },
  85. // 添加类
  86. addClass(selector, className) {
  87. this.each(selector, element => {
  88. element.classList.add(className);
  89. });
  90. },
  91. // 移除类
  92. removeClass(selector, className) {
  93. this.each(selector, element => {
  94. element.classList.remove(className);
  95. });
  96. },
  97. // 设置属性
  98. attr(selector, attr, value) {
  99. this.each(selector, element => {
  100. element.setAttribute(attr, value);
  101. });
  102. },
  103. // 获取属性
  104. getAttr(selector, attr) {
  105. const element = this.first(selector);
  106. return element ? element.getAttribute(attr) : null;
  107. },
  108. // 添加事件监听
  109. on(selector, event, handler) {
  110. this.each(selector, element => {
  111. element.addEventListener(event, handler);
  112. });
  113. },
  114. // 移除元素
  115. remove(selector) {
  116. this.each(selector, element => {
  117. element.remove();
  118. });
  119. },
  120. // 添加HTML
  121. append(selector, html) {
  122. const element = this.first(selector);
  123. if (element) {
  124. element.insertAdjacentHTML('beforeend', html);
  125. }
  126. },
  127. // 添加元素到指定元素
  128. appendTo(selector, targetSelector) {
  129. const element = document.createElement(selector);
  130. const target = this.first(targetSelector);
  131. if (target) {
  132. target.appendChild(element);
  133. }
  134. return element;
  135. },
  136. // 点击事件
  137. click(selector) {
  138. const element = this.first(selector);
  139. if (element) {
  140. element.click();
  141. }
  142. },
  143. // 获取子元素
  144. children(selector) {
  145. const element = this.first(selector);
  146. return element ? element.children : [];
  147. },
  148. // 获取父元素
  149. parent(selector) {
  150. const element = this.first(selector);
  151. return element ? element.parentElement : null;
  152. },
  153. // 创建元素
  154. create(tagName) {
  155. return document.createElement(tagName);
  156. }
  157. };
  158. // 打印载入日志
  159. (function(left, right, color) {
  160. const arg = [
  161. `%c ${left} %c ${right} `,
  162. 'padding:1px;border-radius:3px 0 0 3px;color:#fff;background:#606060;',
  163. `padding:1px;border-radius:0 3px 3px 0;color:#fff;background:${color}`
  164. ];
  165. console.log(...arg);
  166. })('Loaded', 'Beautify', '#e99010');
  167. switch (location.hostname) {
  168. case 'vuejs.org':
  169. function zhVue() {
  170. let url = location.href.replace('://vue', '://cn.vue');
  171. location.href = url;
  172. }
  173. const el = document.querySelector('a[href="/translations/"]');
  174. el.addEventListener("click", zhVue);
  175. el.href = '#';
  176. break;
  177. case 'www.runoob.com':
  178. //隐藏头部logo 移动搜索框位置到navbar
  179. $.append('#index-nav', `<form action="//www.runoob.com/" target="_blank" style="display: inline;float: right;">
  180. <input class="placeholder" id="s" name="s" placeholder="搜索……" autocomplete="off"></form>`);
  181. $.append('.pc-nav', `<form action="//www.runoob.com/" target="_blank" style="display: inline;position: absolute;right:0;">
  182. <input class="placeholder" id="s" name="s" placeholder="搜索……" autocomplete="off"></form>`);
  183. GM_addStyle(`#s{outline: 0; height: 2.3rem; margin-top: -1px; margin-right: 2rem; border: 0; border-radius: 4px;}`);
  184. $.remove('.logo-search');
  185. GM_addStyle(`.col.nav{padding-top: 5px;}`);
  186. $.parent('#sidebar-right-re')?.remove();
  187. $.remove('.feedback-btn');
  188. $.remove('.qrcode');
  189. GM_addStyle(`.navigation{background: grey;}`);
  190. if (document.location.href.split('/')[3] == "try") {
  191. $.remove('nav');
  192. GM_addStyle(`body{padding-top: 60px;}`);
  193. $.remove('footer');
  194. }
  195. break;
  196. case 'csdn.net': {
  197. console.log('Beautify@ try to click');
  198. const btnReadmore = $.first('.btn-readmore');
  199. if (btnReadmore) {
  200. btnReadmore.click();
  201. console.log('Beautify@ clicked: true');
  202. }
  203. break;
  204. }
  205. case 'es6.ruanyifeng.com':
  206. GM_addStyle(`
  207. #content{width: 63%; padding-bottom: 0px;}
  208. #back_to_top{right: 35px;}
  209. #edit{right: 35px;}
  210. #theme{right: 35px;}
  211. #flip{right: 10px;}
  212. `);
  213. break;
  214. case 'wenku.baidu.com':
  215. setTimeout(function() {
  216. console.log('show more');
  217. $.click('.btn-know');
  218. $.click('.moreBtn');
  219. }, 1500 );
  220. break;
  221. case 'didi.github.io':
  222. setTimeout(function() {
  223. GM_addStyle(`
  224. .navigator{height: 54px; line-height: 54px;}
  225. .home-view{padding-top: 38px;}
  226. `);
  227. }, 500 );
  228. break;
  229. case 'bilibili.com':
  230. case 'www.bilibili.com': {
  231. const enableWideScreen = GM_getValue('enableWideScreen', true); // 是否启用宽屏模式
  232. GM_registerMenuCommand('切换宽屏设置', () => GM_setValue('enableWideScreen', !enableWideScreen));
  233. // 宽屏模式 来自 https://github.com/bilibili-helper/bilibili-helper-o/blob/637d0741b0d81154c7bc330f8fce19b926f5a71b/src/js/modules/videoWiden/UI/index.js
  234. function setWide() {
  235. const btn = document.querySelector('.bpx-player-ctrl-wide:not(.bpx-state-entered)');
  236. if (btn) {
  237. btn.click();
  238. // 调整滚动位置
  239. setTimeout(() => {
  240. const player = document.querySelector('#bilibili-player');
  241. if (player) {
  242. const playerRect = player.getBoundingClientRect();
  243. const position = window.scrollY + playerRect.top - 75; // Navbar height
  244. window.scrollTo({ top: position });
  245. }
  246. }, 500);
  247. if (unsafeWindow.ob) unsafeWindow.ob.disconnect(); // 触发后停止监听
  248. }
  249. }
  250. new Promise(resolve => {
  251. const player = document.querySelector('#bilibili-player');
  252. if (player && enableWideScreen) {
  253. unsafeWindow.ob = new MutationObserver((mutationList) => {
  254. setWide();
  255. });
  256. unsafeWindow.ob.observe(player, {
  257. attributes: false,
  258. subtree: true,
  259. childList: true,
  260. });
  261. }
  262. resolve();
  263. });
  264. // PiP 画中画模式快捷键`p`
  265. document.addEventListener('keyup', function (e) {
  266. if (e.key === 'p' && e.altKey) {
  267. document.querySelector('video').requestPictureInPicture();
  268. } else if (e.key === 'ArrowRight' & e.altKey === true) {
  269. $.click('.bilibili-player-video-btn-next');
  270. }
  271. }, false);
  272. GM_addStyle(`
  273. html.gray {
  274. filter: grayscale(0) !important;
  275. -webkit-filter: grayscale(0) !important;
  276. }
  277. .bili-subtitle-x-subtitle-panel-text {
  278. font-family: unset !important;
  279. }
  280. `);
  281. // start of the `spm_id_from` filter
  282. let listener = function (e) {
  283. let i = e.target;
  284. for (; i && i.tagName !== "A"; )
  285. i = i.parentNode;
  286. if ((i == null ? void 0 : i.tagName) !== "A")
  287. return;
  288. let o = i.getAttribute("href");
  289. if (!o || !/\/\//.test(o) || !/spm_id_from=/.test(o) || /^blob:/.test(o))
  290. return;
  291. i.setAttribute("href", o.split('?spm_id_from')[0]); // fuck bilibili spm_id
  292. }
  293. document.body.addEventListener("contextmenu", listener, false);
  294. break;
  295. }
  296. case 'cn.bing.com': {
  297. //GM_addStyle('#b_content{padding-left: 85px;}');
  298. break;
  299. }
  300. case 'duckduckgo.com': {
  301. GM_addStyle('#links_wrapper{padding-left: 108px;}');
  302. break;
  303. }
  304. case 'baike.baidu.com':
  305. $.remove('.video-list-container'); // 删除播放器容器
  306. GM_addStyle(`
  307. .lemmaWgt-searchHeader{height:55px;}
  308. div[class^="videoListWrap"], div[class^="knowledge-toolbar"], .J-knowledge-editor-toolbar {display: none;}
  309. .content-wrapper .content {font: unset;}
  310. .wgt-searchbar-new.wgt-searchbar .logo-container{padding: 6px 0;}
  311. .wgt-searchbar-new.wgt-searchbar .search{padding: 8px 0;}
  312. .wgt-navbar-hover {margin-top: 5px;}
  313. #J-lemma-video-list, #J-bottom-tashuo {display: none;}
  314. `);
  315. break;
  316. case 'yz.chsi.com.cn': {
  317. // 去除不符合不能调剂的信息
  318. function filter() {
  319. const tbody = $.first("#content-qecxList > table > tbody");
  320. if (!tbody) return;
  321. const children = tbody.children;
  322. for (let i = 0; i < children.length; i++) {
  323. const lastChild = children[i].lastElementChild;
  324. if (lastChild && (
  325. lastChild.innerText.includes("不符合") ||
  326. (lastChild.firstElementChild && lastChild.firstElementChild.title.includes('不符合'))
  327. )) {
  328. children[i].remove();
  329. console.log(children[i].textContent + 'removed');
  330. }
  331. }
  332. }
  333. const btnFilter = $.create('button');
  334. btnFilter.id = 'btn-filter';
  335. GM_addStyle('#btn-filter{width: 50px;}');
  336. btnFilter.textContent = '过滤';
  337. const ewmFix = $.first('.ewm-fix');
  338. if (ewmFix) {
  339. ewmFix.appendChild(btnFilter);
  340. btnFilter.addEventListener('click', filter);
  341. }
  342. document.addEventListener('keyup', function (e) {
  343. if (e.key === 'Enter' && e.ctrlKey) {
  344. $.click('.tj-seach-btn');
  345. }
  346. }, false);
  347. break;
  348. }
  349. case 'www.30secondsofcode.org':
  350. GM_addStyle('.nav-bar{height:auto;}');
  351. break;
  352. case 'developer.mozilla.org': {
  353. GM_addStyle(`
  354. .mdn-cta-container{display:none;}
  355. .page-header{padding:12px 24px;}
  356. .breadcrumb-locale-container,#license{margin:0px;}
  357. .logo{height:59px;}
  358. .localized-content-note.notecard.neutral{display:none;}
  359. .header-search{margin-bottom: 4px;}
  360. .top-banner.fallback{display:none;}
  361. `);
  362. break;
  363. }
  364. case 'juejin.cn':
  365. GM_addStyle('.header.editor-header{height:4rem;}.main .bytemd{height:calc(100vh - 4rem);}');
  366. break;
  367. case 'xui.ptlogin2.qq.com':
  368. // 自动启用账号密码登录 去他大爷的扫码登录
  369. // GM_addStyle('.web_qr_login{display:block !important;}.qlogin,#bottom_qlogin{display:none !important;}');
  370. break;
  371. case 'steamcommunity.com': {
  372. setInterval(()=>{
  373. try {
  374. document.getElementById('market_sell_dialog_accept_ssa').checked = true;
  375. } catch (err) {}
  376. try {
  377. document.getElementById('market_buyorder_dialog_accept_ssa').checked = true;
  378. } catch (err) {}
  379. }, 2000);
  380. break;
  381. }
  382. case 'www.pixiv.net':
  383. // 需要与脚本配合使用 https://greatest.deepsurf.us/zh-CN/scripts/34153-pixiv-plus
  384. GM_addStyle(`
  385. select#select-ahao-favorites {
  386. font-size: 14px;
  387. line-height: 22px;
  388. flex: 1 1 auto;
  389. height: auto;
  390. margin: 0px -9px;
  391. padding: 9px 8px;
  392. border: none;
  393. border-radius: 4px;
  394. color: rgba(0, 0, 0, 0.64);
  395. background-color: rgba(0, 0, 0, 0.04);
  396. transition: background-color 0.2s ease 0s, color 0.2s ease 0s;
  397. }
  398. #select-ahao-favorites+div{gap: 0px;}
  399. `);
  400. break;
  401. case 'live.bilibili.com': {
  402. const enableSideFollow = GM_getValue('enableSideFollow', false); // 是否切换关注按钮全屏展示
  403. GM_registerMenuCommand('切换关注按钮全屏展示', () => GM_setValue('enableSideFollow', !enableSideFollow));
  404. GM_addStyle(`
  405. .side-bar-popup-cntr{bottom:5% !important;height:84% !important;}
  406. .anchor-list {height: calc(100% - 55px) !important}
  407. .anchor-list > div {height:unset !important; align-content: flex-start;}
  408. .follow-cntr{height:100%;}
  409. .shortcut-item .follow-cntr{height:unset;}
  410. .section-content-cntr{height: calc(100% - 64px) !important;}
  411. .title-length-limit{max-width:unset !important;}
  412. `);
  413. if (enableSideFollow) GM_addStyle(`
  414. .player-full-win .side-bar-cntr {display: block !important; height: 60px !important; padding: 4px !important;}
  415. .player-full-win .side-bar-cntr div[data-upgrade-intro="Laboratory"] {display: none;}
  416. .player-full-win .side-bar-cntr div[data-upgrade-intro="Top"] {display: none;}
  417. `);
  418. break;
  419. }
  420. case 'frontendwingman.com':
  421. try {
  422. // credit: github.com/invobzvr
  423. Object.defineProperty(document.querySelector('.theme-container').__vue__,'locked',{
  424. get:()=>true,
  425. set:function(val){this._data.locked=true}
  426. });
  427. document.querySelector('.theme-container').__vue__.locked = true;
  428. } catch (e) {
  429. console.warn('Beautify: 自动解锁失效.');
  430. }
  431. break;
  432. case 'cloud.tencent.com':
  433. GM_addStyle('.doc-main-hd {margin-bottom: 24px;padding-bottom: 28px;border-bottom: 1px solid #e5e5e5;}');
  434. break;
  435. case 'www.npmjs.com':
  436. GM_addStyle(`
  437. .center-ns {padding-bottom: unset;}
  438. pre.editor.editor-colors {overflow: overlay;}
  439. header > div:nth-child(2) {display: none;}
  440. `);
  441. break;
  442. case 'www.zhihu.com':
  443. if (window.location.href === "https://www.zhihu.com/hot") {
  444. document.querySelectorAll('.HotItem').forEach((e) => {
  445. if (!e.outerHTML.includes('HotItem-excerpt')) {e.remove();}
  446. if (!e.outerHTML.includes('HotItem-img')) {e.remove();}
  447. });
  448. }break;
  449. case 'fanyi.baidu.com':
  450. GM_addStyle(`
  451. .download-app,.doc-feedback-group{display:none;}
  452. .header{padding:3px 0 7px 0;}
  453. .doc-whole-container{height:100%;}
  454. .doc-trans-view-wrap{width: unset;height: 88%;margin-top: -38px;}
  455. `);
  456. break;
  457. case 'jiexi.8old.cn': {
  458. // https://jx.m3u8.tv/jiexi/?url=
  459. document.addEventListener('keyup', function (e) {
  460. if (e.key === 'f') {
  461. $.click('.dplayer-full-icon');
  462. } else if ([1,2,3,4].includes(parseInt(e.key))) {
  463. const speedItems = $.$('.dplayer-setting-speed-item');
  464. if (speedItems.length > parseInt(e.key)) {
  465. speedItems[parseInt(e.key)].click();
  466. }
  467. }
  468. }, false);
  469. break;
  470. }
  471. case 'qidian.com':
  472. GM_addStyle(`
  473. body{overflow-x:hidden !important;}
  474. .admire-wrap,.guide-btn-wrap,#j_navGameBtn,#navReward,#j_phoneRead{display:none;}
  475. `);
  476. break;
  477. case 'caddyserver.com':
  478. GM_addStyle(`
  479. pre > code.cmd {font-size: 1rem; overflow: overlay;}
  480. main > .sidebar:last-child {flex-shrink: 2;}
  481. main > nav.sidebar {font-size: 1.2rem; width: 20%;}
  482. article > :not(h1), dd, article p, article ol, article ul, article pre, article table {margin-bottom: 0.5rem;}
  483. pre {padding-bottom: 0.5rem !important;padding-top: 0.5rem !important;}
  484. pre.chroma {font-size: 1rem;}
  485. #paper1, #paper2 {display: none;}
  486. .paper3 {top: unset;left: unset;}
  487. hr {margin-top: 2.5rem; margin-bottom: 2.5rem !important;}
  488. `);
  489. break;
  490. case 'leetcode.cn':
  491. GM_addStyle(`
  492. ul[class*="NavbarList"] > li[class*="NavbarListItem"]:nth-child(2)::after{display:none !important}
  493. ul[class*="NavbarList"] > li[class*="NavbarListItem"]:nth-child(6)::after{display:none !important}
  494. [class*=TimeRemainContainer]{display:none;}
  495. section[class*=MainContainer] > div[class*=Container]:nth-child(1){display: none;}
  496. section[class*=MainContainer]{margin-top: 12px;}
  497. span[class*=BasicTag-StyledTag]{margin-right: 8px;}
  498. `);
  499. // 自动开启运行结果差别
  500. function enableDiff () {
  501. const btn = document.querySelector('label[class*="Label-StyledSwitch"]');
  502. if (btn && !btn.getAttribute('beautify-data')) {
  503. btn.setAttribute('beautify-data', true);
  504. btn.click();
  505. }
  506. }
  507. setTimeout(() => {
  508. const button = $.first('div[class*=second-section-container] > div:last-child button');
  509. if (button) button.click();
  510. new Promise(resolve => {
  511. const container = document.querySelector('div[class*="CodeAreaContainer"]');
  512. if (container) {
  513. new MutationObserver((mutationList) => {
  514. mutationList.forEach((mutation) => {
  515. if (mutation.oldValue) enableDiff();
  516. });
  517. }).observe(container, {
  518. attributes: true,
  519. attributeOldValue: true,
  520. subtree: true,
  521. });
  522. }
  523. resolve();
  524. });
  525. }, 2600);
  526. // 控制台获取题解 Markdown 源码
  527. function getMarkdown() {
  528. const node = document.querySelector('div[class*="ContentContainer"]');
  529. const key = Object.keys(node).find(key=>{
  530. return key.startsWith("__reactEventHandlers$");
  531. });
  532. console.log(node[key].children[0].props.children);
  533. }
  534. globalThis.unsafeWindow.getMarkdown = getMarkdown;
  535. break;
  536. case 's.taobao.com':
  537. GM_addStyle(`
  538. .grid-total .grid-right {display: none !important;}
  539. .grid-total .grid-left {width: unset !important;}
  540. li#J_FeedbackExperience {display: none;}
  541. `);
  542. break;
  543. case 'mooc1.chaoxing.com':
  544. case 'chaoxing.com':
  545. GM_addStyle(`#edui1_iframeholder{height:530px !important;}`);
  546. break;
  547. case 'scholar.google.com':
  548. GM_addStyle(`
  549. .donate{display:none !important;}
  550. #arovswmd_panel{display:none;}
  551. #gs_hdr{margin:unset !important;}
  552. `);
  553. break;
  554. case 'www.dlsite.com':
  555. GM_addStyle('h1#work_name{user-select: text !important;} body{overflow-y: initial !important;}');
  556. break;
  557. case 'preactjs.com':
  558. GM_addStyle(`
  559. header > div[class^='banner'] , header > a[class^='corner'] { display: none !important; }
  560. #app > main { padding-top: 3.5rem; }
  561. #app > main > div[class^=tutorial] { top: 3.5rem; }
  562. #app > main > div[class^=repl] { top: 3.5rem; }
  563. `);
  564. break;
  565. case 'react.dev':
  566. function zhReact(event) {
  567. event.preventDefault();
  568. let url = location.href.replace('://react', '://zh-hans.react');
  569. location.href = url;
  570. } // 跳转到中文对应页面
  571. document.querySelector('a[href="/community/translations"]').addEventListener("click", zhReact);
  572. break;
  573. case 'www.photopea.com': {
  574. // code from https://chrome.google.com/webstore/detail/remove-ads-from-photopea/gjkjjhgjcalgefcimahpbacihndicccn
  575. GM_addStyle('.app > div:not(:first-child) { visibility: hidden; }');
  576. function addCustomEvent() {
  577. const ADS_WIDTH = window.screen.width < 1180 ? 180 : 320;
  578. document.addEventListener('resizecanvas', () => {
  579. // push the ads container outside of the viewport
  580. window.innerWidth = document.documentElement.clientWidth + ADS_WIDTH;
  581. });
  582. }
  583. // inject our custom event listener into the "main world"
  584. document.documentElement.setAttribute('onreset', `(${addCustomEvent})()`);
  585. document.documentElement.dispatchEvent(new CustomEvent('reset'));
  586. document.documentElement.removeAttribute('onreset');
  587. function resize(event = {}) {
  588. if (!event.skip) {
  589. document.dispatchEvent(new CustomEvent('resizecanvas'));
  590.  
  591. // trigger another resize event to update any listeners with the new window.innerWidth
  592. const resizeEvent = new Event('resize');
  593. resizeEvent.skip = true;
  594. window.dispatchEvent(resizeEvent);
  595. }
  596. }
  597. let debounce;
  598. window.addEventListener('resize', event => {
  599. clearTimeout(debounce);
  600. debounce = setTimeout(() => resize(event), 100);
  601. });
  602. resize();
  603. break;
  604. }
  605. case 'www.phind.com':
  606. GM_addStyle(`body {overflow-y: initial !important;}`);
  607. let engines = localStorage.getItem('userSearchRules') || null;
  608. if (!engines) {
  609. localStorage.setItem('userSearchRules', '{"developer.mozilla.org":3,"github.com":2,"stackoverflow.com":2,"www.reddit.com":-1,\
  610. "www.quora.com":-2,"www.pinterest.com":-3,"wikipedia.com":1,"numpy.org":1,"vuejs.org":1,"reactjs.org":1,"csdn.net":-2}');
  611. }
  612. break;
  613. case 'hd.nowcoder.com':
  614. const link = location.href.split('?target=')[1];
  615. location.href = link;
  616. break;
  617. case 'basarat.gitbook.io':
  618. GM_addStyle(`
  619. html {overflow: visible !important;}
  620. div.gitbook-root > div > div > header {height: 3.9rem;}
  621. div.gitbook-root > div header a[href^="https://youtube.com"] {display:none;}
  622. div.gitbook-root > div header a[href^="https://www.udemy.com"] {display:none;}
  623. div.gitbook-root div[data-testid="page.desktopTableOfContents"] {top: 62px !important; height: calc(100vh - 64px) !important;}
  624. `)
  625. break;
  626. case 'www.cesium.xin':
  627. GM_addStyle(`
  628. code[class*="language-"] { white-space: inherit; }
  629. footer { padding: 6px; }
  630. `);
  631. break;
  632. case 'message.bilibili.com':
  633. const callback = function(mutationList, observer) {
  634. if (document.querySelector('div.right .dialog:not(.hide)')) {
  635. const el = document.querySelector('div.right .dialog:not(.hide)')
  636. const mid = el.__vue__.userInfo.mid;
  637. if (mid) {
  638. el.querySelector('.title span').onclick = function() {
  639. window.open(`https://space.bilibili.com/${mid}/video`);
  640. }
  641. }
  642. }
  643. }
  644. const observer = new MutationObserver(callback);
  645. observer.observe(document.body, { childList: true, subtree: true });
  646. GM_addStyle(`
  647. div.right .dialog .title span { padding: 8px; cursor: pointer; }
  648. div.right .dialog .title span:hover { text-decoration: underline; }
  649. `);
  650. break;
  651. case 'pan.baidu.com':
  652. setInterval(() => {
  653. const el = document.querySelector('input#accessCode');
  654. if (el && el.value.length === 4) document.querySelector('#submitBtn').click();
  655. }, 1000)
  656. break;
  657. case 'x.com':
  658. const linkElement = document.createElement('link');
  659. linkElement.rel = 'shortcut icon';
  660. linkElement.href = '//abs.twimg.com/favicons/twitter.ico';
  661. document.head.appendChild(linkElement);
  662. break;
  663. case 'nextjs.org':
  664. GM_addStyle(`
  665. main > div.relative { padding-top: 1rem; }
  666. main > div.relative > div.sticky { top: 5rem; }
  667. main > div.relative > nav > .sticky { top: 6.5rem; }
  668. `);
  669. break;
  670. default:
  671. break;
  672. }
  673. const aliList = [
  674. /^https:.+tmall.com\//,
  675. /^https:.+taobao.com\//,
  676. ];
  677. aliList.forEach((i) => {
  678. if (i.test(document.location.href)) {
  679. // 移除阴间字体 arial
  680. GM_addStyle('span,input,li,div,a{font-family:none;}');
  681. }
  682. });
  683. if (/.*sci-hub.+/.test(location.hostname)) {
  684. GM_addStyle('#rollback img{width:50px !important;height:50px;margin-left:12px;}');
  685. };
  686. if (location.hostname.endsWith('.xiaoeknow.com')) {
  687. document.addEventListener('keyup', function (e) {
  688. const video = document.querySelector('video');
  689. if (!video) return;
  690. if (e.key === ' ' && video.paused) {
  691. video.play();
  692. } else if (e.key === ' ') {
  693. video.pause();
  694. }
  695. if (e.key === 'f') {
  696. document.querySelector('.fullBtn').click();
  697. }
  698. if (e.key === 'ArrowLeft') {
  699. video.currentTime = video.currentTime - 5;
  700. } else if (e.key === 'ArrowRight') {
  701. video.currentTime = video.currentTime + 5;
  702. }
  703. }); // 快捷键控制视频
  704. }
  705. })();