Guest User

Untitled

a guest
Jan 17th, 2026
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.02 KB | None | 0 0
  1. // ==UserScript==
  2. // @name ElitePvpers Dark Mode
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.56
  5. // @description elitepvpers dark mode
  6. // @author 0x41^4
  7. // @match *://*.elitepvpers.com/*
  8. // @run-at document-start
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. const DARK_BG = '#2d2d2d';
  16. const DARK_BG_2 = '#262626';
  17. const DARK_TEXT = '#e0e0e0';
  18. const BORDER = '#404040';
  19.  
  20. const IS_TBM = location.pathname.startsWith('/theblackmarket/');
  21.  
  22. // Redirect pages are /link/?https://...
  23. const IS_REDIRECT =
  24. location.pathname === '/link/' ||
  25. location.pathname.startsWith('/link') ||
  26. location.pathname.includes('/redirect-to/');
  27.  
  28. // Private messages (PM pages)
  29. const IS_PM = location.pathname.includes('private.php');
  30.  
  31. // Profile pages
  32. const IS_PROFILE =
  33. location.pathname.includes('member.php') ||
  34. location.pathname.includes('profile.php') ||
  35. location.pathname.includes('/members/');
  36.  
  37. // Edit post page (your white border repro)
  38. const IS_EDITPOST =
  39. location.pathname.includes('editpost.php') ||
  40. location.search.includes('do=updatepost') ||
  41. location.search.includes('do=editpost');
  42.  
  43. // Home page (https://www.elitepvpers.com/)
  44. const IS_HOME =
  45. location.pathname === '/' &&
  46. !location.pathname.startsWith('/forum/') &&
  47. !location.pathname.startsWith('/theblackmarket/');
  48.  
  49. /* =====================
  50. EARLY ANTI-FOUC (FIRST PAINT)
  51. ===================== */
  52. function injectAntiFlashCSS() {
  53. if (document.getElementById('ep-darkmode-antiflash')) return;
  54.  
  55. const style = document.createElement('style');
  56. style.id = 'ep-darkmode-antiflash';
  57. style.textContent = `
  58. html { background-color: #1e1e1e !important; }
  59. body { background-color: ${DARK_BG_2} !important; color: ${DARK_TEXT} !important; }
  60.  
  61. /* Kill the bar that flashes white */
  62. div[style="padding-top:8px"],
  63. div[style^="padding-top:8px"],
  64. div[style*="padding-top:8px"] {
  65. background-color: ${DARK_BG_2} !important;
  66. background-image: none !important;
  67. }
  68.  
  69. /* Postbit/TBM user info bars flashing white (first paint)
  70. Safe: only background/border, does not touch text colors */
  71. .postbar {
  72. background-color: ${DARK_BG} !important;
  73. background-image: none !important;
  74. border-color: ${BORDER} !important;
  75. }
  76.  
  77. /* Remove the white content shadow strip early */
  78. #contentshadowwhite {
  79. background-image: none !important;
  80. background-color: ${DARK_BG_2} !important;
  81. height: 8px !important;
  82. border-top: 1px solid #3a3a3a !important;
  83. }
  84.  
  85. /* Redirect page title bars early */
  86. .cwtitle1h, .cwtitlehead, .cwtitle1f {
  87. background-color: ${DARK_BG} !important;
  88. background-image: none !important;
  89. border-color: ${BORDER} !important;
  90. color: ${DARK_TEXT} !important;
  91. }
  92. `;
  93.  
  94. document.documentElement.prepend(style);
  95. }
  96.  
  97. const baseCss = `
  98. /* =====================
  99. BASE
  100. ===================== */
  101. html { background-color: #1e1e1e !important; }
  102. body { background-color: ${DARK_BG_2} !important; color: ${DARK_TEXT} !important; }
  103.  
  104. /* =====================
  105. CORE CONTENT (TARGETED)
  106. ===================== */
  107. section, article, aside, main,
  108. .alt1, .alt2, .alt3, .alt4,
  109. .panel, .panelsurround,
  110. .tcat, .thead, .tfoot,
  111. .page, .vbmenu_control {
  112. background-color: ${DARK_BG} !important;
  113. background-image: none !important;
  114. color: ${DARK_TEXT} !important;
  115. }
  116.  
  117. table.tborder,
  118. table.tborder tr,
  119. table.tborder td,
  120. table.tborder th {
  121. background-color: ${DARK_BG} !important;
  122. background-image: none !important;
  123. color: ${DARK_TEXT} !important;
  124. }
  125.  
  126. .forumbit_nopost, .forumbit_post,
  127. .forumrow, .foruminfo, .forumdata,
  128. .threadbit, .postbit, .posthead, .postcontent,
  129. .blockrow, .blockbody, .blockhead {
  130. background-color: ${DARK_BG} !important;
  131. background-image: none !important;
  132. color: ${DARK_TEXT} !important;
  133. }
  134.  
  135. /* =====================
  136. HEADER / NAV
  137. ===================== */
  138. #header, #headerbg, .header {
  139. background-color: #272727 !important;
  140. border-bottom: 1px solid #3a3a3a !important;
  141. }
  142.  
  143. #navbar, .navbar, #navtabs, .navtabs {
  144. background-color: #2a2a2a !important;
  145. border-top: 1px solid #3a3a3a !important;
  146. border-bottom: 1px solid #3a3a3a !important;
  147. box-shadow: 0 1px 0 rgba(0,0,0,0.35) !important;
  148. }
  149.  
  150. #subnavbar, .subnavbar, #navlinks, .navlinks {
  151. background-color: ${DARK_BG_2} !important;
  152. border-bottom: 1px solid #3a3a3a !important;
  153. }
  154.  
  155. .navtab, .navtab a, .navtabs li a,
  156. #navbar a, #navtabs a {
  157. background-color: #2f2f2f !important;
  158. border: 1px solid #3b3b3b !important;
  159. border-bottom-color: #2a2a2a !important;
  160. border-radius: 3px !important;
  161. padding: 6px 10px !important;
  162. margin: 0 4px !important;
  163. }
  164.  
  165. .navtab a:hover, .navtabs li a:hover,
  166. #navbar a:hover, #navtabs a:hover {
  167. background-color: #343434 !important;
  168. border-color: #4a4a4a !important;
  169. }
  170.  
  171. .navtab.selected a, .navtab.active a, .navtab.current a,
  172. .navtabs li.selected a, .navtabs li.active a, .navtabs li.current a {
  173. background-color: #3a3a3a !important;
  174. border-color: #5a5a5a !important;
  175. }
  176.  
  177. /* Remove the white content shadow strip */
  178. #contentshadowwhite {
  179. background-image: none !important;
  180. background-color: ${DARK_BG_2} !important;
  181. height: 8px !important;
  182. border-top: 1px solid #3a3a3a !important;
  183. }
  184.  
  185. /* =====================
  186. DROPDOWNS / POPUPS
  187. ===================== */
  188. .vbmenu_popup,
  189. .popupmenu,
  190. .popupbody {
  191. background-color: ${DARK_BG} !important;
  192. background-image: none !important;
  193. color: ${DARK_TEXT} !important;
  194. border: 1px solid ${BORDER} !important;
  195. }
  196.  
  197. .vbmenu_popup a,
  198. .popupmenu a,
  199. .popupbody a { color: #6eb5ff !important; }
  200. .vbmenu_popup a:hover,
  201. .popupmenu a:hover,
  202. .popupbody a:hover { color: #8fc7ff !important; }
  203.  
  204. .vbmenu_option,
  205. .vbmenu_option td { background-color: ${DARK_BG} !important; color: ${DARK_TEXT} !important; }
  206.  
  207. .vbmenu_hilite,
  208. .vbmenu_hilite td { background-color: #343434 !important; color: ${DARK_TEXT} !important; }
  209.  
  210. /* Keep color palette working */
  211. .ocolor div { border: 1px solid #ACA899 !important; }
  212.  
  213. /* =====================
  214. LINKS
  215. ===================== */
  216. a:not([style*="color"]) { color: #6eb5ff !important; }
  217. a:not([style*="color"]):hover { color: #8fc7ff !important; }
  218. a:not([style*="color"]):visited { color: #6eb5ff !important; }
  219. a[href*="showthread.php"]:not([style*="color"]):visited { color: #bb86fc !important; }
  220.  
  221. /* Elite usergroup thread titles (inline BlueViolet -> dark-mode friendly) */
  222. a[style*="BlueViolet" i],
  223. a[style*="blueviolet" i] { color: #c79bff !important; }
  224.  
  225. /* Revert all other inline-colored links (prevents default #0000EE) */
  226. a[style*="color"]:not([style*="BlueViolet" i]):not([style*="blueviolet" i]) {
  227. color: revert !important;
  228. }
  229.  
  230. /* =====================
  231. INPUTS
  232. IMPORTANT: do NOT style the search input/button at all
  233. ===================== */
  234. input:not(.searchbtn):not(.searchinput),
  235. textarea,
  236. select {
  237. background-color: #3a3a3a !important;
  238. color: ${DARK_TEXT} !important;
  239. border-color: ${BORDER} !important;
  240. }
  241.  
  242. /* =====================
  243. FIX: Editor toolbar hover turning white
  244. ===================== */
  245. #vB_Editor_001_controls .imagebutton,
  246. #vB_Editor_QR_controls .imagebutton,
  247. .vBulletin_editor .controlbar .imagebutton,
  248. .vBulletin_editor .editor_toolbar .imagebutton,
  249. .editor_toolbar .imagebutton {
  250. background: #2f2f2f !important;
  251. background-color: #2f2f2f !important;
  252. color: ${DARK_TEXT} !important;
  253. border: none !important;
  254. padding: 1px !important;
  255. }
  256.  
  257. #vB_Editor_001_controls .imagebutton:hover,
  258. #vB_Editor_QR_controls .imagebutton:hover,
  259. .vBulletin_editor .controlbar .imagebutton:hover,
  260. .vBulletin_editor .editor_toolbar .imagebutton:hover,
  261. .editor_toolbar .imagebutton:hover,
  262. #vB_Editor_001_controls .imagebutton:active,
  263. #vB_Editor_QR_controls .imagebutton:active,
  264. .vBulletin_editor .controlbar .imagebutton:active,
  265. .vBulletin_editor .editor_toolbar .imagebutton:active,
  266. .editor_toolbar .imagebutton:active,
  267. #vB_Editor_001_controls .imagebutton:focus,
  268. #vB_Editor_QR_controls .imagebutton:focus,
  269. .vBulletin_editor .controlbar .imagebutton:focus,
  270. .vBulletin_editor .editor_toolbar .imagebutton:focus,
  271. .editor_toolbar .imagebutton:focus {
  272. background: #343434 !important;
  273. background-color: #343434 !important;
  274. color: ${DARK_TEXT} !important;
  275. outline: none !important;
  276. }
  277.  
  278. /* Borders (only affects elements that already have borders) */
  279. table, tr, th, td:not(.postbar td) { border-color: ${BORDER} !important; }
  280.  
  281. /* =====================
  282. PATCH: white outer borders on Edit Post (tborder/panelsurround)
  283. ===================== */
  284. table.tborder { border-color: ${BORDER} !important; }
  285.  
  286. td.panelsurround,
  287. td.panelsurround > .panel,
  288. td.panelsurround > table,
  289. td.panelsurround table.tborder {
  290. border-color: ${BORDER} !important;
  291. outline: none !important;
  292. box-shadow: none !important;
  293. background-image: none !important;
  294. }
  295.  
  296. table.tborder,
  297. td.panelsurround,
  298. .panel,
  299. .panelsurround {
  300. box-shadow: none !important;
  301. }
  302.  
  303. #contentbg,
  304. #footerbg,
  305. #footerbgend {
  306. background-image: none !important;
  307. border-color: ${BORDER} !important;
  308. }
  309.  
  310. fieldset,
  311. fieldset legend {
  312. border-color: ${BORDER} !important;
  313. outline: none !important;
  314. box-shadow: none !important;
  315. }
  316.  
  317. ${IS_EDITPOST ? `
  318. form[action*="editpost.php"] table.tborder { border: 1px solid ${BORDER} !important; }
  319. form[action*="editpost.php"] td.panelsurround { border: 1px solid ${BORDER} !important; }
  320. ` : ''}
  321.  
  322. /* Scrollbar (Chrome) */
  323. ::-webkit-scrollbar { background-color: #1e1e1e !important; }
  324. ::-webkit-scrollbar-thumb { background-color: ${BORDER} !important; }
  325.  
  326. /* =====================
  327. elite*gold ticker banner
  328. ===================== */
  329. .ticker {
  330. background-color: ${DARK_BG} !important;
  331. background-image: none !important;
  332. color: ${DARK_TEXT} !important;
  333. border: 1px solid ${BORDER} !important;
  334. }
  335.  
  336. #tickermessages,
  337. .tickermessages,
  338. .tickermessages li,
  339. .tickermessages li div,
  340. #tickermessages > li,
  341. #tickermessages > li > div {
  342. background-color: ${DARK_BG} !important;
  343. background-image: none !important;
  344. color: ${DARK_TEXT} !important;
  345. }
  346.  
  347. .tickermessages a { color: #6eb5ff !important; }
  348. .tickermessages a:hover { color: #8fc7ff !important; }
  349.  
  350. /* =====================
  351. Quick Reply / Reply Editor outline fix (scoped)
  352. ===================== */
  353. #quickreply,
  354. #quickreply .tborder,
  355. #quickreply .panel,
  356. #quickreply .panelsurround,
  357. #quickreply fieldset,
  358. #quickreply fieldset legend {
  359. border-color: ${BORDER} !important;
  360. background-image: none !important;
  361. outline: none !important;
  362. box-shadow: none !important;
  363. }
  364.  
  365. form[action*="newreply.php"] .tborder,
  366. form[action*="newreply.php"] .panel,
  367. form[action*="newreply.php"] .panelsurround,
  368. form[action*="newreply.php"] fieldset,
  369. form[action*="newreply.php"] fieldset legend {
  370. border-color: ${BORDER} !important;
  371. background-image: none !important;
  372. outline: none !important;
  373. box-shadow: none !important;
  374. }
  375.  
  376. /* =====================
  377. New Reply editor border
  378. ===================== */
  379. #vB_Editor_001,
  380. #vB_Editor_001 .controlbar,
  381. #vB_Editor_001_controls,
  382. #vB_Editor_001 table,
  383. #vB_Editor_001 td,
  384. #vB_Editor_001 fieldset {
  385. border-color: ${BORDER} !important;
  386. background-image: none !important;
  387. }
  388. #vB_Editor_001 {
  389. border: 1px solid ${BORDER} !important;
  390. background-color: ${DARK_BG} !important;
  391. color: ${DARK_TEXT} !important;
  392. }
  393.  
  394. /* =====================
  395. PATCH: remove extra outlines around Quick Reply + PM delete message box
  396. ===================== */
  397. #quickreply, #quickreply *,
  398. .quick_reply, .quick_reply *,
  399. .quick_reply_controls, .quick_reply_controls *,
  400. #vB_Editor_QR, #vB_Editor_QR *,
  401. #vB_Editor_001, #vB_Editor_001 * {
  402. outline: none !important;
  403. box-shadow: none !important;
  404. }
  405.  
  406. #quickreply,
  407. .quick_reply,
  408. .quick_reply_controls,
  409. .floatcontainer.quick_reply_controls { border: none !important; }
  410.  
  411. #vB_Editor_QR,
  412. #vB_Editor_001 {
  413. border: 1px solid ${BORDER} !important;
  414. background-color: ${DARK_BG} !important;
  415. background-image: none !important;
  416. }
  417.  
  418. #vB_Editor_QR .controlbar,
  419. #vB_Editor_QR table,
  420. #vB_Editor_QR td,
  421. #vB_Editor_QR fieldset,
  422. #vB_Editor_QR textarea,
  423. #vB_Editor_001 .controlbar,
  424. #vB_Editor_001 table,
  425. #vB_Editor_001 td,
  426. #vB_Editor_001 fieldset,
  427. #vB_Editor_001 textarea {
  428. border: none !important;
  429. box-shadow: none !important;
  430. outline: none !important;
  431. }
  432.  
  433. td.panelsurround,
  434. td.panelsurround > .panel,
  435. td.panelsurround .panel {
  436. outline: none !important;
  437. box-shadow: none !important;
  438. }
  439. `;
  440.  
  441. const tbmCss = `
  442. .cwalt {
  443. background-color: ${DARK_BG} !important;
  444. background-image: none !important;
  445. color: ${DARK_TEXT} !important;
  446. border-color: ${BORDER} !important;
  447. }
  448. .cwalt * { border-color: ${BORDER} !important; }
  449. .cwalt table,
  450. .cwalt tr,
  451. .cwalt td,
  452. .cwalt th {
  453. background-color: ${DARK_BG} !important;
  454. background-image: none !important;
  455. color: ${DARK_TEXT} !important;
  456. }
  457. `;
  458.  
  459. const redirectCss = `
  460. .cwalt,
  461. .cw1h,
  462. .cwhead,
  463. .cwtitle1h,
  464. .cwtitlehead,
  465. .cwtitle1f,
  466. .cbtitle1h,
  467. .cbtitlehead,
  468. .cbtitle1f {
  469. background-color: ${DARK_BG} !important;
  470. background-image: none !important;
  471. color: ${DARK_TEXT} !important;
  472. border-color: ${BORDER} !important;
  473. }
  474.  
  475. .cwalt table,
  476. .cwalt tr,
  477. .cwalt td,
  478. .cwalt th {
  479. background-color: ${DARK_BG} !important;
  480. background-image: none !important;
  481. color: ${DARK_TEXT} !important;
  482. border-color: ${BORDER} !important;
  483. }
  484.  
  485. input[type="text"],
  486. input[type="url"] {
  487. background-color: #3a3a3a !important;
  488. color: ${DARK_TEXT} !important;
  489. border: 1px solid ${BORDER} !important;
  490. }
  491. `;
  492.  
  493. const pmCss = `
  494. fieldset.fieldset,
  495. fieldset.fieldset legend,
  496. fieldset.fieldset table,
  497. fieldset.fieldset td,
  498. fieldset.fieldset th,
  499. fieldset.fieldset .tborder,
  500. fieldset.fieldset table[style*="groove"],
  501. fieldset.fieldset table[style*="border:2px groove"],
  502. fieldset.fieldset table[style*="border: 2px groove"] {
  503. border-color: ${BORDER} !important;
  504. }
  505.  
  506. td.panelsurround,
  507. td.panelsurround > table,
  508. td.panelsurround table,
  509. td.panelsurround .panel,
  510. td.panelsurround .panelsurround,
  511. td.panelsurround .tborder,
  512. td.panelsurround td,
  513. td.panelsurround th {
  514. border-color: ${BORDER} !important;
  515. outline: none !important;
  516. box-shadow: none !important;
  517. }
  518.  
  519. td.panelsurround .tborder,
  520. td.panelsurround table.tborder {
  521. border: 1px solid ${BORDER} !important;
  522. }
  523. `;
  524.  
  525. const profileCss = `
  526. .block_row,
  527. .block_footer,
  528. .block_head,
  529. .blockbody,
  530. .blocksubhead,
  531. .blocktitle,
  532. .block,
  533. .block_container,
  534. .member_block {
  535. border-color: ${BORDER} !important;
  536. }
  537.  
  538. .block_row.alt1,
  539. .block_row.alt2,
  540. .block_footer.alt1,
  541. .block_footer.alt2 {
  542. background-color: ${DARK_BG} !important;
  543. background-image: none !important;
  544. color: ${DARK_TEXT} !important;
  545. }
  546.  
  547. .memberinfo_tiny {
  548. border-color: ${BORDER} !important;
  549. box-shadow: none !important;
  550. outline: none !important;
  551. }
  552.  
  553. .block_row *:not(img):not(svg):not(canvas),
  554. .block_footer *:not(img):not(svg):not(canvas),
  555. .memberinfo_tiny *:not(img):not(svg):not(canvas) {
  556. border-color: ${BORDER} !important;
  557. }
  558. `;
  559.  
  560. const homeCss = `
  561. /* =====================
  562. HOME PAGE ONLY ( / )
  563. ===================== */
  564.  
  565. /* Main news wrapper is cwalt and is basically the whole white page */
  566. .cwalt {
  567. background-color: ${DARK_BG} !important;
  568. background-image: none !important;
  569. color: ${DARK_TEXT} !important;
  570. border-color: ${BORDER} !important;
  571. }
  572.  
  573. /* News item tables */
  574. table.cwnewsitem,
  575. table.cwnewsitem tr,
  576. table.cwnewsitem td {
  577. background-color: ${DARK_BG} !important;
  578. background-image: none !important;
  579. color: ${DARK_TEXT} !important;
  580. border-color: ${BORDER} !important;
  581. }
  582.  
  583. /* Some parts use a slightly different background */
  584. .cwnewsimg,
  585. .cwnewsdate,
  586. .cwtaglist {
  587. background-color: ${DARK_BG} !important;
  588. background-image: none !important;
  589. color: ${DARK_TEXT} !important;
  590. }
  591.  
  592. /* Headlines / text */
  593. table.cwnewsitem h3,
  594. table.cwnewsitem p {
  595. color: ${DARK_TEXT} !important;
  596. }
  597.  
  598. /* If the homepage uses separators/lines via background images, kill them */
  599. table.cwnewsitem,
  600. table.cwnewsitem td {
  601. box-shadow: none !important;
  602. outline: none !important;
  603. }
  604.  
  605. /* Make sure any "white cell" inside cwalt gets darkened */
  606. .cwalt td,
  607. .cwalt th,
  608. .cwalt div,
  609. .cwalt p,
  610. .cwalt h1,
  611. .cwalt h2,
  612. .cwalt h3,
  613. .cwalt h4,
  614. .cwalt ul,
  615. .cwalt li {
  616. background-image: none !important;
  617. color: ${DARK_TEXT} !important;
  618. border-color: ${BORDER} !important;
  619. }
  620. `;
  621.  
  622. function injectCSS() {
  623. const old = document.getElementById('ep-darkmode-style');
  624. if (old) old.remove();
  625.  
  626. const style = document.createElement('style');
  627. style.id = 'ep-darkmode-style';
  628. style.textContent =
  629. baseCss +
  630. (IS_TBM ? tbmCss : '') +
  631. (IS_REDIRECT ? redirectCss : '') +
  632. (IS_PM ? pmCss : '') +
  633. (IS_PROFILE ? profileCss : '') +
  634. (IS_HOME ? homeCss : '');
  635.  
  636. (document.head || document.documentElement).appendChild(style);
  637. }
  638.  
  639. // --- Smart “light background” fixer ---
  640. function parseRGB(str) {
  641. const m = str.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([0-9.]+))?\)/i);
  642. if (!m) return null;
  643. return { r: +m[1], g: +m[2], b: +m[3], a: m[4] === undefined ? 1 : +m[4] };
  644. }
  645.  
  646. function luminance({ r, g, b }) {
  647. return (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
  648. }
  649.  
  650. function hasVisibleBorder(cs) {
  651. if (!cs) return false;
  652. const styles = [cs.borderTopStyle, cs.borderRightStyle, cs.borderBottomStyle, cs.borderLeftStyle];
  653. const widths = [
  654. parseFloat(cs.borderTopWidth) || 0,
  655. parseFloat(cs.borderRightWidth) || 0,
  656. parseFloat(cs.borderBottomWidth) || 0,
  657. parseFloat(cs.borderLeftWidth) || 0
  658. ];
  659.  
  660. for (let i = 0; i < 4; i++) {
  661. const st = (styles[i] || '').toLowerCase();
  662. if (widths[i] > 0 && st !== 'none' && st !== 'hidden') return true;
  663. }
  664. return false;
  665. }
  666.  
  667. function shouldExclude(el) {
  668. if (!el || el.nodeType !== 1) return true;
  669.  
  670. if (el.closest('.ocolor')) return true;
  671.  
  672. if (el.closest('#header') || el.closest('#headerbg') || el.closest('.headerbg')) return true;
  673. if (el.closest('#userbarbg')) return true;
  674. if (el.closest('form#searchform') || el.closest('.searchbox')) return true;
  675.  
  676. if (el.classList && el.classList.contains('imagebutton')) return true;
  677. if (el.closest && el.closest('.imagebutton')) return true;
  678.  
  679. if (el.tagName === 'IMG' || el.tagName === 'SVG' || el.tagName === 'CANVAS') return true;
  680.  
  681. return false;
  682. }
  683.  
  684. function darkenIfLight(el) {
  685. if (shouldExclude(el)) return;
  686.  
  687. const cs = getComputedStyle(el);
  688. if (!cs) return;
  689.  
  690. if (cs.backgroundImage && cs.backgroundImage !== 'none') return;
  691.  
  692. const bg = parseRGB(cs.backgroundColor);
  693. if (!bg || bg.a < 0.1) return;
  694.  
  695. if (luminance(bg) < 0.85) return;
  696.  
  697. el.style.setProperty('background-color', DARK_BG, 'important');
  698. el.style.setProperty('background-image', 'none', 'important');
  699.  
  700. const fg = parseRGB(cs.color);
  701. if (fg && luminance(fg) < 0.4) {
  702. el.style.setProperty('color', DARK_TEXT, 'important');
  703. }
  704.  
  705. if (hasVisibleBorder(cs)) {
  706. el.style.setProperty('border-color', BORDER, 'important');
  707. }
  708. }
  709.  
  710. function scanAndFix(root) {
  711. const scope = root && root.querySelectorAll ? root : document;
  712. const candidates = scope.querySelectorAll('div, td, th, table, fieldset, dl, dd, dt, ul, li, p, section, article');
  713. for (const el of candidates) darkenIfLight(el);
  714. }
  715.  
  716. function startObserver() {
  717. const obs = new MutationObserver((mutations) => {
  718. for (const m of mutations) {
  719. for (const node of m.addedNodes) {
  720. if (node && node.nodeType === 1) scanAndFix(node);
  721. }
  722. }
  723. });
  724. obs.observe(document.documentElement, { childList: true, subtree: true });
  725. }
  726.  
  727. // boot
  728. injectAntiFlashCSS();
  729. injectCSS();
  730. if (!document.head) document.addEventListener('DOMContentLoaded', injectCSS, { once: true });
  731.  
  732. document.addEventListener(
  733. 'DOMContentLoaded',
  734. () => {
  735. scanAndFix(document);
  736. startObserver();
  737. },
  738. { once: true }
  739. );
  740. })();
Advertisement
Add Comment
Please, Sign In to add comment