LynxChan Extended Minus Minus

LynxChan Extended with even more features

安装此脚本
作者推荐脚本

您可能也喜欢8chan-buffs

安装此脚本
  1. // ==UserScript==
  2. // @name LynxChan Extended Minus Minus
  3. // @namespace https://rentry.org/8chanMinusMinus
  4. // @version 2.3.13
  5. // @description LynxChan Extended with even more features
  6. // @author SaddestPanda & Dandelion & /gfg/
  7. // @license UNLICENSE
  8. // @match *://8chan.moe/*
  9. // @match *://8chan.se/*
  10. // @match *://8chan.cc/*
  11. // @grant GM.getValue
  12. // @grant GM.setValue
  13. // @grant GM.deleteValue
  14. // @grant GM.registerMenuCommand
  15. // @run-at document-start
  16. // ==/UserScript==
  17.  
  18. //TODO LATER MAYBE: combine all CSS into one <style> and use classes on html or body instead.
  19. (async function () {
  20. "use strict";
  21.  
  22. const REGEX_THREAD = /\/res|last\//;
  23. const SETTINGS_DEFINITIONS = {
  24. firstRun:{
  25. default:true,
  26. hidden:true,
  27. desc:"You shouldn't be able to see this setting! (firstRun)"
  28. },
  29. addKeyboardHandlers:{
  30. default:true,
  31. desc:"Add keyboard Ctrl+ hotkeys to the quick reply box (Disable this for 8chanSS compatibility)"
  32. },
  33. showScrollbarMarkers:{
  34. default:true,
  35. type:"checkbox_with_colors",
  36. desc:"Show your posts and replies on the scrollbar",
  37. color1Default:"#0092ff",
  38. color1Desc:"<b>Your marker:</b>",
  39. color2Default:"#a8d8f8",
  40. color2Desc:"<b>Reply marker:</b>"
  41. },
  42. spoilerImageType:{
  43. default:"off",
  44. desc:"Override how the spoiler thumbnail looks:",
  45. type:"radio",
  46. options:{
  47. off:"Don't change the thumbnail.",
  48. reveal:"Reveal spoilers <span class='altText lineBefore'>(Previously spoilered images will have a red border around them indicating that they're spoilers.)</span>",
  49. reveal_blur:"Change to a blurred thumbnail <span class='altText lineBefore'>(Unblurred when you hover your mouse over.)</span>",
  50. kachina:"Makes the spoiler image Kachina from Genshin Impact.",
  51. thread:`<b>Use <b style="color: var(--link-color);">"ThreadSpoiler.jpg"</b> from the current thread <span class="altText lineBefore">(first posted jpg, png or webp image with that filename)</span></b>`,
  52. threadAlt:`same as above with the filename <b style="color: var(--link-color);">"ThreadSpoilerAlt.jpg"</b> <span class="altText lineBefore">(jpg, png or webp; uses ThreadSpoiler.jpg until this is found)</span>`,
  53. //test:`[TEST OPTION] Set custom spoiler thumb per-thread (For /gacha/ only!)`
  54. },
  55. nonewline:true
  56. },
  57. overrideBoardSpoilerImage: {
  58. default:true,
  59. parent:"spoilerImageType",
  60. //Not implemented yet
  61. //depends: function() {return settings.spoilerImageType != "off"},
  62. desc:"Also override board's custom thumbnail image <span class='altText lineBefore'>(for example, /v/'s spoiler thumbnail is an image of a monitor with a ? inside it)</span>"
  63. },
  64. revealSpoilerText:{
  65. default:"off",
  66. desc:"Reveal the spoiler text. Or make it into madoka runes.",
  67. type:"radio",
  68. options:{
  69. off:"Don't reveal spoilers.",
  70. on:"Spoilers will be always be shown by turning the text white.",
  71. madoka:`Spoilers will turn into madoka runes. Please install <a href="https://www.dropbox.com/s/n6ys414nviitr9y/MadokaRunes-2.0.ttf"><u>MadokaRunes.ttf</u></a> for it to show up properly.`
  72. }
  73. },
  74. markPostEdge:{
  75. default:true,
  76. type:"checkbox_with_colors",
  77. desc:"<span class='boldText'>Style:</span> Mark your posts and replies <span class='altText'>(with a left border)</span>",
  78. color1Default:"#4BB2FF",
  79. color1Desc:"<b>Your border:</b>",
  80. color2Default:"#0066ff",
  81. color2Desc:"<b>Reply border:</b>",
  82. nonewline:true
  83. },
  84. markYouText:{
  85. default:true,
  86. type:"checkbox_with_colors",
  87. desc:"<span class='boldText'>Style:</span> Color your name and (You) links",
  88. color1Default:"#ff2222",
  89. color1Desc:"<b>Color:</b>",
  90. nonewline:true
  91. },
  92. compactPosts:{
  93. default:true,
  94. desc:"<span class='boldText'>Style:</span> Make thumbnails and posts more compact",
  95. nonewline:true
  96. },
  97. showStubs:{
  98. default:true,
  99. desc:"<span class='boldText'>Style:</span> Show post stubs when filtering",
  100. nonewline:true
  101. },
  102. //I swear this used to be a built in option on 8chan
  103. halfchanGreentexts:{
  104. default:false,
  105. desc:"<span class='boldText'>Style:</span> Make the greentext brighter like 4chan"
  106. },
  107. glowFirstPostByID:{
  108. default:true,
  109. type:"checkbox_with_colors",
  110. desc:"Mark new/unique posters by adding a glow effect to their ID",
  111. color1Default:"#26bf47",
  112. color1Desc:"<b>Glow color:</b>",
  113. nonewline:true
  114. },
  115. showPostIndex:{
  116. default:true,
  117. type:"checkbox_with_colors",
  118. desc:"Show the current index of a post on the thread. <span class='altText'>(OP: 1, first post: 2 etc.)</span>",
  119. color1Default:"#7b3bcc",
  120. color1Desc:"<b>Index color:</b>",
  121. nonewline:true
  122. },
  123. showWatcherOnLoad: {
  124. default:false,
  125. desc:'Show the "Watched Threads" popup on page load',
  126. nonewline:true
  127. },
  128. showVideoIcons: {
  129. default:true,
  130. desc:"Distinguish videos, gifs and audio with an icon before the filename"
  131. },
  132. preserveQuickReply:{
  133. default:false,
  134. desc:"Preserve the quick reply text when closing the box or refreshing the page",
  135. nonewline:true
  136. },
  137. preserveName:{
  138. default:false,
  139. desc:"Preserve the last used name between page refreshes"
  140. },
  141. reverseSearchOptions:{
  142. default:{
  143. pixiv:true,
  144. booru:true,
  145. saucenao:true
  146. },
  147. desc:"Reverse image search buttons to show:",
  148. type:"checkbox_multiple_dict", //Maybe "multiple_array" or "bitfield" types allowed in the future
  149. options:{
  150. pixiv:"Pixiv <span class='altText lineBefore'>Shown if the filename matches an image downloaded from Pixiv</span>",
  151. booru:"Gelbooru / Danbooru / Safebooru <span class='altText lineBefore'>Shown if the filename contains an md5 hash</span>",
  152. saucenao:"Saucenao <span class='altText lineBefore'>Always shown, uses JS to download and reupload the image to saucenao</span>"
  153. },
  154. nonewline:true
  155. },
  156. reverseSearchBooruSite:{
  157. desc:"Booru to link if the above option is enabled",
  158. type:"dropdown",
  159. default:"gelbooru",
  160. choices:{
  161. "gelbooru":"https://gelbooru.com/index.php?page=post&s=list&tags=md5%3a",
  162. "danbooru":"https://danbooru.donmai.us/posts?tags=md5%3a",
  163. "safebooru":"https://safebooru.org/index.php?page=post&s=list&tags=md5%3a"
  164. }
  165. }
  166. /*redirectToCatalog:{
  167. default:false,
  168. desc:"Redirect to catalog when clicking on the index."
  169. }*/
  170. }
  171.  
  172. const settingsNames = Object.keys(SETTINGS_DEFINITIONS);
  173.  
  174. //Collect all color fields for checkbox_with_colors settings
  175. //In the userscript storage they look like settingName_color1 etc.
  176. const colorSettingKeys = [];
  177. settingsNames.forEach(key => {
  178. const def = SETTINGS_DEFINITIONS[key];
  179. if (def.type === "checkbox_with_colors") {
  180. Object.keys(def).forEach(k => {
  181. const match = k.match(/^color(\d+)Default$/);
  182. if (match) {
  183. colorSettingKeys.push(`${key}_color${match[1]}`);
  184. }
  185. });
  186. }
  187. });
  188.  
  189. //Compose all keys to load: main settings + color fields
  190. const allSettingKeys = [...settingsNames, ...colorSettingKeys];
  191.  
  192. //For each color field, get its default from the definition
  193. function getDefaultForKey(key) {
  194. const colorMatch = key.match(/^(.+)_color(\d+)$/);
  195. if (colorMatch) {
  196. const [_, base, idx] = colorMatch;
  197. const def = SETTINGS_DEFINITIONS[base];
  198. //Return color setting default like color1Default
  199. return def && def[`color${idx}Default`] ? def[`color${idx}Default`] : undefined;
  200. }
  201. //Return regular setting
  202. return SETTINGS_DEFINITIONS[key]?.default;
  203. }
  204.  
  205. const allSettingDefaults = allSettingKeys.map(getDefaultForKey);
  206. const allSettingValues = await Promise.all(allSettingKeys.map((key, i) => GM.getValue(key, allSettingDefaults[i])));
  207. const settings = Object.fromEntries(allSettingKeys.map((key, i) => [key, allSettingValues[i]]));
  208.  
  209. function addMyStyle(newID, newStyle) {
  210. let myStyle = document.createElement("style");
  211. //myStyle.type = 'text/css';
  212. myStyle.id = newID;
  213. myStyle.textContent = newStyle;
  214. document.head.appendChild(myStyle);
  215. }
  216.  
  217. function waitForDom(callback) {
  218. if (document.readyState === "loading") {
  219. //Loading hasn't finished yet. Wait for the inital document to load and start.
  220. document.addEventListener("DOMContentLoaded", callback);
  221. } else {
  222. //Document has already loaded. Start.
  223. callback();
  224. }
  225. }
  226.  
  227. if (document?.head) {
  228. runASAP();
  229. } else {
  230. //On some environments document.head doesn't exist yet?
  231. waitForDom(runASAP);
  232. }
  233.  
  234. async function runASAP() {
  235. // Migrations can be removed in a few weeks
  236. // Migrations are disabled now. Keeping the code for potential future migrations
  237.  
  238. // // Migrate old useExtraStylingFixes setting if present
  239. // const oldStyling = await GM.getValue("useExtraStylingFixes", undefined);
  240. // if (typeof oldStyling !== "undefined") {
  241. // // If oldStyling is false, set both new options to false
  242. // if (oldStyling === false) {
  243. // settings.markPostEdge = false;
  244. // settings.compactPosts = false;
  245. // await GM.setValue("markPostEdge", false);
  246. // await GM.setValue("compactPosts", false);
  247. // }
  248. // // Remove the old setting
  249. // await GM.deleteValue("useExtraStylingFixes");
  250. // }
  251.  
  252. if (settings.preserveName === false) {
  253. localStorage.removeItem("name");
  254. }
  255.  
  256. //Secret tip for anyone manually editing colors:
  257. //if you edit the saved value in your userscript manager's settings database manually, you can use semi-transparent colors for the color pickers (until you click save on the settings menu).
  258. //or easier: just copy the relevant part of the css and paste it to the css box in the website settings. Add !important if you want to force it like: color: red !important;
  259.  
  260. //Apply all the styles as soon as possible
  261. if (settings.compactPosts) {
  262. addMyStyle("lynx-compact-posts", `
  263. /* smaller thumbnails & image paddings */
  264. body .uploadCell img:not(.imgExpanded) {
  265. max-width: 160px;
  266. max-height: 125px;
  267. object-fit: contain;
  268. height: auto;
  269. width: auto;
  270. margin-right: 0em;
  271. margin-bottom: 0em;
  272. }
  273.  
  274. .uploadCell {
  275. margin-bottom: 0.45em;
  276. }
  277.  
  278. .uploadCell .imgLink {
  279. margin-right: 1em;
  280. }
  281.  
  282. /* smaller post spacing (not too much) */
  283. .divMessage {
  284. margin: .8em .8em .5em 3em;
  285. }
  286.  
  287. /* file details: reduce paddings and icon sizes */
  288. .uploadDetails {
  289. & > * {
  290. vertical-align: top;
  291. font-size: 95%;
  292. }
  293. & > .dimensionLabel {
  294. margin-right: 0.3ch;
  295. }
  296. .coloredIcon {
  297. font-size: 90%;
  298. }
  299. & > a.nameLink {
  300. margin-right: -2.5px;
  301. }
  302. & > span.hideFileButton {
  303. margin-right: -4px;
  304. }
  305. }
  306.  
  307. /* This thing adds an unnecessary line break (only on chrome) */
  308. .uploadCell > details > summary + br {
  309. display: none;
  310. }
  311.  
  312. /* Contain expanded images to the page */
  313. .imgExpanded {
  314. max-height: 100vh;
  315. object-fit: contain;
  316. }
  317.  
  318. `);
  319. }
  320.  
  321. const markerColor1 = settings.showScrollbarMarkers_color1 || SETTINGS_DEFINITIONS.showScrollbarMarkers.color1Default;
  322. const markerColor2 = settings.showScrollbarMarkers_color2 || SETTINGS_DEFINITIONS.showScrollbarMarkers.color2Default;
  323. const indexColor = settings.showPostIndex_color1 || SETTINGS_DEFINITIONS.showPostIndex.color1Default;
  324. const glowColor = settings.glowFirstPostByID_color1 || SETTINGS_DEFINITIONS.glowFirstPostByID.color1Default;
  325. addMyStyle("lynx-extended-css", `
  326. :root {
  327. --showScrollbarMarkers_color1: ${markerColor1};
  328. --showScrollbarMarkers_color2: ${markerColor2};
  329. --showPostIndex_color1: ${indexColor};
  330. --glowFirstPostByID_color1: ${glowColor};
  331. }
  332.  
  333. /* Booru links */
  334. /* For multiple uploads the button is below the image, for single upload it's next to the filename */
  335. /* single upload buttons can also be moved below the image by setting the innerPost as relative. */
  336. .lynxReverseImageSearch a:hover {
  337. text-decoration: underline;
  338. }
  339. .lynxReverseImageSearch > a {
  340. margin: 0 4px 0 1px;
  341.  
  342. &.fetch-awaiting:after {
  343. content: attr(data-booruname)" (please wait...)" !important;
  344. }
  345.  
  346. &.fetch-failed:after {
  347. content: attr(data-booruname)" (failed!)" !important;
  348. }
  349.  
  350. & > svg {
  351. margin-block: -2.5px;
  352. height: 1em;
  353. width: 1em;
  354. }
  355. }
  356.  
  357. .panelUploads:not(.multipleUploads) .lynxReverseImageSearch > a:after, lynxReverseImageSearch.showSearchNames > a:after {
  358. content: attr(data-booruname);
  359. }
  360.  
  361. .multipleUploads .uploadCell:has(.lynxReverseImageSearch) {
  362. position: relative;
  363. }
  364.  
  365. .multipleUploads .lynxReverseImageSearch {
  366. position: absolute;
  367. bottom: 0;
  368. left: 0;
  369. z-index: 2; /* Fixes the button not being clickable if you have spoiler thumbs disabled */
  370.  
  371. & a {
  372. font-size: 0.9em;
  373. filter: drop-shadow(0px 0px 1px black) drop-shadow(0px 0px 1px var(--contrast-color)) drop-shadow(0px 0px 1px var(--contrast-color));
  374. &:hover,
  375. &:active {
  376. background: var(--contrast-color);
  377. opacity: 0.9;
  378. max-width: 999px;
  379. &:after {
  380. content: attr(data-booruname);
  381. }
  382. }
  383. }
  384. }
  385.  
  386. /* video icons for filenames */
  387. a.originalNameLink.lynx-video::before {
  388. content: "\\e0a9";
  389. font-family: "Icons"; /* open-iconic font from the page */
  390. font-size: 90%;
  391. margin-right: 2px;
  392. }
  393.  
  394. /* Scrollbar you and reply markers */
  395. .marker-container {
  396. position: fixed;
  397. top: 8px;
  398. right: 0px;
  399. width: 10px;
  400. height: calc(100vh - 16px);
  401. z-index: 11000;
  402. pointer-events: none;
  403. }
  404.  
  405. .marker {
  406. position: absolute;
  407. width: 100%;
  408. height: 7px;
  409. background: var(--showScrollbarMarkers_color1);
  410. cursor: pointer;
  411. pointer-events: auto;
  412. border-radius: 40% 0 0 40%;
  413. z-index: 5;
  414. filter: drop-shadow(0px 0px 1px #000000BA);
  415. }
  416.  
  417. .marker.alt {
  418. background: var(--showScrollbarMarkers_color2);
  419. z-index: 2;
  420. }
  421.  
  422. .postNum.index {
  423. color: var(--showPostIndex_color1);
  424. font-weight: bold;
  425. }
  426.  
  427. .labelId.glows {
  428. box-shadow: 0 0 15px var(--glowFirstPostByID_color1);
  429. }
  430.  
  431. #lynxExtendedMenu {
  432. position: fixed;
  433. top: 15px;
  434. left: 50%;
  435. transform: TranslateX(-50%);
  436. padding: 10px;
  437. z-index: 10000;
  438. font-family: Arial, sans-serif;
  439. font-size: 14px;
  440. box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
  441. background: var(--contrast-color);
  442. color: var(--text-color);
  443. border: 1px solid #737373;
  444. border-radius: 4px;
  445. max-height:90%;
  446. overflow-y: auto;
  447. line-height: 0.8em;
  448.  
  449. & .altText {
  450. opacity: 0.8;
  451. font-size: 0.9em;
  452.  
  453. &.lineBefore:before {
  454. content: "—— ";
  455. }
  456. }
  457.  
  458. & .boldText {
  459. color: var(--link-color);
  460. font-weight: bold;
  461. }
  462.  
  463. & .colorLabel {
  464. padding: 3px 2px 3px 4px;
  465. border-radius: 8px;
  466. box-shadow: 0px 0px 1px currentColor;
  467. margin-left: 0.5em;
  468. }
  469.  
  470. & input[type="color"] {
  471. width: 40px;
  472. height: 20px;
  473. padding: 1px;
  474. transform: translate(0, 2px);
  475. }
  476.  
  477. & button {
  478. padding: 10px 20px;
  479. margin-right: 4px;
  480. margin-bottom: 0;
  481. filter: contrast(115%) brightness(110%);
  482. &:hover {
  483. filter: brightness(130%);
  484. }
  485. }
  486. }
  487. #lynxExtendedMenu > .settings-footer {
  488. height: auto;
  489. }
  490. @media screen and (max-width: 1000px) {
  491. #lynxExtendedMenu{
  492. right:0;
  493. width:90%;
  494. line-height: 1em;
  495. /*bottom:15px;*/
  496. }
  497. }
  498.  
  499. .lynxExtendedButton::before {
  500. content: "\\e0da";
  501. }
  502.  
  503. `);
  504.  
  505. if (settings.markPostEdge) {
  506. const color1 = settings.markPostEdge_color1 || SETTINGS_DEFINITIONS.markPostEdge.color1Default;
  507. const color2 = settings.markPostEdge_color2 || SETTINGS_DEFINITIONS.markPostEdge.color2Default;
  508. addMyStyle("lynx-mark-posts", `
  509. /*
  510. README:
  511. Mark your posts and replies with a left border. Specificity order: (you) > (reply).
  512. Important: The :not(#SP1) selectors are used for extra specificity.
  513. These are made extra specific so we can override ones from other userscripts.
  514. (because Lynx-- has an option to disable only this and also has the ability to customize the color)
  515. */
  516. /* Match your posts. This is easy. */
  517. body:not(#SP1#SP1) :is(.innerOP.yourPost, .innerPost.yourPost) {
  518. border-left: 3px dashed var(--markPostEdge_color1, ${color1});
  519. }
  520.  
  521. /*
  522. * Match replies:
  523. * This can be a simple .divMessage > .quoteLink
  524. * or it can be a .divMessage > details > .spoiler > s > u > .quoteLink (or something like that)
  525. */
  526. body:not(#SP1) :is(.innerOP.quotesYou, .innerPost.quotesYou) {
  527. border-left: 2px solid var(--markPostEdge_color2, ${color2});
  528. }
  529. `);
  530. }
  531.  
  532. if (settings.markYouText) {
  533. const color1 = settings.markYouText_color1 || SETTINGS_DEFINITIONS.markYouText.color1Default;
  534. addMyStyle("lynx-mark-you-text", `
  535. .youName { color: var(--markYouText_color1, ${color1}); }
  536. .you { --link-color: var(--markYouText_color1, ${color1}); }
  537. `);
  538. }
  539.  
  540. if (settings.halfchanGreentexts) {
  541. addMyStyle("lynx-halfchanGreentexts",
  542. `.greenText {
  543. filter: brightness(110%);
  544. }
  545. `);
  546. }
  547.  
  548. if (settings.showStubs === false) {
  549. addMyStyle("lynx-hide-stubs",`
  550. .postCell:has(> span.unhideButton.glowOnHover) {
  551. display: none;
  552. }
  553. `);
  554. }
  555.  
  556. if (settings.revealSpoilerText=="on") {
  557. addMyStyle("lynx-reveal-spoilertext1",`
  558. span.spoiler { color: white }
  559. `);
  560. } else if (settings.revealSpoilerText=="madoka") {
  561. addMyStyle("lynx-reveal-spoilertext2",`
  562. span.spoiler:not(:hover) {
  563. color: white;
  564. font-family: MadokaRunes !important;
  565. }
  566. `);
  567. }
  568.  
  569. } //End of runASAP()
  570.  
  571. //Everything in runAfterDom runs after document has loaded (like @run-at document-end)
  572. //Everything in runAfterDom runs after document has loaded (like @run-at document-end)
  573. //Everything in runAfterDom runs after document has loaded (like @run-at document-end)
  574. async function runAfterDom() {
  575. console.log("%cLynx Minus Minus Started with settings:", "color:rgb(0, 140, 255)", settings);
  576.  
  577. //Detect if the current page is a thread
  578. const url = window.location.href;
  579. const isThread = REGEX_THREAD.test(url);
  580.  
  581. //Keep these for now I guess.
  582. //Get the following window objects
  583. //unsafeWindow works on chrome and Tampermonkey FF, wrappedJSObject works on Firefox VM.
  584. //Chrome and firefox behavior is different here. In Chrome you can simply do 'api' to check if the variable is defined, in Firefox you need to do typeof api !== 'undefined'.
  585. //And a && will return the second element if the first is true.
  586.  
  587. // const window_api = (typeof api !== 'undefined' && api) || window?.api || unsafeWindow?.api || wrappedJSObject?.api || undefined;
  588. // const window_posting = (typeof posting !== 'undefined' && posting) || window?.posting || unsafeWindow?.posting || wrappedJSObject?.posting || undefined;
  589. // const window_qr = (typeof qr !== 'undefined' && qr) || window?.qr || unsafeWindow?.qr || wrappedJSObject?.qr || undefined;
  590. // if (window_api && window_posting && window_qr) {
  591. // windowAccessible = true;
  592. // } else {
  593. // //I think greasemonkey sandboxes the script. I use violentmonkey though
  594. // console.error("Lynx Minus Minus: This JS script is sandboxed and can't access page JS... (If you can read this, let me know what browser/extension does this. Or maybe the site just failed to load?)")
  595. // }
  596.  
  597. if (settings.preserveQuickReply === false) {
  598. const qrBody = document.getElementById("qrbody");
  599. if (qrBody) {
  600. qrBody.value = "";
  601. }
  602. }
  603.  
  604. function pageHotkeys(ev) {
  605. const key = ev.key.toLowerCase();
  606. //Ctrl+Q or Alt+R to open quick reply
  607. if ((ev.ctrlKey && key == "q") || (ev.altKey && key == "r")) {
  608. ev.preventDefault();
  609. //8chan's HTML will keep the text after a reload so attempt to clear it again
  610. const qrBody = document.getElementById("qrbody");
  611. if (settings.preserveQuickReply === false) {
  612. if (qrBody) {
  613. qrBody.value = "";
  614. }
  615. }
  616. const replyBtn = document.getElementById("replyButton");
  617. replyBtn?.click();
  618. qrBody?.focus();
  619. };
  620. //Alt+T to toggle thread watcher
  621. if (ev.altKey && (key == "t")) {
  622. ev.preventDefault();
  623. const watcherBtn = document.querySelector("body > nav a.watcherButton");
  624. if (watcherBtn) watcherBtn.click();
  625. }
  626. }
  627. document.addEventListener("keydown", pageHotkeys);
  628.  
  629. function createSettingsButton() {
  630. //Desktop
  631. document.querySelector("#navLinkSpan > .settingsButton").insertAdjacentHTML("afterend", `
  632. <span>/</span>
  633. <a id="navigation-lynxextended" class="coloredIcon lynxExtendedButton" title="LynxChan Extended-- Settings"></a>
  634. `);
  635. //Mobile
  636. document.querySelector("#sidebar-menu > ul > li > .settingsButton").parentElement.insertAdjacentHTML("afterend", `
  637. <li>
  638. <a id="navigation-lynxextended-mobile" class="coloredIcon lynxExtendedButton" title="LynxChan Extended-- Settings">Lynx Ex-- Settings</a>
  639. </li>
  640. `);
  641. document.querySelector("#navigation-lynxextended").addEventListener("click", openMenu);
  642. document.querySelector("#navigation-lynxextended-mobile").addEventListener("click", openMenu);
  643. }
  644.  
  645. //Register menu command for the settings button
  646. GM.registerMenuCommand("Show Options Menu", openMenu);
  647. try {
  648. createSettingsButton();
  649. } catch (error) {
  650. console.log("Error while creating settings button:", error);
  651. }
  652.  
  653. //Open the settings menu on the first run
  654. if (settings.firstRun) {
  655. settings.firstRun = false;
  656. await GM.setValue("firstRun", settings.firstRun);
  657. openMenu();
  658. }
  659. //Show watched threads on page load
  660. if (settings.showWatcherOnLoad) {
  661. const watchedMenu = document.querySelector("body > #watchedMenu");
  662. const watcherButton = document.querySelector("body > nav > #navLinkSpan > .watcherButton");
  663. if (watchedMenu && watcherButton) {
  664. if (watchedMenu?.style?.display === "none") {
  665. watcherButton.click();
  666. }
  667. }
  668. }
  669.  
  670. function replyKeyboardShortcuts(ev) {
  671. if (ev.ctrlKey) {
  672. let combinations = {
  673. "s":["[spoiler]","[/spoiler]"],
  674. "b":["'''","'''"],
  675. "u":["__","__"],
  676. "i":["''","''"],
  677. "d":["[doom]","[/doom]"],
  678. "m":["[moe]","[/moe]"]
  679. }
  680. for (var key in combinations)
  681. {
  682. if (ev.key == key)
  683. {
  684. ev.preventDefault();
  685. console.log("ctrl+"+key+" pressed in textbox")
  686. const textBox = ev.target;
  687. let newText = textBox.value;
  688. const tags = combinations[key]
  689. const selectionStart = textBox.selectionStart
  690. const selectionEnd = textBox.selectionEnd
  691. if (selectionStart == selectionEnd) { //If there is nothing selected, make empty tags and center the cursor between it
  692. document.execCommand("insertText",false, tags[0] + tags[1]);
  693. //Center the cursor between tags
  694. textBox.selectionStart = textBox.selectionEnd = (textBox.selectionEnd - tags[1].length);
  695. } else {
  696. //Insert text and keep undo/redo support (Only replaces highlighted text)
  697. document.execCommand("insertText",false, tags[0] + newText.slice(selectionStart, selectionEnd) + tags[1])
  698. }
  699. return;
  700. }
  701. }
  702. //Ctrl+Enter to send reply
  703. if (ev.key=="Enter") {
  704. document.getElementById("qrbutton")?.click()
  705. }
  706. }
  707. }
  708.  
  709.  
  710. function openMenu() {
  711. const oldMenu = document.getElementById("lynxExtendedMenu");
  712. if (oldMenu) {
  713. oldMenu.remove();
  714. return;
  715. }
  716. // Create options menu
  717. const menu = document.createElement("div");
  718. menu.id = "lynxExtendedMenu";
  719. menu.innerHTML = `
  720. <h3 style="text-align: center; color: var(--subject-color);" class='settings-header'>LynxChan Extended-- Options</h3>
  721. <p style="text-align: center;"><a href="https://greasyfork.org/en/scripts/533169-lynxchan-extended-minus-minus/versions">Version ${GM.info.script.version}</a></p><br>
  722. `;
  723.  
  724. //we use createElement() here instead of setting innerHTML so we can attach onclick to elements
  725. //...In the future, at least. There aren't any onclicks added yet.
  726. let settings_content = document.createElement("div");
  727. settings_content.classList.add("settings-content");
  728. Object.keys(SETTINGS_DEFINITIONS).forEach((name) => {
  729. const setting = SETTINGS_DEFINITIONS[name];
  730. if (setting.hidden) {
  731. //pass
  732. }
  733. else if (setting.type == "radio") {
  734. let html = `<span>${setting.desc}</span><br><form id="${name}" action='#'>`;
  735. for (const [value, description] of Object.entries(setting.options)) {
  736. html += `
  737. <label>
  738. <input name="${name}" type="radio" value="${value}" ${settings[name]==value ? "checked" : ""}
  739. <span>${description}</span>
  740. </label><br>
  741. `;
  742. }
  743. html += `</form>${setting.nonewline ? '' : '<br>'}`;
  744. settings_content.innerHTML += html;
  745. } else if (setting.type == "checkbox_multiple_dict") {
  746. const dict = settings[name]
  747. let html = `<span>${setting.desc}</span><br><form id="${name}" action='#'>`;
  748. for (const [key, description] of Object.entries(setting.options)) {
  749. html += `
  750. <label>
  751. <input name="${name}" type="checkbox" value="${key}" ${dict[key] ? "checked" : ""}
  752. <span>${description}</span>
  753. </label><br>
  754. `;
  755. }
  756. html += `</form>${setting.nonewline ? '' : '<br>'}`;
  757. settings_content.innerHTML += html;
  758. } else if (setting.type == "dropdown") {
  759. let html = `<label for="${name}">${setting.desc}:</label><select id="${name}">`
  760. Object.keys(setting['choices']).forEach(value => {
  761. html+=`<option value="${value}" ${settings[name]==value ? "selected" : ""}>${value}</option>`
  762. })
  763. html+=`</select><br>${setting.nonewline ? '' : '<br>'}`;
  764. settings_content.innerHTML += html;
  765.  
  766. } else if (setting.type == "checkbox_with_colors") {
  767. let colorHtml = "";
  768. let colorFields = Object.keys(setting).filter(k => /^color\d+Default$/.test(k));
  769. colorFields.forEach((colorKey) => {
  770. const idx = colorKey.match(/^color(\d+)Default$/)[1];
  771. const colorValue = settings[`${name}_color${idx}`] || setting[`color${idx}Default`];
  772. const colorDesc = setting[`color${idx}Desc`] || "";
  773. colorHtml += `
  774. <label class="colorLabel">
  775. ${colorDesc}
  776. <input type="color" id="${name}_color${idx}" value="${colorValue}" ${settings[name] ? '' : 'disabled'}>
  777. </label>
  778. `;
  779. });
  780. settings_content.innerHTML += `
  781. <label>
  782. <input type="checkbox" id="${name}" ${settings[name] ? "checked" : ""}>
  783. ${setting.desc}
  784. </label>
  785. ${colorHtml}
  786. <br>${setting.nonewline ? '' : '<br>'}`;
  787. } else {
  788. settings_content.innerHTML += `
  789. <label>
  790. <input type="checkbox" id="${name}" ${settings[name] ? "checked" : ""}>
  791. ${setting.desc}
  792. </label><br>${setting.nonewline ? '' : '<br>'}`;
  793. }
  794. })
  795. menu.appendChild(settings_content);
  796. menu.innerHTML += `
  797. <div class='settings-footer'>
  798. <button id="saveSettings">Save</button>
  799. <button id="closeMenu">Close</button>
  800. <button id="resetSettings" style="float: right;">Reset</button>
  801. </div>
  802. `;
  803. document.body.appendChild(menu);
  804.  
  805. // Save button functionality
  806. document.getElementById("saveSettings").addEventListener("click", async () => {
  807. Object.keys(SETTINGS_DEFINITIONS).forEach((name) => {
  808. const setting = SETTINGS_DEFINITIONS[name];
  809. if (!('hidden' in setting)) {
  810. if (setting.type=="radio") {
  811. settings[name] = menu.querySelector(`input[name="${name}"]:checked`).value;
  812. } else if (setting.type == "checkbox_multiple_dict") {
  813. const d = {}
  814. menu.querySelectorAll(`input[name="${name}"]`).forEach(checkbox => {
  815. d[checkbox.value] = checkbox.checked;
  816. })
  817. settings[name] = d;
  818. } else if (setting.type=="dropdown") {
  819. settings[name] = document.getElementById(name).value;
  820. } else if (setting.type=="checkbox_with_colors") {
  821. settings[name] = document.getElementById(name).checked;
  822. let colorFields = Object.keys(setting).filter(k => /^color\d+Default$/.test(k));
  823. colorFields.forEach((colorKey) => {
  824. const idx = colorKey.match(/^color(\d+)Default$/)[1];
  825. const colorName = `${name}_color${idx}`;
  826. const colorValue = document.getElementById(colorName).value;
  827. settings[colorName] = colorValue;
  828. // Set CSS variable on body (so it can be used without a refresh)
  829. document.body.style.setProperty(`--${colorName}`, colorValue);
  830. });
  831. } else {
  832. settings[name] = document.getElementById(name).checked;
  833. }
  834. }
  835. })
  836. console.log("Saving settings ",settings)
  837. await Promise.all(Object.entries(settings).map(([key, value]) => GM.setValue(key, value)));
  838. setTimeout(()=>{
  839. alert("Settings saved!\nFor most settings you must refresh the page for the changes to take effect.\n\n(only color pickers don't need a refresh)");
  840. }, 1);
  841. // menu.remove();
  842. });
  843.  
  844. // Reset button functionality
  845. document.getElementById("resetSettings").addEventListener("click", async () => {
  846. if (!confirm("Are you sure you want to reset all settings? This will delete all saved data.")) return;
  847. const keys = await GM.listValues();
  848. await Promise.all(keys.map(key => GM.deleteValue(key)));
  849. alert("All settings have been reset.\nRefreshing automatically for the changes to take effect.");
  850. menu.remove();
  851. location.reload();
  852. });
  853.  
  854. // Close button functionality
  855. document.getElementById("closeMenu").addEventListener("click", () => {
  856. menu.remove();
  857. });
  858.  
  859. }
  860.  
  861. function createMarker(element, container, isReply) {
  862. const pageHeight = document.body.scrollHeight;
  863. const offsetTop = element.offsetTop;
  864. const percent = offsetTop / pageHeight;
  865. const top = (percent * 100).toFixed(2);
  866.  
  867. const marker = document.createElement("div");
  868. marker.classList.add("marker");
  869. if (isReply) {
  870. marker.classList.add("alt");
  871. }
  872. marker.style.top = `${top}%`;
  873. marker.dataset.postid = element.id;
  874.  
  875. marker.addEventListener("click", () => {
  876. let elem = element?.previousElementSibling || element;
  877. if (elem) elem.scrollIntoView({ behavior: "instant", block: "start" });
  878. });
  879.  
  880. container.appendChild(marker);
  881. }
  882.  
  883. function recreateScrollMarkers() {
  884. let oldContainer = document.querySelector(".marker-container");
  885. if (oldContainer) {
  886. oldContainer.remove();
  887. }
  888. // Create marker container
  889. const markerContainer = document.createElement("div");
  890. markerContainer.classList.add("marker-container");
  891. document.body.appendChild(markerContainer);
  892. // Match and create markers for "my posts" (matches native & dollchan)
  893. document.querySelectorAll(".postCell:has(> .innerPost > .postInfo.title :is(.linkName.youName, .de-post-counter-you)),.postCell:has(.innerPost.de-mypost)")
  894. .forEach((elem) => {
  895. createMarker(elem, markerContainer, false);
  896. });
  897. // Match and create markers for "replies" (matches native & dollchan)
  898. document.querySelectorAll(".postCell:has(> .innerPost > .divMessage :is(.quoteLink.you, .de-ref-you)),.postCell:has(.innerPost.de-mypost-reply)")
  899. .forEach((elem) => {
  900. createMarker(elem, markerContainer, true);
  901. });
  902. }
  903. let postCount = 1;
  904. const postIndexLookup = {};
  905. function addPostCount(post, newpost = true) {
  906. // const posts = Array.from(document.querySelectorAll(".innerOP, .divPosts > .postCell"));
  907. if (post.querySelector(".postNum")) {
  908. return;
  909. }
  910. const postInfoDiv = post.getElementsByClassName("title")[0]
  911. if (!postInfoDiv) {
  912. console.error("[Lynx--] Failed to find post for div ", post);
  913. return;
  914. }
  915. const posterNameDiv = postInfoDiv.getElementsByClassName("linkName")[0];
  916. const postNumber = post.querySelector(".linkQuote")?.textContent;
  917. if (!postNumber) return;
  918.  
  919. let localCount = postCount;
  920. if (newpost) {
  921. postIndexLookup[postNumber] = localCount;
  922. postCount++;
  923. } else {
  924. //Show cached post count for inlines & hovers
  925. localCount = postIndexLookup[postNumber];
  926. if (!localCount) return;
  927. }
  928.  
  929. let newNode = document.createElement("span");
  930. newNode.innerText = localCount;
  931. newNode.className = "postNum index";
  932. if (localCount < Infinity) //knownBumpLimit
  933. {
  934. // color is handled by .postNum.index
  935. newNode.style = "";
  936. }
  937. else
  938. {
  939. newNode.style = "color: rgb(255, 4, 4); font-weight: bold;"
  940. }
  941. postInfoDiv.insertBefore(newNode, posterNameDiv);
  942. let foo = document.createTextNode("\u00A0"); // Non-breaking space
  943. postInfoDiv.insertBefore(foo, posterNameDiv);
  944. }
  945.  
  946. //Open source svg from iconify.design
  947. const SVG_SEARCH = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="3"><path stroke-linecap="round" d="m20 20l-6-6"></path><path d="M15 9.5a5.5 5.5 0 1 1-11 0a5.5 5.5 0 0 1 11 0Z"></path></g></svg>`;
  948. function filenameFeatures(post) {
  949. const fileNames = post.querySelectorAll(".originalNameLink[href]");
  950.  
  951. //Feature: Distinguish videos, gifs and audio with an icon
  952. //Theres also a mime type on .imgLink
  953. if (settings.showVideoIcons) {
  954. const videoExts = /\.(webm|mp4|mkv|mov|avi|flv|wmv|m4v|gif|apng|mp3|flac|opus|ogg|wav|aac|m4a|wma)$/i;
  955. fileNames.forEach((nameElem) => {
  956. if (videoExts.test(nameElem.download)) {
  957. nameElem.classList.add("lynx-video");
  958. }
  959. });
  960. }
  961.  
  962. //Last feature: Reverse image search buttons
  963. //TODO MAYBE: Make this button open a small menu (like the post menu) instead of multiple buttons. AI can do it in 20 seconds.
  964. // .some() will return true if any value in the dict is true
  965. // So inverting this means no values are true, so return without doing anything
  966. if (!Object.values(settings.reverseSearchOptions).some(Boolean)) {
  967. return;
  968. }
  969.  
  970. const fileNameElements = Array.from(fileNames);
  971. const regex_md5sum = /[0-9a-f]{32}/g;
  972. const regex_pixiv = /(\d+)_p\d+/;
  973.  
  974. for (let i = fileNameElements.length-1; i>=0; i--)
  975. {
  976. const nameElem = fileNameElements[i];
  977. const parent = nameElem.parentElement
  978. if (parent.querySelector(".lynxReverseImageSearch")) {
  979. return;
  980. }
  981. const attachmentFileName = nameElem.download;
  982.  
  983. const span = document.createElement("span");
  984. span.classList.add("lynxReverseImageSearch");
  985.  
  986. let searchButtonsAdded = 0
  987.  
  988. let m;
  989. if (settings.reverseSearchOptions.pixiv && (m = regex_pixiv.exec(attachmentFileName)) !== null) {
  990. span.innerHTML += `<a rel="noopener noreferrer" target="_blank" data-booruname="pixiv" href="https://pixiv.net/i/${m[1]}">${SVG_SEARCH}</a>`
  991. searchButtonsAdded++;
  992. }
  993. //This is 'else if' because these options are mutually exclusive - a filename will never match pixiv AND an md5 hash
  994. //Careful with this insane abuse of conditionals, the order of operations matters (&& is before = without parenthesis)
  995. //And we don't want to match >1 because that could be an 8chan hash (There should only be 1 md5 hash in a file name anyways)
  996. else if (settings.reverseSearchOptions.booru && (m = [...attachmentFileName.matchAll(regex_md5sum)]) && m?.length == 1) {
  997. span.innerHTML += `<a rel="noopener noreferrer" target="_blank" data-booruname="${settings.reverseSearchBooruSite}" href="${SETTINGS_DEFINITIONS['reverseSearchBooruSite']['choices'][settings.reverseSearchBooruSite]}${m[0]}">${SVG_SEARCH}</a>`
  998. searchButtonsAdded++;
  999. }
  1000.  
  1001. if (settings.reverseSearchOptions.saucenao) {
  1002. //Logic: for everything thats not supported i.e. not an image use the thumbnail if its available
  1003. //Supported image extensions for Saucenao direct search
  1004. const imageExts = /\.(png|jpe?g|webp|bmp|gif)$/i;
  1005. let validImage = true;
  1006. let useThumbInstead = false;
  1007. let thumbUrl = null;
  1008. if (!imageExts.test(attachmentFileName)) {
  1009. // Not a supported image, try to find a thumbnail
  1010. const uploadCell = parent.closest('.uploadCell');
  1011. if (uploadCell) {
  1012. const thumbImg = uploadCell.querySelector('.imgLink > img');
  1013. const thumbSrc = thumbImg?.getAttribute("src");
  1014. if (thumbImg && thumbSrc?.startsWith('/.media/t_')) {
  1015. useThumbInstead = true;
  1016. thumbUrl = thumbSrc;
  1017. }
  1018. }
  1019. // If no valid thumbnail, don't add saucenao
  1020. if (!useThumbInstead) {
  1021. // Don't add saucenao button for this file
  1022. validImage = false;
  1023. }
  1024. }
  1025.  
  1026. const sauceNaoWrapper = function(ev) {
  1027. ev.preventDefault(); //Prevent <details> node from contracting
  1028. const a = ev.currentTarget;
  1029. a.classList.add("fetch-awaiting");
  1030. const fetchUrl = useThumbInstead ? thumbUrl : nameElem.href;
  1031. const fetchName = useThumbInstead ? ("thumbnail_" + attachmentFileName) : attachmentFileName;
  1032. fetch(fetchUrl)
  1033. .then(resp => {
  1034. if (!resp.ok) throw new Error("Fetch failed");
  1035. return resp.blob();
  1036. })
  1037. .then(blob => {
  1038. let file = new File([blob], fetchName, {type: blob.type} );
  1039. let dataTransfer = new DataTransfer();
  1040. dataTransfer.items.add(file);
  1041. document.getElementById("saucenao_file_input").files = dataTransfer.files;
  1042. document.getElementById("saucenao_submit").click();
  1043. a.classList.remove("fetch-awaiting");
  1044. })
  1045. .catch(() => {
  1046. a.classList.remove("fetch-awaiting");
  1047. a.classList.add("fetch-failed");
  1048. });
  1049. }
  1050.  
  1051. if (validImage) {
  1052. const a = document.createElement("a");
  1053. a.setAttribute("data-booruname","saucenao")
  1054. // a.innerText = '🔍︎'
  1055. a.innerHTML = SVG_SEARCH;
  1056. a.addEventListener("click", sauceNaoWrapper)
  1057. span.appendChild(a);
  1058. //span.innerHTML += `<a data-booruname='saucenao' onclick=''>🔍︎</a>`
  1059. searchButtonsAdded++;
  1060. }
  1061. }
  1062.  
  1063. if (searchButtonsAdded > 1) {
  1064. span.classList.add("showSearchNames")
  1065. }
  1066.  
  1067. if (searchButtonsAdded > 0) {
  1068. parent.insertAdjacentElement("beforeend", span);
  1069. }
  1070. }
  1071. }
  1072. /*function glowpost() {
  1073. // Create a frequency map to track occurrences of each item
  1074. const list = document.querySelectorAll(".labelId");
  1075. const countMap = Array.from(list).reduce((acc, item) => {
  1076. acc[item.style.backgroundColor] = (acc[item.style.backgroundColor] || 0) + 1;
  1077. return acc;
  1078. }, {});
  1079. // Filter the list to keep only items with a count of 1
  1080. Array.from(list).filter(item => countMap[item.style.backgroundColor] === 1).forEach((item) => {
  1081. item.style.boxShadow = "0 0 15px #26bf47";
  1082. item.title = "This is the first post from this ID.";
  1083. });
  1084. }*/
  1085. var idMap = {};
  1086. const glowpost = function(post, newpost = true) {
  1087. const list = post.querySelectorAll(".labelId");
  1088. const postNumber = post.querySelector(".linkQuote")?.textContent;
  1089. list.forEach((poster) => {
  1090. const bgColor = poster.style.backgroundColor;
  1091. if (newpost && idMap[bgColor] === undefined) {
  1092. idMap[bgColor] = postNumber;
  1093. poster.classList.add("glows");
  1094. poster.title = "This is the first post from this ID.";
  1095. } else if (!newpost && idMap[bgColor] == postNumber) {
  1096. poster.classList.add("glows");
  1097. poster.title = "This is the first post from this ID.";
  1098. }
  1099. });
  1100. }
  1101.  
  1102. const revealSpoilerImages = function(post) {
  1103. const spoilers = post.querySelectorAll(".imgLink > img:is([src='/spoiler.png'],[src*='/custom.spoiler'])");
  1104. spoilers.forEach(spoiler => {
  1105. spoiler.classList.add('spoiler-thumb');
  1106. const parent = spoiler.parentElement;
  1107. const hrefTokens = parent.href.split("/");
  1108. const fileNameTokens = hrefTokens[4].split(".");
  1109. const thumbUrl = `/.media/t_${fileNameTokens[0]}`;
  1110. spoiler.src = thumbUrl;
  1111. //spoiler.style.border = "2px dotted red";
  1112. });
  1113. }
  1114.  
  1115. if (settings.spoilerImageType.startsWith("reveal")) {
  1116. addMyStyle("lynx-reveal-spoilerimage",`
  1117. img.spoiler-thumb {
  1118. transition: 0.2s;
  1119. outline: 2px dotted #ff0000ee;
  1120. ${settings.spoilerImageType=="reveal_blur" ? "filter: blur(10px);" : ""}
  1121. }
  1122. img.spoiler-thumb:hover {
  1123. filter: blur(0);
  1124. }
  1125. `)
  1126. }
  1127. // Add functionality to apply the custom spoiler image CSS
  1128. let threadSpoilerFound = false;
  1129. let tsFallbackUsed = false;
  1130. function setThreadSpoiler(post) {
  1131. if (threadSpoilerFound) return;
  1132.  
  1133. let spoilerImageUrl = null;
  1134.  
  1135. //When the option is "threadAlt", fallback to "thread" if "threadAlt" doesn't exist yet.
  1136. if (settings.spoilerImageType == "threadAlt") {
  1137. const altSpoilerLink = Array.from(post.querySelectorAll('a.originalNameLink[download^="ThreadSpoilerAlt"]')).find(link => /\.(jpg|jpeg|png|webp)$/i.test(link.download));
  1138. spoilerImageUrl = altSpoilerLink ? altSpoilerLink.href : null;
  1139. tsFallbackUsed = false; //stop looking for threadAlt
  1140. }
  1141.  
  1142. if (settings.spoilerImageType == "thread" || (!spoilerImageUrl && !tsFallbackUsed && settings.spoilerImageType == "threadAlt")) {
  1143. const spoilerLink = Array.from(post.querySelectorAll('a.originalNameLink[download^="ThreadSpoiler"]')).find(link => /\.(jpg|jpeg|png|webp)$/i.test(link.download));
  1144. spoilerImageUrl = spoilerLink ? spoilerLink.href : null;
  1145. if (settings.spoilerImageType == "threadAlt") {
  1146. tsFallbackUsed = true; //Keep looking for threadAlt
  1147. }
  1148. } else if (settings.spoilerImageType == "test") {
  1149. const myArray = [
  1150. 'https://8chan.moe/.media/f76e9657d6b506115ccd0ade73d3d562777a441e4b6bb396610669396ff3032a.png',
  1151. 'https://8chan.moe/.media/1074fdb6eea4ba609910581e7824106736a1bcad446ace1ae0792b231b52cf9a.png',
  1152. 'https://8chan.moe/.media/c32b4de8490d7e77987f0e2a381d5935ffa6fec9b98c78ea7c05bd4381d6f64b.png',
  1153. 'https://8chan.moe/.media/bb225302110d52494ec2bea68693d566acee09767212ce4ee8c0d83d49cfa05b.png'
  1154. ];
  1155. spoilerImageUrl = myArray[Math.floor(Math.random() * myArray.length)];
  1156. addMyStyle("lynx-thread-spoiler-css1", `
  1157. body {
  1158. --spoiler-img: url("${spoilerImageUrl}")
  1159. }
  1160. .uploadCell:not(.expandedCell) a.imgLink:has(>img[src="/spoiler.png"]),
  1161. .uploadCell:not(.expandedCell) a.imgLink:has(>img[src*="/custom.spoiler"]) {
  1162. background-image: var(--spoiler-img);
  1163. background-size: cover;
  1164. background-position: center;
  1165. & > img {
  1166. opacity: 0;
  1167. }
  1168. }
  1169. `);
  1170. threadSpoilerFound = true;
  1171. return;
  1172. }
  1173.  
  1174. if (spoilerImageUrl) {
  1175. document.head?.querySelector("#lynx-thread-spoiler-css2")?.remove(); //Remove if the style already exists (from fallback)
  1176. addMyStyle("lynx-thread-spoiler-css2", `
  1177. ${settings.overrideBoardSpoilerImage ? '.uploadCell:not(.expandedCell) a.imgLink:has(>img[src*="/custom.spoiler"]),' : "" }
  1178. .uploadCell:not(.expandedCell) a.imgLink:has(>img[src="/spoiler.png"]) {
  1179. background-image: url("${spoilerImageUrl}");
  1180. background-size: cover;
  1181. background-position: center;
  1182. outline: dashed 2px #ff000090;
  1183. & > img {
  1184. opacity: 0;
  1185. }
  1186. }
  1187. `);
  1188. if (!tsFallbackUsed) {
  1189. threadSpoilerFound = true;
  1190. }
  1191. }
  1192. }
  1193.  
  1194. if (settings.spoilerImageType=="kachina") {
  1195. addMyStyle("lynx-kachinaSpoilers",`
  1196. ${settings.overrideBoardSpoilerImage ? '.uploadCell:not(.expandedCell) a.imgLink:has(>img[src*="/custom.spoiler"]),' : "" }
  1197. .uploadCell:not(.expandedCell) a.imgLink:has(>img[src="/spoiler.png"]) {
  1198. background-size: cover;
  1199. background-position: center;
  1200. margin-right:5px;
  1201. background-image: url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAA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nCp95oinN0OcGhj/eTIkBAdKvsasYHWvzBy2B4BzQsxlZSa4uu9/Qy7HSKj1LeGVY1L3dY7MDvXvVjE9QaPVyyMeomv3QHGR+r2e15q/U0kjaNwfix5xUZWWwaGOrFCEq89MDprKbuVIwYjK6UoBy1Xlxmt1MaQPJf5Clo0TeEnOc6vnDpVz7TF0bLKr+RhkCQMNlknvgkZTxm5pGF9818CvptPCENoBZ/gVh0Hxn2Z/WHSH6m64x5LFFdtcZ8eciYK4vCtjkYY1wxJhgBzcuGRFNG8MqWADZPgc5ON5AAs4ytiROSKBvOtVHucGvOFco4Ac//Z");
  1202. & > img {
  1203. opacity: 0;
  1204. }
  1205. }
  1206. `)
  1207. }
  1208.  
  1209. function iterateAllPosts() {
  1210. //Get ALL posts (this does NOT include inlined posts and hovered posts)
  1211. const allPosts = document.querySelectorAll("#divThreads > .opCell > .innerOP, .divPosts > .postCell");
  1212. const postsArray = Array.from(allPosts); //use an array to find the last post
  1213. postsArray.forEach((post, index) => {
  1214. if (index == postsArray.length-1) {
  1215. //only the last post sends batching=false
  1216. iterateSinglePost(post, true, false);
  1217. } else {
  1218. iterateSinglePost(post, true, true);
  1219. }
  1220. });
  1221. }
  1222.  
  1223. /**
  1224. * Processes a single post element.
  1225. *
  1226. * @param {HTMLElement} post - The post here can be an .innerPost or one of its containers
  1227. * @param {boolean} newpost - True if this is a new post in the thread (i.e. not a tooltip or inline)
  1228. * @param {boolean} batching - False if this is not from a batch from iterateAllPosts (or not the last post of the batch)
  1229. */
  1230. function iterateSinglePost(post, newpost = false, batching = false) {
  1231. // console.log("Lynx-- processing post", {post}, {newpost}, {batching});
  1232. filenameFeatures(post);
  1233. if (settings.glowFirstPostByID)
  1234. glowpost(post, newpost);
  1235. if (settings.spoilerImageType.startsWith("reveal"))
  1236. revealSpoilerImages(post);
  1237. if (settings.showPostIndex)
  1238. addPostCount(post, newpost);
  1239.  
  1240. //Run only if its a new post in the thread
  1241. if (newpost) {
  1242. if (settings.spoilerImageType=="thread" || settings.spoilerImageType=="threadAlt")
  1243. setThreadSpoiler(post);
  1244. //This still has to iterate all posts, do it last and only when necessary.
  1245. //These are manually ran in the mutation observer
  1246. if (batching === false && settings.showScrollbarMarkers)
  1247. recreateScrollMarkers();
  1248. }
  1249. }
  1250.  
  1251. //ANYTHING BELOW ONLY RUNS ON THREAD PAGES (if (isThread))
  1252. //ANYTHING BELOW ONLY RUNS ON THREAD PAGES (if (isThread))
  1253. //99% of above are functions. They can be ignored.
  1254. if (isThread) {
  1255. if (settings.addKeyboardHandlers) {
  1256. document.getElementById("qrbody")?.addEventListener("keydown", replyKeyboardShortcuts);
  1257. document.getElementById("quick-reply")?.addEventListener('keydown',function(ev) {
  1258. if (ev.key == "Escape") {
  1259. document.getElementById("quick-reply")?.querySelector(".close-btn").click();
  1260. }
  1261. })
  1262. }
  1263. //I'm not sure who would ever want this on but I'm making it an option anyways
  1264. if (settings.preserveQuickReply===false) {
  1265. document.getElementById("quick-reply")?.querySelector(".close-btn")?.addEventListener("click", function(ev){
  1266. document.getElementById("qrbody").value = "";
  1267. });
  1268. //This doesn't replace the built in onclick but adds to it so the original onclick will still bring up the qr
  1269. document.getElementById("replyButton")?.addEventListener("click", function(ev){
  1270. ev.preventDefault();
  1271. const qrBody = document.getElementById("qrbody");
  1272. if (qrBody) {
  1273. qrBody.value = "";
  1274. qrBody?.focus();
  1275. }
  1276. });
  1277. }
  1278. if (settings.reverseSearchOptions.saucenao) {
  1279. //have to shove this at the bottom of the document since the entire thread is inside a form div and I can't nest it
  1280. const formm =`
  1281. <form target="_blank" action="https://saucenao.com/search.php" method="POST" enctype="multipart/form-data" style="display:none">
  1282. <input type="file" name="file" size="50" id='saucenao_file_input'>
  1283. <input type="submit" accesskey="s" value="get sauce" id='saucenao_submit'>
  1284. </form>`
  1285. document.body.insertAdjacentHTML('beforeend', formm);
  1286. }
  1287. //Start running and observing, no need for a delay.
  1288. iterateAllPosts();
  1289. //Observe posts and all their children
  1290. const observer = new MutationObserver((mt_callback) => {
  1291. let foundNewPost = false;
  1292. mt_callback.forEach(mut => {
  1293. if (mut.type == "childList" && mut.addedNodes?.length > 0) {
  1294. //console.log("MutationObserver!!!");
  1295. mut.addedNodes.forEach(node => {
  1296. //New posts, new inlined posts, new hovered posts all contain .innerPost and are always in a div container.
  1297. //New posts are div.postCell and new inlines are div.inlineQuote
  1298. if (node.tagName === "DIV") {
  1299. // console.log("lynx ~ observer:", {node}, {mut});
  1300. //batching=true for both new posts and inlined posts
  1301. if (node.classList.contains("postCell")) {
  1302. foundNewPost = true;
  1303. iterateSinglePost(node, true, true);
  1304. } else if (node.classList.contains("inlineQuote")) {
  1305. iterateSinglePost(node, false, true);
  1306. }
  1307. }
  1308. });
  1309. }
  1310. });
  1311. //Manually run all batching=false actions here
  1312. if (foundNewPost && settings.showScrollbarMarkers) {
  1313. recreateScrollMarkers();
  1314. }
  1315. });
  1316. observer.observe(document.querySelector(".divPosts"), {childList: true, subtree: true});
  1317.  
  1318. //Observe the hover tooltip (ignore everything else)
  1319. const toolObserver = new MutationObserver((mutationsList) => {
  1320. for (const mutation of mutationsList) {
  1321. if (mutation.type === 'childList') {
  1322. mutation.addedNodes.forEach(node => {
  1323. if (node.tagName === "DIV" && node.matches(".innerPost, .innerOP")) {
  1324. //New hover tooltip found
  1325. iterateSinglePost(node, false, false);
  1326. }
  1327. });
  1328. }
  1329. }
  1330. });
  1331. const quoteTooltip = document.body?.querySelector(":scope > div.quoteTooltip");
  1332. if (quoteTooltip) {
  1333. toolObserver.observe(quoteTooltip, {childList: true});
  1334. }
  1335. }
  1336. } //End of runAfterDom()
  1337.  
  1338. //Starting runAfterDom when the document is ready
  1339. waitForDom(runAfterDom);
  1340. })();
  1341.