MSPFA extras

Adds custom quality of life features to MSPFA.

当前为 2021-01-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MSPFA extras
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.8
  5. // @description Adds custom quality of life features to MSPFA.
  6. // @author seymour schlong
  7. // @icon https://pipe.miroware.io/5b52ba1d94357d5d623f74aa/mspfa/ico.png
  8. // @icon64 https://pipe.miroware.io/5b52ba1d94357d5d623f74aa/mspfa/ico.png
  9. // @match https://mspfa.com/
  10. // @match https://mspfa.com/?*
  11. // @match https://mspfa.com/*/
  12. // @match https://mspfa.com/*/?*
  13. // @match https://mspfa.com/my/*
  14. // @match https://mspfa.com/random/
  15. // @exclude https://mspfa.com/js/*
  16. // @exclude https://mspfa.com/css/*
  17. // @exclude https://mspfa.com/rss/*
  18. // @grant none
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23.  
  24. const currentVersion = "1.8";
  25. console.log(`MSPFA extras script v${currentVersion} by seymour schlong`);
  26.  
  27. const debug = false;
  28.  
  29. /**
  30. * https://github.com/GrantGryczan/MSPFA/projects/1?fullscreen=true
  31. * Github to-do completion list (and other stuff too)
  32. *
  33. * https://github.com/GrantGryczan/MSPFA/issues/26 - Dropdown menu - February 23rd, 2020
  34. * https://github.com/GrantGryczan/MSPFA/issues/18 - MSPFA themes - February 23rd, 2020
  35. * https://github.com/GrantGryczan/MSPFA/issues/32 - Adventure creation dates - February 23rd, 2020
  36. * https://github.com/GrantGryczan/MSPFA/issues/32 - User creation dates - February 23rd, 2020
  37. * https://github.com/GrantGryczan/MSPFA/issues/40 - Turn certain buttons into links - July 21st, 2020
  38. * https://github.com/GrantGryczan/MSPFA/issues/41 - Word and character count - July 21st, 2020
  39. * https://github.com/GrantGryczan/MSPFA/issues/57 - Default spoiler values - August 7th, 2020
  40. * https://github.com/GrantGryczan/MSPFA/issues/62 - Buttonless spoilers - August 7th, 2020
  41. * https://github.com/GrantGryczan/MSPFA/issues/52 - Hash URLs - August 8th, 2020
  42. * - Page drafts - August 8th, 2020
  43. * - Edit pages button - August 8th, 2020
  44. * - Image preloading - August 20th, 2020
  45. * https://github.com/GrantGryczan/MSPFA/issues/19 - Manage game saves - August 22nd, 2020
  46. *
  47. * Extension to-do... maybe...
  48. *
  49. * If trying to save a page and any other save button is not disabled, ask the user if they would rather Save All instead, or prompt to disable update notifications.
  50. * When adding a new page, store it in an array and if that array length is > 1 when someone tries to save, prompt them to press Save All?
  51. */
  52.  
  53. // A general function that allows for waiting until a certain element appears on the page.
  54. const pageLoad = (fn, length) => {
  55. const interval = setInterval(() => {
  56. if (fn()) clearInterval(interval);
  57. }, length ? length*1000 : 500);
  58. };
  59.  
  60. // Saves the options data for the script.
  61. const saveData = (data) => {
  62. localStorage.mspfaextra = JSON.stringify(data);
  63. if (debug) {
  64. console.log('Settings:');
  65. console.log(data);
  66. }
  67. };
  68.  
  69. // Saves the data for drafts
  70. const saveDrafts = (data) => {
  71. localStorage.mspfadrafts = JSON.stringify(data);
  72. if (debug) {
  73. console.log('Drafts:');
  74. console.log(data);
  75. }
  76. };
  77.  
  78. // Encases an element within a link
  79. const addLink = (elm, url, target) => {
  80. const link = document.createElement('a');
  81. link.href = url;
  82. link.draggable = false;
  83. if (elm.parentNode) elm.parentNode.insertBefore(link, elm);
  84. if (target) link.target = target;
  85. link.appendChild(elm);
  86. return link;
  87. };
  88.  
  89. // Easy br element
  90. const newBr = () => {
  91. return document.createElement('br');
  92. }
  93.  
  94. const clearListeners = (elm) => {
  95. let clone = elm.cloneNode(1);
  96. elm.parentNode.replaceChild(clone, elm);
  97. return clone;
  98. }
  99.  
  100. // Make creating label elements easier
  101. const createLabel = (text, id) => {
  102. const newLabel = document.createElement('label');
  103. newLabel.textContent = text;
  104. newLabel.setAttribute('for', id);
  105. return newLabel;
  106. }
  107.  
  108. let settings = {};
  109. let drafts = {};
  110.  
  111. const defaultSettings = {
  112. autospoiler: false,
  113. style: 0,
  114. styleURL: "",
  115. night: false,
  116. auto502: true,
  117. textFix: false,
  118. pixelFix: false,
  119. intro: false,
  120. commandScroll: false,
  121. preload: true,
  122. dialogKeys: true,
  123. dialogFocus: false,
  124. navStick: false,
  125. spoilerValues: {}
  126. }
  127.  
  128. let pageLoaded = false;
  129.  
  130. const loadDrafts = () => {
  131. if (localStorage.mspfadrafts) {
  132. drafts = JSON.parse(localStorage.mspfadrafts);
  133. }
  134. }
  135. loadDrafts();
  136.  
  137. // Load any previous settings from localStorage
  138. if (localStorage.mspfaextra) {
  139. Object.assign(settings, JSON.parse(localStorage.mspfaextra));
  140.  
  141. // Get draft data from settings
  142. if (typeof settings.drafts === "object") {
  143. if (Object.keys(settings.drafts).length > 0 && Object.keys(drafts).length === 0) {
  144. drafts = settings.drafts;
  145. }
  146. }
  147. saveDrafts(drafts);
  148. }
  149.  
  150. // If any settings are undefined, re-set to their default state. (For older users when new things get stored)
  151. const checkSettings = () => {
  152. const defaultSettingsKeys = Object.keys(defaultSettings);
  153. for (let i = 0; i < defaultSettingsKeys.length; i++) {
  154. if (typeof settings[defaultSettingsKeys[i]] === "undefined") {
  155. settings[defaultSettingsKeys[i]] = defaultSettings[defaultSettingsKeys[i]];
  156. }
  157. }
  158. saveData(settings);
  159. }
  160.  
  161. checkSettings();
  162.  
  163. if (GM_info && GM_info.scriptHandler !== "Tampermonkey" && !settings.warned) {
  164. alert(`It appears that you're running the MSPFA extras script with ${GM_info.scriptHandler}.\nUnfortunately, this script cannot run at its full potential because of that.\nTry switching to Tampermonkey if you want to use more of the features!\n(this message will only appear once.)`);
  165. settings.warned = true;
  166. saveData(settings);
  167. }
  168.  
  169. // Enable the sticky nav bar (scrolls with you)
  170. if (settings.navStick) {
  171. pageLoad(() => {
  172. let formIDs = {
  173. '/stories/': '#explore',
  174. '/my/profile/': '#editprofile',
  175. '/my/settings/': '#editsettings',
  176. '/my/stories/info/': '#editstory'
  177. }
  178.  
  179. let nav = document.querySelector('nav');
  180. if (nav) {
  181. nav.className = 'nav-sticky';
  182. if (location.pathname === '/' && location.search && params.s || location.pathname === '/preview/') {
  183. let slide = document.querySelector('#slide');
  184. slide.parentNode.insertBefore(nav, slide);
  185. } else {
  186. let parentDiv = document.createElement('div');
  187. parentDiv.appendChild(nav);
  188. document.querySelectorAll('.alert').forEach(banner => {
  189. parentDiv.appendChild(banner);
  190. });
  191.  
  192. if (formIDs[location.pathname]) {
  193. let container = document.querySelector(formIDs[location.pathname]);
  194. container.parentNode.insertBefore(parentDiv, container);
  195. parentDiv.appendChild(container);
  196. } else {
  197. let containers = document.querySelectorAll('#main > table.container');
  198.  
  199. containers[0].parentNode.insertBefore(parentDiv, containers[0]);
  200. document.querySelectorAll('.banner').forEach(b => {
  201. parentDiv.appendChild(b);
  202. });
  203. containers.forEach(c => {
  204. parentDiv.appendChild(c);
  205. });
  206. }
  207. }
  208. return true;
  209. }
  210. });
  211. }
  212.  
  213. // Scrolls you to where you need to be
  214. const hashSearch = location.href.replace(location.origin + location.pathname, '').replace(location.search, '');
  215. if (hashSearch !== '') {
  216. pageLoad(() => {
  217. const idElement = document.querySelector(hashSearch);
  218. if (idElement) {
  219. const selected = document.querySelector(hashSearch);
  220. selected.scrollIntoView();
  221. selected.style.outline = '3px solid black';
  222. selected.style.transition = '0.5s';
  223. pageLoad(() => {
  224. if (pageLoaded) {
  225. selected.style.outline = '0px solid black';
  226. }
  227. });
  228.  
  229. return true;
  230. }
  231. }, 1);
  232. }
  233.  
  234. // Ripped shamelessly right from mspfa lol (URL search parameters -- story ID, page num, etc.)
  235. let rawParams;
  236. if (location.href.indexOf("#") != -1) {
  237. rawParams = location.href.slice(0, location.href.indexOf("#"));
  238. } else {
  239. rawParams = location.href;
  240. }
  241. if (rawParams.indexOf("?") != -1) {
  242. rawParams = rawParams.slice(rawParams.indexOf("?") + 1).split("&");
  243. } else {
  244. rawParams = [];
  245. }
  246. const params = {};
  247. for (let i = 0; i < rawParams.length; i++) {
  248. try {
  249. const p = rawParams[i].split("=");
  250. params[p[0]] = decodeURIComponent(p[1]);
  251. } catch (err) {}
  252. }
  253.  
  254. // Show the URL params if in debug more
  255. if (debug) {
  256. console.log('URL parameters:');
  257. console.log(params);
  258. }
  259.  
  260. // Functions to get/change data from the console
  261. window.MSPFAe = {
  262. getSettings: () => {
  263. return settings;
  264. },
  265. getSettingsString: (formatted) => {
  266. if (formatted) {
  267. console.log(JSON.stringify(settings, null, 4));
  268. } else {
  269. console.log(JSON.stringify(settings));
  270. }
  271. },
  272. getDrafts: () => {
  273. loadDrafts();
  274. return drafts;
  275. },
  276. getDraftsString: (formatted) => {
  277. loadDrafts();
  278. if (formatted) {
  279. console.log(JSON.stringify(drafts, null, 4));
  280. } else {
  281. console.log(JSON.stringify(drafts));
  282. }
  283. },
  284. changeSettings: (newSettings) => {
  285. console.log('Settings updated');
  286. console.log(settings);
  287. Object.assign(settings, newSettings);
  288. saveData(settings);
  289. },
  290. changeSettingsString: (fullString) => {
  291. try {
  292. JSON.parse(fullString);
  293. } catch (err) {
  294. console.error(err);
  295. return;
  296. }
  297. settings = JSON.parse(fullString);
  298. checkSettings();
  299. console.log(settings);
  300. },
  301. getParams: params
  302. }
  303.  
  304. // Error reloading
  305. if (settings.auto502 && document.querySelector('#cf-wrapper')) {
  306. window.location.reload();
  307. }
  308. window.addEventListener("load", () => {
  309. // Reload the page if 502 CloudFlare error page appears
  310.  
  311. // Wait five seconds, then refresh the page
  312. if (document.body.textContent === "Your client is sending data to MSPFA too quickly. Wait a moment before continuing.") {
  313. setTimeout(() => {
  314. window.location.reload();
  315. }, 5000);
  316. }
  317.  
  318. pageLoaded = true;
  319. });
  320.  
  321. // Delete any unchanged spoiler values
  322. if (location.pathname !== "/my/stories/pages/") {
  323. // Go through spoiler values and remove any that aren't unique
  324. Object.keys(settings.spoilerValues).forEach(adventure => {
  325. if (settings.spoilerValues[adventure].open === "Show" && settings.spoilerValues[adventure].close === "Hide") {
  326. delete settings.spoilerValues[adventure];
  327. } else if (settings.spoilerValues[adventure].open === '' && settings.spoilerValues[adventure].close === '') {
  328. delete settings.spoilerValues[adventure];
  329. }
  330. });
  331. }
  332.  
  333. const styleOptions = ["Standard", "Low Contrast", "Light", "Dark", "Felt", "Trickster", "Custom"];
  334. const styleUrls = ['', '/css/theme1.css', '/css/theme2.css', 'https://pipe.miroware.io/5b52ba1d94357d5d623f74aa/mspfa/themes/dark.css', '/css/theme4.css', '/css/theme5.css'];
  335.  
  336. const createDropdown = (parent, explore) => {
  337. const dropDiv = document.createElement('div');
  338. dropDiv.className = 'dropdown';
  339. dropDiv.style.display = 'inline-block';
  340.  
  341. const dropContent = document.createElement('div');
  342. dropContent.className = 'dropdown-content';
  343. dropContent.style.display = 'none';
  344.  
  345. dropDiv.addEventListener('mouseenter', evt => {
  346. dropContent.style.display = 'block';
  347. dropContent.style.color = getComputedStyle(parent).color;
  348. dropContent.style.backgroundImage = getComputedStyle(parent.parentNode.parentNode).backgroundImage;
  349.  
  350. dropContent.querySelectorAll('a').forEach(link => {
  351. link.style.color = getComputedStyle(parent).color;
  352. link.style.fontSize = getComputedStyle(parent, 'after').fontSize;
  353. });
  354. });
  355.  
  356. if (!explore) {
  357. dropDiv.addEventListener('mouseleave', evt => {
  358. dropContent.style.display = 'none';
  359. });
  360. }
  361.  
  362. parent.parentNode.insertBefore(dropDiv, parent);
  363. dropDiv.appendChild(parent);
  364. dropDiv.appendChild(dropContent);
  365. return [dropDiv, dropContent];
  366. }
  367.  
  368. // "MY MSPFA" dropdown
  369. const myLink = document.querySelector('nav a[href="/my/"]');
  370. if (myLink) {
  371. const dropContent = createDropdown(myLink)[1];
  372.  
  373. const dLinks = [];
  374. dLinks[0] = [ 'Messages', 'My Adventures', 'Settings' ];
  375. dLinks[1] = [ '/my/messages/', '/my/stories/', '/my/settings/' ];
  376.  
  377. for (let i = 0; i < dLinks[0].length; i++) {
  378. const newLink = document.createElement('a');
  379. newLink.textContent = dLinks[0][i];
  380. newLink.href = dLinks[1][i];
  381. dropContent.appendChild(newLink);
  382. }
  383.  
  384. // Append "My Profile" to the dropdown list if you're signed in
  385. pageLoad(() => {
  386. if (window.MSPFA) {
  387. if (window.MSPFA.me.n) {
  388. const newFavLink = document.createElement('a');
  389. newFavLink.textContent = "My Favourites";
  390. newFavLink.href = `/favs/?u=${window.MSPFA.me.i}`;
  391.  
  392. const newMyLink = document.createElement('a');
  393. newMyLink.textContent = "My Profile";
  394. newMyLink.href = `/user/?u=${window.MSPFA.me.i}`;
  395.  
  396. dropContent.appendChild(newFavLink);
  397. dropContent.appendChild(newMyLink);
  398.  
  399. // Move SETTINGS to the bottom
  400. dropContent.appendChild(dropContent.querySelectorAll('a')[2]);
  401. return true;
  402. }
  403. }
  404. },.1);
  405. }
  406.  
  407. // "RANDOM" dropdown
  408. const randomLink = document.querySelector('nav a[href="/random/"]');
  409. if (randomLink) {
  410. // Thank you @MadCreativity 🙏
  411. const dropContent = createDropdown(randomLink)[1];
  412.  
  413. (async () => {
  414. const dLinks = [];
  415. dLinks[0] = [ 'Recent ongoing' ];
  416. dLinks[1] = [ await fetch(`https://mspfa-extras-server.herokuapp.com/api/random`).then(e => e.text()) ];
  417.  
  418. for (let i = 0; i < dLinks[0].length; i++) {
  419. const newLink = document.createElement('a');
  420. newLink.textContent = dLinks[0][i];
  421. newLink.href = dLinks[1][i];
  422. dropContent.appendChild(newLink);
  423. }
  424. })()
  425. }
  426.  
  427. // "EXPLORE" dropdown
  428. const exploreLink = document.querySelector('nav a[href="/stories/"');
  429. if (exploreLink) {
  430. const dropdown = createDropdown(exploreLink, true);
  431. const dropDiv = dropdown[0];
  432. const dropContent = dropdown[1];
  433.  
  434. const userLink = document.createElement('a');
  435. userLink.textContent = 'User Search';
  436. userLink.href = '/?s=36596&p=7'
  437. dropContent.appendChild(userLink);
  438.  
  439. const exploreInput = document.createElement('input');
  440. Object.assign(exploreInput, { type: 'text', placeholder: 'Search...', id: 'dropdown-explore' });
  441. dropContent.appendChild(exploreInput);
  442. exploreInput.addEventListener('keydown', ke => {
  443. if (ke.code === 'Enter') {
  444. const searchLink = `/stories/?go=1&n=${encodeURIComponent(exploreInput.value)}&t=&h=14&o=favs&p=p&m=50&load=true`;
  445. if (ke.altKey || ke.ctrlKey) {
  446. window.open(searchLink, '_blank').focus();
  447. } else {
  448. location.href = searchLink;
  449. }
  450. return;
  451. }
  452. });
  453. dropDiv.addEventListener('mouseleave', evt => {
  454. // If input is focused
  455. if (document.activeElement !== exploreInput) {
  456. dropContent.style.display = 'none';
  457. }
  458. });
  459. document.body.addEventListener('click', evt => {
  460. if (document.activeElement !== exploreInput) {
  461. dropContent.style.display = 'none';
  462. }
  463. });
  464. }
  465.  
  466. document.querySelector('header .mspfalogo').parentNode.draggable = false;
  467. addLink(document.querySelector('footer .mspfalogo'), 'javascript://');
  468.  
  469. // Message that shows when you first get the script
  470. const showIntroDialog = () => {
  471. const msg = window.MSPFA.parseBBCode('Hi! Thanks for installing this script!\n\nBe sure to check the [url=https://greasyfork.org/en/scripts/396798-mspfa-extras#additional-info]GreasyFork[/url] page to see a full list of features, and don\'t forget to check out your [url=https://mspfa.com/my/settings/#extraSettings]settings[/url] page to tweak things to how you want.\n\nIf you have any suggestions, or you find a bug, please be sure to let me know on Discord at [url=discord://discordapp.com/users/277928549866799125]@seymour schlong#3669[/url].\n\n[size=12]This dialog will only appear once. To view it again, click "View Script Message" at the bottom of the site.[/size]');
  472. window.MSPFA.dialog("MSPFA extras message", msg, ["Okay"]);
  473. }
  474.  
  475. // Check if show intro dialog has displayed
  476. if (!settings.intro) {
  477. pageLoad(() => {
  478. if (window.MSPFA) {
  479. showIntroDialog();
  480. settings.intro = true;
  481. saveData(settings);
  482. return true;
  483. }
  484. });
  485. }
  486.  
  487. const details = document.querySelector('#details');
  488.  
  489. // Add 'link' at the bottom to show the intro dialog again
  490. const introLink = document.createElement('a');
  491. introLink.textContent = 'View Script Message';
  492. introLink.href = 'javascript://';
  493. introLink.addEventListener('click', showIntroDialog);
  494. details.appendChild(introLink);
  495.  
  496. // vbar!!!!
  497. const vbar = document.createElement('span');
  498. Object.assign(vbar, {className: 'vbar', textContent: '|'});
  499. details.appendChild(document.createTextNode(' '));
  500. details.appendChild(vbar);
  501. details.appendChild(document.createTextNode(' '));
  502.  
  503. // if you really enjoy the script and has some extra moneys 🥺
  504. const donateLink = document.createElement('a');
  505. donateLink.textContent = 'Donate';
  506. donateLink.href = 'https://ko-fi.com/ironbean';
  507. donateLink.target = "blank";
  508. details.appendChild(donateLink);
  509.  
  510. // Theme stuff
  511. const theme = document.createElement('link');
  512. Object.assign(theme, { id: 'theme', type: 'text/css', rel: 'stylesheet' });
  513. const updateTheme = (src) => {
  514. theme.href = src;
  515. }
  516. if (!document.querySelector('#theme')) {
  517. document.querySelector('head').appendChild(theme);
  518. if (settings.night) {
  519. updateTheme(styleUrls[3]);
  520. } else {
  521. updateTheme(settings.style == styleOptions.length - 1 ? settings.styleURL : styleUrls[settings.style]);
  522. }
  523. }
  524.  
  525. const pixelText = () => {
  526. return settings.pixelFix ? 'body { image-rendering: pixelated; image-rendering: -moz-crisp-edges; } .cellicon { image-rendering: -webkit-optimize-contrast !important; }' : '';
  527. }
  528.  
  529. // Dropdown menu and pixelated scaling
  530. const mspfaeCSS = document.createElement('link');
  531. Object.assign(mspfaeCSS, { id: 'script-css', type: 'text/css', rel: 'stylesheet', href: 'https://pipe.miroware.io/5b52ba1d94357d5d623f74aa/mspfa/mspfae.css' });
  532. document.querySelector('head').appendChild(mspfaeCSS);
  533.  
  534. const extraStyle = document.createElement('style');
  535. if (!document.querySelector('#extra-style')) {
  536. extraStyle.id = 'extra-style';
  537. extraStyle.textContent = pixelText();
  538. document.querySelector('head').appendChild(extraStyle);
  539. }
  540.  
  541. let nightSwitch = [];
  542.  
  543. // Enabling night mode.
  544. document.querySelector('footer .mspfalogo').addEventListener('click', evt => {
  545. settings.night = !settings.night;
  546. saveData(settings);
  547.  
  548. for (let i = 0; i < nightSwitch.length; i++) {
  549. clearTimeout(nightSwitch[i]);
  550. }
  551. nightSwitch = [];
  552.  
  553. // Transition to make it feel nicer on the eyes
  554. extraStyle.textContent = pixelText();
  555. extraStyle.textContent = pixelText() + ' *{transition:1.5s;}';
  556.  
  557. if (settings.night) {
  558. updateTheme(styleUrls[3]);
  559. } else {
  560. updateTheme(settings.style == styleOptions.length - 1 ? settings.styleURL : styleUrls[settings.style]);
  561. }
  562.  
  563. nightSwitch.push(setTimeout(() => {
  564. extraStyle.textContent = pixelText();
  565. }, 1500));
  566. });
  567.  
  568. // Enable keyboard controls for some dialog boxes (enter/esc to accept/close)
  569. const dialog = document.querySelector('#dialog');
  570. document.addEventListener('keydown', evt => {
  571. if (settings.dialogKeys && !dialog.textContent.includes('BBCode')) {
  572. if (dialog.style.display === '' && (evt.code === 'Enter' || evt.code === "Escape") && (document.activeElement === document.body || settings.dialogFocus)) {
  573. let buttons = dialog.querySelectorAll('button');
  574. if (buttons.length === 1) {
  575. buttons[0].click();
  576. } else if (buttons.length === 2) {
  577. if (["Okay", "Yes"].indexOf(buttons[0].textContent) !== -1 && evt.code === "Enter") {
  578. buttons[0].click();
  579. }
  580. }
  581. if (["Cancel", "Close", "No"].indexOf(buttons[buttons.length - 1].textContent) !== -1 && evt.code === "Escape") {
  582. buttons[buttons.length - 1].click();
  583. }
  584. }
  585. }
  586. });
  587.  
  588. if (location.pathname.includes('//')) {
  589. location.href = location.pathname.replace(/\/\//g, '/') + location.search;
  590. }
  591.  
  592. if (location.pathname === "/" || location.pathname === "/preview/") {
  593. if (location.search) {
  594. // Remove the current theme if the adventure has CSS (to prevent conflicts);
  595. if (settings.style > 0) {
  596. pageLoad(() => {
  597. if (window.MSPFA) {
  598. if (window.MSPFA.story && window.MSPFA.story.y && (window.MSPFA.story.y.toLowerCase().includes('import') || window.MSPFA.story.y.includes('{'))) {
  599. if (!settings.night) updateTheme('');
  600. return true;
  601. }
  602. }
  603. if (pageLoaded) return true;
  604. });
  605. }
  606.  
  607. const getPreloadImages = (code) => {
  608. let e = document.createElement("span");
  609. e.innerHTML = code.replace(window.MSPFA.BBC[17][0], window.MSPFA.BBC[17][1]).replace(window.MSPFA.BBC[18][0], window.MSPFA.BBC[18][1]);
  610. let images = e.querySelectorAll("img");
  611. e = '';
  612. return images;
  613. }
  614.  
  615. // Preload adjacent pages
  616. if (settings.preload) {
  617. const preloadImages = document.createElement('div');
  618. preloadImages.id = 'preload';
  619. document.querySelector('#container').appendChild(preloadImages);
  620. window.MSPFA.slide.push(p => {
  621. preloadImages.innerHTML = '';
  622. if (window.MSPFA.story.p[p-2]) {
  623. getPreloadImages(window.MSPFA.story.p[p-2].b).forEach(image => {
  624. preloadImages.appendChild(image);
  625. });
  626. }
  627. if (window.MSPFA.story.p[p]) {
  628. getPreloadImages(window.MSPFA.story.p[p].b).forEach(image => {
  629. preloadImages.appendChild(image);
  630. });
  631. }
  632. });
  633. }
  634.  
  635. // Automatic spoiler opening
  636. if (settings.autospoiler) {
  637. window.MSPFA.slide.push((p) => {
  638. document.querySelectorAll('#slide .spoiler:not(.open) > div:first-child > input').forEach(sb => sb.click());
  639. });
  640. }
  641.  
  642. // Scroll up to the nav bar when changing page so you don't have to scroll down as much =)
  643. if (settings.commandScroll) {
  644. let heightTop = document.querySelector('header').getBoundingClientRect().height;
  645. let temp = -2; // To prevent moving the page down when loading it for the first time
  646. window.MSPFA.slide.push((p) => {
  647. if (temp < 0) {
  648. temp++;
  649. } else {
  650. window.scroll(0, heightTop);
  651. heightTop = document.querySelector('header').getBoundingClientRect().height;
  652. }
  653. });
  654. }
  655.  
  656. // Show creation date
  657. pageLoad(() => {
  658. let infoTd = document.querySelector('#infobox tr td:nth-child(2)');
  659. let dateSpan = document.createElement('span');
  660. dateSpan.id = 'escript-dates';
  661. dateSpan.class = 'escript-elm';
  662. if (infoTd) {
  663. dateSpan.appendChild(document.createTextNode('Creation date: ' + new Date(window.MSPFA.story.d).toString().split(' ').splice(1, 3).join(' ')));
  664. dateSpan.appendChild(newBr());
  665. dateSpan.appendChild(document.createTextNode('Last update: ' + new Date(window.MSPFA.story.p[window.MSPFA.story.p.length-1].d).toString().split(' ').splice(1, 3).join(' ')));
  666. infoTd.appendChild(dateSpan);
  667. return true;
  668. }
  669. });
  670.  
  671. // Hash scrolling and opening infobox or commmentbox
  672. if (['#infobox', '#commentbox', '#newcomment', '#latestpages'].indexOf(hashSearch) !== -1) {
  673. pageLoad(() => {
  674. if (document.querySelector(hashSearch)) {
  675. if (hashSearch === '#infobox') {
  676. document.querySelector('input[data-open="Show Adventure Info"]').click();
  677. } else if (hashSearch === '#commentbox' || hashSearch === '#newcomment') {
  678. document.querySelector('input[data-open="Show Comments"]').click();
  679. } else if (hashSearch === '#latestpages') {
  680. document.querySelector('input[data-open="Show Adventure Info"]').click();
  681. document.querySelector('input[data-open="Show Latest Pages"]').click();
  682. }
  683. return true;
  684. }
  685. });
  686. }
  687.  
  688. // Attempt to fix text errors
  689. if (settings.textFix && location.pathname !== "/preview/") {
  690. pageLoad(() => {
  691. if (window.MSPFA.story && window.MSPFA.story.p) {
  692. // russian/bulgarian is not possible =(
  693. const currentPage = parseInt(/^\?s(?:.*?)&p=([\d]*)$/.exec(location.search)[1]);
  694. const library = [
  695. ["&acirc;��", "'"],
  696. ["&Atilde;�", "Ñ"],
  697. ["&Atilde;&plusmn;", "ñ"],
  698. ["&Atilde;&sup3;", "ó"],
  699. ["&Atilde;&iexcl;", "á"],
  700. ["&Auml;�", "ą"],
  701. ["&Atilde;&shy;", "í"],
  702. ["&Atilde;&ordm;", "ú"],
  703. ["&Atilde;&copy;", "é"],
  704. ["&Aring;�", "ł"],
  705. ["&Aring;&frac14;", "ż"],
  706. ["&Acirc;&iexcl;", "¡"],
  707. ["&Acirc;&iquest;", "¿"],
  708. ["N&Acirc;&ordm;", "#"]
  709. ];
  710. // https://mspfa.com/?s=5280&p=51 -- unknown error
  711.  
  712. const replaceTerms = (p) => {
  713. library.forEach(term => {
  714. if (window.MSPFA.story.p[p]) {
  715. window.MSPFA.story.p[p].c = window.MSPFA.story.p[p].c.replace(new RegExp(term[0], 'g'), term[1]);
  716. window.MSPFA.story.p[p].b = window.MSPFA.story.p[p].b.replace(new RegExp(term[0], 'g'), term[1]);
  717. }
  718. });
  719. };
  720.  
  721. replaceTerms(currentPage-1);
  722.  
  723. window.MSPFA.slide.push(p => {
  724. replaceTerms(p);
  725. replaceTerms(p-2);
  726. });
  727. return true;
  728. }
  729. });
  730. }
  731.  
  732. // Turn buttons into links
  733. const pageButton = document.createElement('button');
  734. const pageLink = addLink(pageButton, `/my/stories/pages/?s=${params.s}#p${params.p}`);
  735. pageButton.className = 'pages edit major';
  736. pageButton.type = 'button';
  737. pageButton.title = 'Edit Pages';
  738.  
  739. // Edit pages button & button link
  740. pageLoad(() => {
  741. const infoButton = document.querySelector('.edit.major');
  742. if (infoButton) {
  743. pageLoad(() => {
  744. if (window.MSPFA.me.i) {
  745. // Change notify and favourite titles to make sense
  746. document.querySelector('.notify.major').title = 'Toggle Notifications';
  747. const favButton = document.querySelector('.fav.major');
  748. let fav = favButton.className.includes(' lit');
  749. const changeTitle = () => {
  750. if (fav) {
  751. favButton.title = 'Unfavorite';
  752. } else {
  753. favButton.title = 'Favorite';
  754. }
  755. }
  756. changeTitle();
  757. favButton.addEventListener('click', () => {
  758. fav = !fav;
  759. changeTitle();
  760. });
  761.  
  762. infoButton.title = "Edit Info";
  763. infoButton.parentNode.insertBefore(pageLink, infoButton);
  764. infoButton.parentNode.insertBefore(document.createTextNode(' '), infoButton);
  765. addLink(infoButton, `/my/stories/info/?s=${params.s}`);
  766. pageButton.style.display = document.querySelector('.edit.major:not(.pages)').style.display;
  767.  
  768. // Change change page link when switching pages
  769. window.MSPFA.slide.push(p => {
  770. const newSearch = location.search.split('&p=');
  771. pageLink.href = `/my/stories/pages/?s=${params.s}#p${newSearch[1].split('#')[0]}`;
  772. });
  773. return true;
  774. }
  775. });
  776. addLink(clearListeners(document.querySelector('.rss.major')), `/rss/?s=${params.s}`);
  777. return true;
  778. }
  779. });
  780.  
  781. // Add "Reply" button next to comment gear
  782. setInterval(() => {
  783. if (document.querySelector('#commentbox > .spoiler.open')) {
  784. document.querySelectorAll('.gear').forEach(gear => {
  785. if (!gear.parentNode.querySelector('.reply')) {
  786. const replyDiv = document.createElement('div');
  787. replyDiv.className = 'reply';
  788. gear.insertAdjacentElement('afterEnd', replyDiv);
  789. gear.insertAdjacentHTML('afterEnd', '<span style="float: right"> </span>');
  790. const userID = gear.parentNode.parentNode.classList[2].replace('u', '');
  791.  
  792. replyDiv.addEventListener('click', () => {
  793. const commentBox = document.querySelector('#commentbox textarea');
  794. commentBox.value = `[user]${userID}[/user], ${commentBox.value}`;
  795. commentBox.focus();
  796. commentBox.parentNode.scrollIntoView();
  797. });
  798. }
  799. });
  800. }
  801. }, 500);
  802. }
  803. }
  804. else if (location.pathname === "/my/") {
  805. const editStories = document.querySelector('#editstories');
  806. editStories.classList.remove('alt');
  807. const parent = editStories.parentNode;
  808. const viewSaves = document.createElement('a');
  809. Object.assign(viewSaves, { id: 'viewsaves', className: 'major', textContent: 'View Adventure Saves' });
  810.  
  811. parent.appendChild(viewSaves);
  812. parent.appendChild(newBr());
  813. parent.appendChild(newBr());
  814.  
  815. pageLoad(() => {
  816. if (window.MSPFA && window.MSPFA.me && window.MSPFA.me.i) {
  817. viewSaves.href = `/?s=36596&p=6`;
  818. return true;
  819. }
  820. },.1);
  821.  
  822. const messages = document.querySelector('#messages');
  823.  
  824. pageLoad(() => {
  825. if (messages.textContent.includes('(')) {
  826. document.title = document.title + messages.textContent.toLowerCase().replace('messages', '');
  827. return true;
  828. }
  829. });
  830. }
  831. else if (location.pathname === "/my/settings/") { // Custom settings
  832. const saveBtn = document.querySelector('#savesettings');
  833.  
  834. const table = document.querySelector("#editsettings tbody");
  835. let saveTr = table.querySelectorAll("tr");
  836. saveTr = saveTr[saveTr.length - 1];
  837.  
  838. const headerTr = document.createElement('tr');
  839. const header = document.createElement('th');
  840. Object.assign(header, { id: 'extraSettings', textContent: 'Extra Settings' });
  841. headerTr.appendChild(header);
  842.  
  843. const settingsTr = document.createElement('tr');
  844. const localMsg = window.MSPFA.parseBBCode('Because this is an extension, any data saved is only [b]locally[/b] on this device.<br>Don\'t forget to [b]save[/b] when you\'ve finished making changes!<br>Click on the <input value="?" class="major" type="button" disabled style="padding: 0"> boxes for descriptions.');
  845. const settingsTd = document.createElement('td');
  846. const plusTable = document.createElement('table');
  847. const plusTbody = document.createElement('tbody');
  848. plusTable.appendChild(plusTbody);
  849. settingsTd.appendChild(localMsg);
  850. settingsTd.appendChild(newBr());
  851. settingsTd.appendChild(newBr());
  852. settingsTd.appendChild(plusTable);
  853. settingsTr.appendChild(settingsTd);
  854.  
  855. plusTable.style = "text-align: center;";
  856.  
  857. // Create checkbox (soooo much better)
  858. const createCheckbox = (text, desc, checked, id) => {
  859. const optionTr = plusTbody.insertRow(plusTbody.childNodes.length);
  860. const optionTextTd = optionTr.insertCell(0);
  861. const optionLabel = createLabel(text, id);
  862. const optionInputTd = optionTr.insertCell(1);
  863. const optionInput = document.createElement('input');
  864. optionInputTd.appendChild(optionInput);
  865.  
  866. optionTextTd.appendChild(optionLabel);
  867. optionInput.type = "checkbox";
  868. optionInput.checked = checked;
  869. optionInput.id = id;
  870.  
  871. const tipButton = document.createElement('input');
  872. Object.assign(tipButton, { className: 'major', value: '?', style: 'padding: 0', type: 'button', title: 'What does enabling this do?' });
  873. tipButton.addEventListener('click', () => {
  874. window.MSPFA.dialog('What does enabling this do?', window.MSPFA.parseBBCode(desc), ["Close"]);
  875. });
  876. optionInputTd.appendChild(document.createTextNode(' '));
  877. optionInputTd.appendChild(tipButton);
  878.  
  879. return optionInput;
  880. }
  881.  
  882. const spoilerInput = createCheckbox("Automatically open spoilers:", 'This will automatically open any spoiler when you change pages without any interaction necessary.', settings.autospoiler, 'autospoiler');
  883. const preloadInput = createCheckbox("Preload images for the pages immediately before and after:", 'The pages directly before and after the one you\'re on will be loaded, saving time loading images and making the experience more seamless.', settings.preload, 'preload');
  884. const errorInput = createCheckbox("Automatically reload Cloudflare 502 error pages:", 'Automatically reloads the webpage when an error occurs from Cloudflare, such as the 520 and 502 errors, as well as refreshing when the "Too Much Data" page shows.', settings.auto502, 'auto502');
  885. const commandScrollInput = createCheckbox("Scroll back up to the nav bar when switching page:", 'When going back and forth pages, scroll back up to the nav bar\'s position so you don\'t have to scroll up each time.', settings.commandScroll, 'commandScroll');
  886. const navStickInput = createCheckbox("Makes the nav bar sticky, and scrolls with you:", 'Scrolling down the page will always show the nav bar.<br>[i]Note: This feature may end up being a bit buggy at times. If any errors occur, please let me know so I can fix them ASAP.[/i]', settings.navStick, 'navStick');
  887. const dialogKeysInput = createCheckbox("Use enter/escape keys to accept/exit control some dialogs:", 'Some dialogs can now be closed out of or confirmed by pressing the Escape or Enter keys respectively. The Escape key can close most dialogs.', settings.dialogKeys, 'dialogKeys');
  888. const dialogFocusInput = createCheckbox("Let keys work while dialog isn't focused (above required):", 'While the Dialog Keys option is enabled, you can press keys to press the buttons regardless of whether or not it\'s not focused.', settings.dialogFocus, 'dialogFocus');
  889. const pixelFixInput = createCheckbox("Change pixel scaling to nearest neighbour:", 'Makes images scale up or down using nearest neighbour to prevent making the images fuzzy when zooming in, or on monitors with upscaling. This is disabled for images with the .cellicon class.', settings.pixelFix, 'pixelFix');
  890. const textFixInput = createCheckbox("Attempt to fix text errors (experimental):", 'When changing pages, attempts to fix unicode errors and broken text.<br>This only applies to a select few older adventures that have had their text corrupted. Some punctuation is fixed, as well as regular characters with accents. Currently only some spanish/french is fixable. Russian/Bulgarian is not possible.', settings.textFix, 'textFix');
  891.  
  892. const cssTr = plusTbody.insertRow(plusTbody.childNodes.length);
  893. const cssTextTd = cssTr.insertCell(0);
  894. const cssSelectTd = cssTr.insertCell(1);
  895. const cssSelect = document.createElement('select');
  896. cssSelectTd.appendChild(cssSelect);
  897.  
  898. cssTextTd.textContent = "Change style:";
  899.  
  900. const customTr = plusTbody.insertRow(plusTbody.childNodes.length);
  901. const customTextTd = customTr.insertCell(0);
  902. const customCssTd = customTr.insertCell(1);
  903. const customCssInput = document.createElement('input');
  904. customCssTd.appendChild(customCssInput);
  905.  
  906. customTextTd.textContent = "Custom CSS URL:";
  907. customCssInput.style.width = "99px";
  908. customCssInput.value = settings.styleURL;
  909.  
  910. styleOptions.forEach(o => cssSelect.appendChild(new Option(o, o)));
  911.  
  912. saveTr.parentNode.insertBefore(headerTr, saveTr);
  913. saveTr.parentNode.insertBefore(settingsTr, saveTr);
  914. cssSelect.selectedIndex = settings.style;
  915.  
  916. const buttonSpan = document.createElement('span');
  917. const draftButton = document.createElement('input');
  918. const spoilerButton = document.createElement('input');
  919. draftButton.value = 'Manage Drafts';
  920. draftButton.className = 'major';
  921. draftButton.type = 'button';
  922. spoilerButton.value = 'Manage Spoiler Values';
  923. spoilerButton.className = 'major';
  924. spoilerButton.type = 'button';
  925. buttonSpan.appendChild(draftButton);
  926. buttonSpan.appendChild(document.createTextNode(' '));
  927. buttonSpan.appendChild(spoilerButton);
  928. settingsTd.appendChild(buttonSpan);
  929.  
  930. const draftMsg = window.MSPFA.parseBBCode('Here you can manage the drafts that you have saved for your adventure(s).\n');
  931. const listTable = document.createElement('table');
  932. listTable.id = 'draft-table';
  933. const listTbody = document.createElement('tbody');
  934. listTable.appendChild(listTbody);
  935.  
  936. const draftsEmpty = () => {
  937. loadDrafts();
  938. let empty = true;
  939. Object.keys(drafts).forEach(adv => {
  940. if (empty) {
  941. const length = typeof drafts[adv].cachedTitle === "undefined" ? 0 : 1;
  942. if (Object.keys(drafts[adv]).length > length) {
  943. empty = false;
  944. }
  945. }
  946. });
  947. return empty;
  948. }
  949.  
  950. setInterval(() => {
  951. draftButton.disabled = draftsEmpty();
  952. }, 1000);
  953.  
  954. draftButton.addEventListener('click', () => {
  955. draftMsg.appendChild(listTable);
  956. listTbody.innerHTML = '';
  957. loadDrafts();
  958.  
  959. const addAdv = (story, name) => {
  960. const storyTr = listTbody.insertRow(listTable.rows);
  961. const titleLink = document.createElement('a');
  962. Object.assign(titleLink, { className: 'major', href: `/my/stories/pages/?s=${story}&click=d`, textContent: name, target: '_blank' });
  963. storyTr.insertCell(0).appendChild(titleLink);
  964. const deleteButton = document.createElement('input');
  965. Object.assign(deleteButton, { className: 'major', type: 'button', value: 'Delete' });
  966. storyTr.insertCell(1).appendChild(deleteButton);
  967.  
  968. deleteButton.addEventListener('click', () => {
  969. setTimeout(() => {
  970. window.MSPFA.dialog('Delete adventure draft?', document.createTextNode('Are you really sure?\nThis action cannot be undone!'), ["Yes", "No"], (output, form) => {
  971. if (output === "Yes") {
  972. loadDrafts();
  973. drafts[story] = {};
  974.  
  975. if (settings.drafts && settings.drafts[story]) {
  976. delete settings.drafts[story];
  977. saveData(settings);
  978. }
  979.  
  980. saveDrafts(drafts);
  981.  
  982. setTimeout(() => {
  983. draftButton.click();
  984. }, 1);
  985.  
  986. if (draftsEmpty) {
  987. draftButton.disabled = true;
  988. }
  989. }
  990. });
  991. }, 1);
  992. });
  993. }
  994.  
  995. Object.keys(drafts).forEach(adv => {
  996. const length = typeof drafts[adv].cachedTitle === "undefined" ? 0 : 1;
  997. if (Object.keys(drafts[adv]).length > length) {
  998. if (!!length) {
  999. addAdv(adv, drafts[adv].cachedTitle);
  1000. }
  1001. else {
  1002. window.MSPFA.request(0, {
  1003. do: "story",
  1004. s: adv
  1005. }, story => {
  1006. if (typeof story !== "undefined") {
  1007. console.log(story);
  1008. addAdv(adv, story.n);
  1009. }
  1010. });
  1011. }
  1012. }
  1013. });
  1014.  
  1015. window.MSPFA.dialog('Manage Drafts', draftMsg, ["Delete All", "Close"], (output, form) => {
  1016. if (output === "Delete All") {
  1017. setTimeout(() => {
  1018. window.MSPFA.dialog('Delete all Drafts?', document.createTextNode('Are you really sure?\nThis action cannot be undone!'), ["Yes", "No"], (output, form) => {
  1019. if (output === "Yes") {
  1020. Object.keys(drafts).forEach(adv => {
  1021. drafts[adv] = {};
  1022. });
  1023. saveDrafts(drafts);
  1024.  
  1025. if (typeof settings.drafts !== "undefined") {
  1026. delete settings.drafts;
  1027. saveData(settings);
  1028. }
  1029.  
  1030. draftButton.disabled = true;
  1031. }
  1032. });
  1033. }, 1);
  1034. }
  1035. });
  1036. });
  1037.  
  1038. if (Object.keys(settings.spoilerValues).length === 0) {
  1039. spoilerButton.disabled = true;
  1040. }
  1041.  
  1042. const spoilerMsg = window.MSPFA.parseBBCode('Here you can manage the spoiler values that you have set for your adventure(s).\nClick on an adventure\'s title to see the values.\n');
  1043.  
  1044. spoilerButton.addEventListener('click', () => {
  1045. spoilerMsg.appendChild(listTable);
  1046. listTbody.innerHTML = '';
  1047. Object.keys(settings.spoilerValues).forEach(adv => {
  1048. window.MSPFA.request(0, {
  1049. do: "story",
  1050. s: adv
  1051. }, story => {
  1052. if (typeof story !== "undefined") {
  1053. const storyTr = listTbody.insertRow(listTable.rows);
  1054. const titleLink = document.createElement('a');
  1055. Object.assign(titleLink, { className: 'major', href: `/my/stories/pages/?s=${adv}&click=s`, textContent: story.n, target: '_blank' });
  1056. storyTr.insertCell(0).appendChild(titleLink);
  1057. const deleteButton = document.createElement('input');
  1058. Object.assign(deleteButton, { className: 'major', type: 'button', value: 'Delete' });
  1059. storyTr.insertCell(1).appendChild(deleteButton);
  1060.  
  1061. deleteButton.addEventListener('click', () => {
  1062. setTimeout(() => {
  1063. window.MSPFA.dialog('Delete adventure spoilers?', document.createTextNode('Are you really sure?\nThis action cannot be undone!'), ["Yes", "No"], (output, form) => {
  1064. if (output === "Yes") {
  1065. delete settings.spoilerValues[adv];
  1066. saveData(settings);
  1067.  
  1068. setTimeout(() => {
  1069. spoilerButton.click();
  1070. }, 1);
  1071.  
  1072. if (Object.keys(settings.spoilerValues).length === 0) {
  1073. spoilerButton.disabled = true;
  1074. }
  1075. }
  1076. });
  1077. }, 1);
  1078. });
  1079. }
  1080. });
  1081. });
  1082. window.MSPFA.dialog('Manage Spoiler Values', spoilerMsg, ["Delete All", "Close"], (output, form) => {
  1083. if (output === "Delete All") {
  1084. setTimeout(() => {
  1085. window.MSPFA.dialog('Delete all Spoiler Values?', 'Are you sure you want to delete all spoiler values?\nThis action cannot be undone!', ["Yes", "No"], (output, form) => {
  1086. if (output === "Yes") {
  1087. settings.spoilerValues = {};
  1088. saveData(settings);
  1089. spoilerButton.disabled = true;
  1090. }
  1091. });
  1092. }, 1);
  1093. }
  1094. });
  1095. });
  1096.  
  1097. // Add event listeners
  1098. plusTbody.querySelectorAll('input, select').forEach(elm => {
  1099. elm.addEventListener("change", () => {
  1100. saveBtn.disabled = false;
  1101. });
  1102. });
  1103.  
  1104. saveBtn.addEventListener('mouseup', () => {
  1105. settings.autospoiler = spoilerInput.checked;
  1106. settings.style = cssSelect.selectedIndex;
  1107. settings.styleURL = customCssInput.value;
  1108. settings.auto502 = errorInput.checked;
  1109. settings.textFix = textFixInput.checked;
  1110. settings.pixelFix = pixelFixInput.checked;
  1111. settings.dialogKeys = dialogKeysInput.checked;
  1112. settings.dialogFocus = dialogFocusInput.checked;
  1113. settings.commandScroll = commandScrollInput.checked;
  1114. settings.preload = preloadInput.checked;
  1115. settings.navStick = navStickInput.checked;
  1116. settings.night = false;
  1117. console.log(settings);
  1118. saveData(settings);
  1119.  
  1120. updateTheme(settings.style == styleOptions.length - 1 ? settings.styleURL : styleUrls[settings.style]);
  1121.  
  1122. extraStyle.textContent = pixelText() + ' *{transition:1s}';
  1123.  
  1124. extraStyle.textContent = pixelText();
  1125. setTimeout(() => {
  1126. extraStyle.textContent = pixelText();
  1127. }, 1000);
  1128. });
  1129. }
  1130. else if (location.pathname === "/my/messages/") { // New buttons
  1131. // Select all read messages button.
  1132. const selRead = document.createElement('input');
  1133. Object.assign(selRead, { value: 'Select Read', className: 'major', type: 'button' });
  1134.  
  1135. // On click, select all messages with the style attribute indicating it as read.
  1136. selRead.addEventListener('mouseup', () => {
  1137. document.querySelectorAll('td[style="border-left: 8px solid rgb(221, 221, 221);"] > input').forEach((m) => m.click());
  1138. });
  1139.  
  1140. // Select duplicate message (multiple update notifications).
  1141. const selDupe = document.createElement('input');
  1142. Object.assign(selDupe, { value: 'Select Same', className: 'major', type: 'button', style: 'margin-top: 6px' });
  1143.  
  1144. selDupe.addEventListener('mouseup', evt => {
  1145. const temp = document.querySelectorAll('#messages > tr');
  1146. const msgs = [];
  1147. for (let i = temp.length - 1; i >= 0; i--) {
  1148. msgs.push(temp[i]);
  1149. }
  1150. const titles = [];
  1151. msgs.forEach((msg) => {
  1152. const title = msg.querySelector('a.major').textContent;
  1153. // Select only adventure updates
  1154. if (/^New update: /.test(title)) {
  1155. if (titles.indexOf(title) === -1) {
  1156. if (msg.querySelector('td').style.cssText !== "border-left: 8px solid rgb(221, 221, 221);") {
  1157. titles.push(title);
  1158. }
  1159. } else {
  1160. msg.querySelector('input').click();
  1161. }
  1162. }
  1163. });
  1164. });
  1165.  
  1166. // Prune button
  1167. const pruneButton = document.createElement('input');
  1168. Object.assign(pruneButton, { type: 'button', value: 'Prune', className: 'major' });
  1169.  
  1170. pruneButton.addEventListener('click', () => {
  1171. const ageInput = document.createElement('input');
  1172. Object.assign(ageInput, { type: 'number', min: 1, max: 10, value: 1 });
  1173.  
  1174. const msgState = document.createElement('select');
  1175. ['all', 'all unread', 'all read'].forEach(option => {
  1176. const op = document.createElement('option');
  1177. op.textContent = option;
  1178. msgState.appendChild(op);
  1179. });
  1180.  
  1181. const timeUnit = document.createElement('select');
  1182. ['month(s)', 'week(s)', 'day(s)'].forEach(option => {
  1183. const op = document.createElement('option');
  1184. op.textContent = option;
  1185. timeUnit.appendChild(op);
  1186. });
  1187. timeUnit.childNodes[1].setAttribute('selected', 'selected');
  1188.  
  1189. const msg = document.createElement('span');
  1190. msg.appendChild(document.createTextNode('Prune '));
  1191. msg.appendChild(msgState);
  1192. msg.appendChild(document.createTextNode(' messages older than '));
  1193. msg.appendChild(ageInput);
  1194. msg.appendChild(timeUnit);
  1195.  
  1196. window.MSPFA.dialog('Prune messages', msg, ['Prune', 'Cancel'], (output, form) => {
  1197. if (output === 'Prune') {
  1198. document.querySelector('#messages').childNodes.forEach(node => {
  1199. if (node.firstChild.firstChild.checked) {
  1200. node.firstChild.firstChild.click();
  1201. }
  1202.  
  1203. const selectedState = msgState.selectedOptions[0].textContent;
  1204. const selectedUnit = timeUnit.selectedOptions[0].textContent;
  1205.  
  1206. if (selectedState === 'all unread') {
  1207. if (node.firstChild.style.borderLeftColor === 'rgb(221, 221, 221)') {
  1208. return;
  1209. }
  1210. }
  1211. else if (selectedState === 'all read') {
  1212. if (node.firstChild.style.borderLeftColor === 'rgb(92, 174, 223)') {
  1213. return;
  1214. }
  1215. }
  1216. const dateText = node.childNodes[2].childNodes[2].textContent.split(' - ');
  1217. const messageDate = new Date(dateText[dateText.length-1]);
  1218. const currentDate = Date.now();
  1219. const diff = Math.floor(Math.round((currentDate-messageDate)/(1000*60*60))/24); // Difference in days
  1220.  
  1221. if (selectedUnit === 'month(s)') diff = Math.floor(diff / 30);
  1222. else if (selectedUnit === 'week(s)') diff = Math.floor(diff / 7);
  1223.  
  1224. if (diff >= ageInput.value) {
  1225. node.firstChild.firstChild.click();
  1226. }
  1227. });
  1228.  
  1229. setTimeout(() => {
  1230. document.querySelector('input[value=Delete]').click();
  1231. }, 1);
  1232. }
  1233. });
  1234. });
  1235.  
  1236. // Maybe add a "Merge Updates" button?
  1237. // [Merge Updates] would create a list of updates, similar to [Select Same]
  1238.  
  1239. // Add buttons to the page.
  1240. const del = document.querySelector('#deletemsgs');
  1241. del.parentNode.appendChild(newBr());
  1242. del.parentNode.appendChild(selRead);
  1243. del.parentNode.appendChild(document.createTextNode(' '));
  1244. del.parentNode.appendChild(selDupe);
  1245. del.parentNode.appendChild(document.createTextNode(' '));
  1246. del.parentNode.appendChild(pruneButton);
  1247.  
  1248. // Click the green cube to open the update/comment in a new tab, and mark notification as read.
  1249. pageLoad(() => {
  1250. if (document.querySelector('#messages').childNodes.length > 0) {
  1251. if (document.querySelector('#messages').textContent === 'No new messages were found.') {
  1252. // Disable some buttons if there are no messages.
  1253. pruneButton.disabled = true;
  1254. selDupe.disabled = true;
  1255. return true;
  1256. } else {
  1257. document.querySelector('#messages').childNodes.forEach(node => {
  1258. if (node.textContent.includes('New update:') && node.textContent.includes('MS Paint Fan Adventures')) {
  1259. const link = addLink(node.querySelector('.cellicon'), node.querySelector('.spoiler a').href);
  1260. link.addEventListener('mouseup', () => {
  1261. const spoiler = node.querySelector('.spoiler');
  1262. const button = spoiler.querySelector('input');
  1263. spoiler.className = 'spoiler closed';
  1264. button.click();
  1265. button.click();
  1266. });
  1267. }
  1268. else if ((node.textContent.includes('New comment on ') || node.textContent.includes('You were tagged on ')) && node.textContent.includes('MS Paint Fan Adventures')) {
  1269. const link = addLink(node.querySelector('.cellicon'), node.querySelectorAll('.spoiler a')[1].href + '#commentbox');
  1270. link.addEventListener('mouseup', () => {
  1271. const spoiler = node.querySelector('.spoiler');
  1272. const button = spoiler.querySelector('input');
  1273. spoiler.className = 'spoiler closed';
  1274. button.click();
  1275. button.click();
  1276. });
  1277. }
  1278. });
  1279. return true;
  1280. }
  1281. }
  1282. });
  1283. }
  1284. else if (location.pathname === "/my/messages/new/" && location.search) { // Auto-fill user when linked from a user page
  1285. const recipientInput = document.querySelector('#addrecipient');
  1286. recipientInput.value = params.u;
  1287. pageLoad(() => {
  1288. const recipientButton = document.querySelector('#addrecipientbtn');
  1289. if (recipientButton) {
  1290. recipientButton.click();
  1291. if (recipientInput.value === "") { // If the button press doesn't work
  1292. return true;
  1293. }
  1294. }
  1295. });
  1296. }
  1297. else if (location.pathname === "/my/stories/") {
  1298. // Add links to buttons
  1299. pageLoad(() => {
  1300. const adventures = document.querySelectorAll('#stories tr');
  1301. if (adventures.length > 0) {
  1302. adventures.forEach(story => {
  1303. const buttons = story.querySelectorAll('input.major');
  1304. const id = story.querySelector('a').href.replace('https://mspfa.com/', '').replace('&p=1', '');
  1305. if (id) {
  1306. addLink(buttons[0], `/my/stories/info/${id}`);
  1307. addLink(buttons[1], `/my/stories/pages/${id}`);
  1308. addLink(story.querySelector('img'), `/${id}&p=1`);
  1309. }
  1310. });
  1311. return true;
  1312. }
  1313. if (pageLoaded) return true;
  1314. });
  1315.  
  1316. // Add user guides
  1317. const guides = ["A Guide To Uploading Your Comic To MSPFA", "MSPFA Etiquette", "Fanventure Guide for Dummies", "CSS Guide", "HTML and CSS Things", ];
  1318. const links = ["https://docs.google.com/document/d/17QI6Cv_BMbr8l06RrRzysoRjASJ-ruWioEtVZfzvBzU/edit?usp=sharing", "/?s=27631", "/?s=29299", "/?s=21099", "/?s=23711"];
  1319. const authors = ["Farfrom Tile", "Radical Dude 42", "nzar", "MadCreativity", "seymour schlong"];
  1320.  
  1321. const parentTd = document.querySelector('.container > tbody > tr:last-child > td');
  1322. const unofficial = parentTd.querySelector('span');
  1323. unofficial.textContent = "Unofficial Guides";
  1324. const guideTable = document.createElement('table');
  1325. const guideTbody = document.createElement('tbody');
  1326. guideTable.style.width = "100%";
  1327. guideTable.style.textAlign = "center";
  1328.  
  1329. guideTable.appendChild(guideTbody);
  1330. parentTd.appendChild(guideTable);
  1331.  
  1332. for (let i = 0; i < guides.length; i++) {
  1333. const guideTr = guideTbody.insertRow(i);
  1334. const guideTd = guideTr.insertCell(0);
  1335. const guideLink = document.createElement('a');
  1336. Object.assign(guideLink, { href: links[i], textContent: guides[i], className: 'major' });
  1337. guideTd.appendChild(guideLink);
  1338. guideTd.appendChild(newBr());
  1339. guideTd.appendChild(document.createTextNode('by '+authors[i]));
  1340. guideTd.appendChild(newBr());
  1341. guideTd.appendChild(newBr());
  1342. }
  1343. }
  1344. else if (location.pathname === "/my/stories/info/" && location.search) {
  1345. // Button links
  1346. addLink(document.querySelector('#userfavs'), `/readers/?s=${params.s}`);
  1347. addLink(document.querySelector('#editpages'), `/my/stories/pages/?s=${params.s}`);
  1348.  
  1349. // Reorder some elements under Icons to be more sensible
  1350. const bannerInput = document.querySelector('input[name="storybanner"]');
  1351. bannerInput.parentNode.style.paddingLeft = '130px';
  1352. const bannerPrev = document.querySelector(`a[href="/?b=${params.s}`);
  1353. bannerPrev.parentNode.insertBefore(bannerPrev, bannerInput.nextSibling);
  1354.  
  1355. bannerInput.parentNode.removeChild(document.querySelector('#storyicon').nextSibling);
  1356.  
  1357. if (params.s !== 'new') {
  1358. // Download adventure data
  1359. const downloadButton = document.createElement('input');
  1360. Object.assign(downloadButton, { className: 'major', value: 'Export Data', type: 'button', style: 'margin-top: 6px' });
  1361. const downloadLink = document.createElement('a');
  1362. window.MSPFA.request(0, {
  1363. do: "story",
  1364. s: params.s
  1365. }, (s) => {
  1366. if (s) {
  1367. downloadLink.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(s, null, 4)));
  1368.  
  1369. // Display week of anniversary banner
  1370. const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
  1371. const ann = new Date(s.d);
  1372. const end = new Date(s.d + 7*24*60*60*1000);
  1373. bannerInput.parentNode.insertBefore(document.createTextNode(months[ann.getMonth()] + ' ' + ann.getDate() + ' - ' + months[end.getMonth()] + ' ' + end.getDate()), bannerInput.nextSibling.nextSibling);
  1374. bannerInput.parentNode.insertBefore(newBr(), bannerInput.nextSibling.nextSibling);
  1375. }
  1376. });
  1377. downloadLink.setAttribute('download', `${params.s}.json`);
  1378. downloadLink.appendChild(downloadButton);
  1379. document.querySelector('#savestory').parentNode.appendChild(newBr());
  1380. document.querySelector('#savestory').parentNode.appendChild(downloadLink);
  1381. }
  1382. }
  1383. else if (location.pathname === "/my/stories/pages/" && location.search) {
  1384. const adventureID = params.s;
  1385.  
  1386. const notifyLabel = createLabel('Notify readers of new pages during this editing session: ', 'notifyreaders');
  1387. const notifyButton = document.querySelector('#notifyreaders');
  1388. notifyButton.previousSibling.textContent = '';
  1389. notifyButton.parentNode.insertBefore(notifyLabel, notifyButton);/**/
  1390.  
  1391. if (!drafts[adventureID]) {
  1392. drafts[adventureID] = {};
  1393. saveDrafts(drafts);
  1394. }
  1395.  
  1396. pageLoad(() => {
  1397. if (document.querySelector('#storyname').textContent !== '-') {
  1398. drafts[adventureID].cachedTitle = document.querySelector('#storyname').textContent;
  1399. saveDrafts(drafts);
  1400. return true;
  1401. }
  1402. });
  1403.  
  1404. // Button links
  1405. addLink(document.querySelector('#editinfo'), `/my/stories/info/?s=${adventureID}`);
  1406.  
  1407. // Default spoiler values
  1408. const replaceButton = document.querySelector('#replaceall');
  1409. const spoilerButton = document.createElement('input');
  1410. Object.assign(spoilerButton, { className: 'major', value: 'Default Spoiler Values', type: 'button'});
  1411. replaceButton.parentNode.insertBefore(spoilerButton, replaceButton);
  1412. replaceButton.parentNode.insertBefore(newBr(), replaceButton);
  1413. replaceButton.parentNode.insertBefore(newBr(), replaceButton);
  1414.  
  1415. if (!settings.spoilerValues[adventureID]) {
  1416. settings.spoilerValues[adventureID] = {
  1417. open: 'Show',
  1418. close: 'Hide'
  1419. }
  1420. }
  1421.  
  1422. spoilerButton.addEventListener('click', evt => {
  1423. const spoilerSpan = document.createElement('span');
  1424. const spoilerOpen = document.createElement('input');
  1425. const spoilerClose = document.createElement('input');
  1426. spoilerSpan.appendChild(document.createTextNode('Open button text:'));
  1427. spoilerSpan.appendChild(newBr());
  1428. spoilerSpan.appendChild(spoilerOpen);
  1429. spoilerSpan.appendChild(newBr());
  1430. spoilerSpan.appendChild(newBr());
  1431. spoilerSpan.appendChild(document.createTextNode('Close button text:'));
  1432. spoilerSpan.appendChild(newBr());
  1433. spoilerSpan.appendChild(spoilerClose);
  1434.  
  1435. spoilerOpen.value = settings.spoilerValues[adventureID].open;
  1436. spoilerClose.value = settings.spoilerValues[adventureID].close;
  1437.  
  1438. window.MSPFA.dialog('Default Spoiler Values', spoilerSpan, ['Save', 'Cancel'], (output, form) => {
  1439. if (output === 'Save') {
  1440. settings.spoilerValues[adventureID].open = spoilerOpen.value === '' ? 'Show' : spoilerOpen.value;
  1441. settings.spoilerValues[adventureID].close = spoilerClose.value === '' ? 'Hide' : spoilerClose.value;
  1442. if (settings.spoilerValues[adventureID].open === 'Show' && settings.spoilerValues[adventureID].close === 'Hide') {
  1443. delete settings.spoilerValues[adventureID];
  1444. }
  1445. saveData(settings);
  1446. }
  1447. });
  1448. });
  1449.  
  1450. document.querySelector('input[title="Spoiler"]').addEventListener('click', evt => {
  1451. document.querySelector('#dialog input[name="open"]').value = document.querySelector('#dialog input[name="open"]').placeholder = settings.spoilerValues[adventureID].open;
  1452. document.querySelector('#dialog input[name="close"]').value = document.querySelector('#dialog input[name="close"]').placeholder = settings.spoilerValues[adventureID].close;
  1453. });
  1454.  
  1455. // --- Custom BBToolbar buttons
  1456. // Buttonless spoilers
  1457. const flashButton = document.querySelector('input[title=Flash]');
  1458. const newSpoilerButton = document.createElement('input');
  1459. newSpoilerButton.setAttribute('data-tag', 'Buttonless Spoiler');
  1460. Object.assign(newSpoilerButton, { title: 'Buttonless Spoiler', type: 'button', style: 'background-position: -66px -88px;' });
  1461.  
  1462. newSpoilerButton.addEventListener('click', evt => {
  1463. const bbe = document.querySelector('#bbtoolbar').parentNode.querySelector('textarea');
  1464. if (bbe) {
  1465. bbe.focus();
  1466. const start = bbe.selectionStart;
  1467. const end = bbe.selectionEnd;
  1468. bbe.value = bbe.value.slice(0, start) + '<div class="spoiler"><div>' + bbe.value.slice(start, end) + '</div></div>' + bbe.value.slice(end);
  1469. bbe.selectionStart = start + 26;
  1470. bbe.selectionEnd = end + 26;
  1471. }
  1472. });
  1473.  
  1474. flashButton.parentNode.insertBefore(newSpoilerButton, flashButton);
  1475.  
  1476. // Audio button
  1477. const audioButton = document.createElement('input');
  1478. Object.assign(audioButton, { title: 'Audio Player', type: 'button', style: 'background-position: -22px -110px' });
  1479.  
  1480. audioButton.addEventListener('click', evt => {
  1481. const bbe = document.querySelector('#bbtoolbar').parentNode.querySelector('textarea');
  1482. if (bbe) {
  1483. const msg = window.MSPFA.parseBBCode('Audio URL:<br>');
  1484. const audioInput = document.createElement('input');
  1485. Object.assign(audioInput, { type: 'url', name: 'audio-url', required: true });
  1486.  
  1487. const autoplayButton = document.createElement('input');
  1488. autoplayButton.type = 'checkbox';
  1489. autoplayButton.id = 'autoplay';
  1490. autoplayButton.checked = true;
  1491.  
  1492. const loopButton = document.createElement('input');
  1493. loopButton.type = 'checkbox';
  1494. loopButton.id = 'loop';
  1495. loopButton.checked = true;
  1496.  
  1497. const controlsButton = document.createElement('input');
  1498. controlsButton.type = 'checkbox';
  1499. controlsButton.id = 'controls';
  1500.  
  1501. msg.appendChild(audioInput);
  1502. msg.appendChild(newBr());
  1503. msg.appendChild(createLabel('Autoplay: ', 'autoplay'));
  1504. msg.appendChild(autoplayButton);
  1505. msg.appendChild(newBr());
  1506. msg.appendChild(createLabel('Loop: ', 'loop'));
  1507. msg.appendChild(loopButton);
  1508. msg.appendChild(newBr());
  1509. msg.appendChild(createLabel('Show controls: ', 'controls'));
  1510. msg.appendChild(controlsButton);
  1511. msg.appendChild(newBr());
  1512.  
  1513. window.MSPFA.dialog("Audio Player", msg, ["Okay", "Cancel"], (output, form) => {
  1514. if (output == "Okay") {
  1515. bbe.focus();
  1516. const start = bbe.selectionStart;
  1517. const end = bbe.selectionEnd;
  1518. const properties = `"${autoplayButton.checked ? ' autoplay' : ''}${loopButton.checked ? ' loop' : ''}${controlsButton.checked ? ' controls' : ''}`;
  1519. bbe.value = bbe.value.slice(0, start) + '<audio src="' + audioInput.value + properties +'>' + bbe.value.slice(start);
  1520. bbe.selectionStart = start + properties.length + audioInput.value.length + 13;
  1521. bbe.selectionEnd = end + properties.length + audioInput.value.length + 13;
  1522. }
  1523.  
  1524. });
  1525.  
  1526. audioInput.select();
  1527. }
  1528. });
  1529.  
  1530. flashButton.insertAdjacentElement('afterEnd', audioButton);
  1531.  
  1532. // YouTube button
  1533. const youtubeButton = document.createElement('input');
  1534. Object.assign(youtubeButton, { title: 'YouTube Video', type: 'button', style: 'background-position: 0px -110px' });
  1535.  
  1536. youtubeButton.addEventListener('click', evt => {
  1537. const bbe = document.querySelector('#bbtoolbar').parentNode.querySelector('textarea');
  1538. if (bbe) {
  1539. const msg = window.MSPFA.parseBBCode('Video URL:<br>');
  1540. const videoUrl = document.createElement('input');
  1541. videoUrl.type = 'url';
  1542. videoUrl.name = 'youtube';
  1543. videoUrl.required = true;
  1544.  
  1545. const autoplayButton = document.createElement('input');
  1546. autoplayButton.type = 'checkbox';
  1547. autoplayButton.checked = true;
  1548. autoplayButton.id = 'autoplay';
  1549.  
  1550. const controlsButton = document.createElement('input');
  1551. controlsButton.type = 'checkbox';
  1552. controlsButton.checked = true;
  1553. controlsButton.id = 'controls';
  1554.  
  1555. const fullscreenButton = document.createElement('input');
  1556. fullscreenButton.type = 'checkbox';
  1557. fullscreenButton.checked = true;
  1558. fullscreenButton.id = 'fullscreen';
  1559.  
  1560. const widthInput = document.createElement('input');
  1561. Object.assign(widthInput, { type: 'number', required: true, value: 650, style: 'width: 5em' });
  1562.  
  1563. const heightInput = document.createElement('input');
  1564. Object.assign(heightInput, { type: 'number', required: true, value: 450, style: 'width: 5em' });
  1565.  
  1566. msg.appendChild(videoUrl);
  1567. msg.appendChild(newBr());
  1568. msg.appendChild(createLabel('Autoplay: ', 'autoplay'));
  1569. msg.appendChild(autoplayButton);
  1570. msg.appendChild(newBr());
  1571. msg.appendChild(createLabel('Show controls: ', 'controls'));
  1572. msg.appendChild(controlsButton);
  1573. msg.appendChild(newBr());
  1574. msg.appendChild(createLabel('Allow fullscreen: ', 'fullscreen'));
  1575. msg.appendChild(fullscreenButton);
  1576. msg.appendChild(newBr());
  1577. msg.appendChild(document.createTextNode('Embed size: '));
  1578. msg.appendChild(widthInput);
  1579. msg.appendChild(document.createTextNode('x'));
  1580. msg.appendChild(heightInput);
  1581.  
  1582. window.MSPFA.dialog("YouTube Embed", msg, ["Okay", "Cancel"], (output, form) => {
  1583. if (output == "Okay") {
  1584. let videoID = videoUrl.value.split('/');
  1585. videoID = videoID[videoID.length-1].replace('watch?v=', '').split('&')[0];
  1586.  
  1587. bbe.focus();
  1588. const start = bbe.selectionStart;
  1589. const end = bbe.selectionEnd;
  1590. const iframeContent = `<iframe width="${widthInput.value}" height="${heightInput.value}" src="https://www.youtube.com/embed/${videoID}?autoplay=${+autoplayButton.checked}&controls=${+controlsButton.checked}" frameborder="0" allow="accelerometer; ${autoplayButton.checked ? 'autoplay; ' : ''}encrypted-media;"${fullscreenButton.checked ? ' allowfullscreen' : ''}></iframe>`;
  1591. bbe.value = bbe.value.slice(0, start) + iframeContent + bbe.value.slice(start);
  1592. bbe.selectionStart = start + iframeContent + 13;
  1593. bbe.selectionEnd = end + iframeContent + 13;
  1594. }
  1595.  
  1596. });
  1597.  
  1598. videoUrl.select();
  1599. }
  1600. });
  1601.  
  1602. flashButton.insertAdjacentElement('afterEnd', youtubeButton);
  1603. flashButton.insertAdjacentText('afterEnd', ' ');
  1604.  
  1605. // Get preview link
  1606. const getPreviewLink = (form) => {
  1607. const page = parseInt(form.querySelector('a.major').textContent.replace('Page ', ''));
  1608. return "/preview/?s=" + params.s + "&p=" + page + "&d=" + encodeURIComponent(JSON.stringify({
  1609. p: page,
  1610. c: form.querySelector('input[name=cmd]').value,
  1611. b: form.querySelector('textarea[name=body]').value,
  1612. n: form.querySelector('input[name=next]').value,
  1613. k: !form.querySelector('input[name=usekeys]').checked
  1614. }));
  1615. }
  1616.  
  1617. // -- Drafts --
  1618. // Accessing draft text
  1619. const accessDraftsButton = document.createElement('input');
  1620. Object.assign(accessDraftsButton, { className: 'major', value: 'Saved Drafts', type: 'button' });
  1621. replaceButton.parentNode.insertBefore(accessDraftsButton, replaceButton);
  1622. accessDraftsButton.parentNode.insertBefore(document.createTextNode(' '), replaceButton);
  1623. //accessDraftsButton.parentNode.insertBefore(newBr(), replaceButton);
  1624. //accessDraftsButton.parentNode.insertBefore(newBr(), replaceButton);
  1625.  
  1626. accessDraftsButton.addEventListener('click', () => {
  1627. loadDrafts();
  1628.  
  1629. const draftDialog = window.MSPFA.parseBBCode('Use the textbox below to copy out the data and save to a file somewhere else, or click the download button below.\nYou can also paste in data to replace the current drafts to ones stored there.');
  1630. const draftInputTextarea = document.createElement('textarea');
  1631. draftInputTextarea.placeholder = 'Paste your draft data here';
  1632. draftInputTextarea.style = 'width: 100%; box-sizing: border-box; resize: vertical;';
  1633.  
  1634. const downloadLink = document.createElement('a');
  1635. downloadLink.textContent = 'Download drafts';
  1636. downloadLink.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(drafts[adventureID], null, 4)));
  1637. downloadLink.setAttribute('download', `${adventureID}.json`);
  1638.  
  1639. draftInputTextarea.rows = 8;
  1640. draftDialog.appendChild(newBr());
  1641. draftDialog.appendChild(newBr());
  1642. draftDialog.appendChild(draftInputTextarea);
  1643. draftDialog.appendChild(newBr());
  1644. draftDialog.appendChild(newBr());
  1645. draftDialog.appendChild(downloadLink);
  1646. setTimeout(() => {
  1647. draftInputTextarea.focus();
  1648. draftInputTextarea.selectionStart = 0;
  1649. draftInputTextarea.selectionEnd = 0;
  1650. draftInputTextarea.scrollTop = 0;
  1651. }, 1);
  1652.  
  1653. draftInputTextarea.value = JSON.stringify(drafts[adventureID], null, 4);
  1654.  
  1655. window.MSPFA.dialog('Saved Drafts', draftDialog, ["Load Draft", "Cancel"], (output, form) => {
  1656. if (output === "Load Draft") {
  1657. if (draftInputTextarea.value === '') {
  1658. setTimeout(() => {
  1659. window.MSPFA.dialog('Saved Drafts', window.MSPFA.parseBBCode('Are you sure you want to delete this adventure\'s draft data?\nMake sure you have it saved somewhere!'), ["Delete", "Cancel"], (output, form) => {
  1660. if (output === "Delete") {
  1661. loadDrafts();
  1662. drafts[adventureID] = {};
  1663.  
  1664. if (settings.drafts && settings.drafts[adventureID]) {
  1665. delete settings.drafts[adventureID];
  1666. saveData(settings);
  1667. }
  1668.  
  1669. saveDrafts(drafts);
  1670. }
  1671. });
  1672. }, 1);
  1673. } else if (draftInputTextarea.value !== JSON.stringify(drafts[adventureID], null, 4)) {
  1674. setTimeout(() => {
  1675. window.MSPFA.dialog('Saved Drafts', window.MSPFA.parseBBCode('Are you sure you want to load this draft data?\nAll previous draft data for this adventure will be lost!'), ["Load", "Cancel"], (output, form) => {
  1676. if (output === "Load") {
  1677. let newData = {};
  1678. try { // Just in case the data given is invalid.
  1679. newData = JSON.parse(draftInputTextarea.value);
  1680. } catch (err) {
  1681. console.error(err);
  1682. setTimeout(() => {
  1683. window.MSPFA.dialog('Error', window.MSPFA.parseBBCode('The entered data is invalid.'), ["Okay"]);
  1684. }, 1);
  1685. return;
  1686. }
  1687.  
  1688. loadDrafts();
  1689. drafts[adventureID] = newData;
  1690. saveDrafts(drafts);
  1691. }
  1692. });
  1693. }, 1);
  1694. }
  1695. }
  1696. });
  1697. });
  1698.  
  1699. const addDraftPagesButton = document.createElement('input');
  1700. replaceButton.parentNode.insertBefore(addDraftPagesButton, replaceButton);
  1701. addDraftPagesButton.parentNode.insertBefore(newBr(), replaceButton);
  1702. addDraftPagesButton.parentNode.insertBefore(newBr(), replaceButton);
  1703.  
  1704. Object.assign(addDraftPagesButton, { className: 'major', value: 'Add Draft Pages', type: 'button' });
  1705. addDraftPagesButton.addEventListener('click', () => {
  1706. const newPageForm = document.querySelector('#newpage');
  1707. let currentPage = 1;
  1708. let pageAmount = 0;
  1709. if (newPageForm.nextSibling.nodeName !== '#text') {
  1710. currentPage = parseInt(newPageForm.nextSibling.id.replace('p', ''))+1;
  1711. }
  1712. for (let i = currentPage; drafts[adventureID][i] && pageAmount < 10; i++) {
  1713. pageAmount++;
  1714. }
  1715.  
  1716. if (pageAmount > 0) {
  1717. window.MSPFA.dialog("Drafts: Add New Pages", document.createTextNode(`This will add the pages with draft data from pages ${currentPage}-${currentPage+pageAmount-1} (you are only allowed 10 at once)`), ["Okay", "Cancel"], (output, form) => {
  1718. if (output === "Okay") {
  1719. for (let i = currentPage; drafts[adventureID][i] && i < currentPage+10; i++) {
  1720. newPageForm.querySelector('input[name=cmd]').value = drafts[adventureID][i].command;
  1721. newPageForm.querySelector('textarea[name=body]').value = drafts[adventureID][i].pageContent;
  1722. if (drafts[adventureID][i].next) newPageForm.querySelector('input[name=next]').value = drafts[adventureID][i].next;
  1723.  
  1724. newPageForm.querySelector('input[name=save]').click();
  1725. }
  1726. }
  1727. });
  1728. }
  1729. });
  1730.  
  1731. // Draft stuff
  1732. const showDraftDialog = (pageNum) => {
  1733. loadDrafts();
  1734.  
  1735. const msg = document.createElement('span');
  1736. msg.appendChild(document.createTextNode('Command:'));
  1737. msg.appendChild(document.createElement('br'));
  1738.  
  1739. const commandInput = document.createElement('input');
  1740. Object.assign(commandInput, { style: 'width: 100%; box-sizing: border-box;', readOnly: true, });
  1741.  
  1742. msg.appendChild(commandInput);
  1743. msg.appendChild(document.createElement('br'));
  1744. msg.appendChild(document.createElement('br'));
  1745.  
  1746. msg.appendChild(document.createTextNode('Body:'));
  1747.  
  1748. const bodyInput = document.createElement('textarea');
  1749. Object.assign(bodyInput, { style: 'width: 100%; box-sizing: border-box; resize: vertical;', readOnly: true, rows: 8 });
  1750.  
  1751. msg.appendChild(bodyInput);
  1752.  
  1753. const pageElement = document.querySelector(`#p${pageNum}`);
  1754.  
  1755. let shownMessage = msg;
  1756. let optionButtons = [];
  1757.  
  1758. const commandElement = pageElement.querySelector('input[name="cmd"]');
  1759. const pageContentElement = pageElement.querySelector('textarea[name="body"]');
  1760.  
  1761. if (typeof drafts[adventureID][pageNum] === "undefined") {
  1762. shownMessage = document.createTextNode('There is no draft saved for this page.');
  1763. optionButtons = ["Save New", "Close"];
  1764. } else {
  1765. commandInput.value = drafts[adventureID][pageNum].command;
  1766. bodyInput.textContent = drafts[adventureID][pageNum].pageContent;
  1767. optionButtons = ["Save New", "Load", "Delete", "Close"];
  1768. }
  1769.  
  1770. window.MSPFA.dialog(`Page ${pageNum} Draft`, shownMessage, optionButtons, (output, form) => {
  1771. if (output === "Save New") {
  1772. if (typeof drafts[adventureID][pageNum] === "undefined") {
  1773. loadDrafts();
  1774. drafts[adventureID][pageNum] = {
  1775. command: commandElement.value,
  1776. pageContent: pageContentElement.value
  1777. }
  1778. saveDrafts(drafts);
  1779. } else {
  1780. setTimeout(() => {
  1781. window.MSPFA.dialog('Overwrite current draft?', document.createTextNode('Doing this will overwrite your current draft with what is currently written in the page box. Are you sure?'), ["Yes", "No"], (output, form) => {
  1782. if (output === "Yes") {
  1783. loadDrafts();
  1784. drafts[adventureID][pageNum] = {
  1785. command: commandElement.value,
  1786. pageContent: pageContentElement.value
  1787. }
  1788. saveDrafts(drafts);
  1789. }
  1790. });
  1791. }, 1);
  1792. }
  1793. } else if (output === "Load") {
  1794. if (pageContentElement.value === '' && (commandElement.value === '' || commandElement.value === document.querySelector('#defaultcmd').value)) {
  1795. commandElement.value = drafts[adventureID][pageNum].command;
  1796. pageContentElement.value = drafts[adventureID][pageNum].pageContent;
  1797. pageElement.querySelector('input[value="Save"]').disabled = false;
  1798. } else {
  1799. setTimeout(() => {
  1800. window.MSPFA.dialog('Overwrite current page?', document.createTextNode('Doing this will overwrite the page\'s content with what is currently written in the draft. Are you sure?'), ["Yes", "No"], (output, form) => {
  1801. if (output === "Yes") {
  1802. commandElement.value = drafts[adventureID][pageNum].command;
  1803. pageContentElement.value = drafts[adventureID][pageNum].pageContent;
  1804. pageElement.querySelector('input[value="Save"]').disabled = false;
  1805. }
  1806. });
  1807. }, 1);
  1808. }
  1809. } else if (output === "Delete") {
  1810. setTimeout(() => {
  1811. window.MSPFA.dialog('Delete this draft?', document.createTextNode('This action is irreversable! Are you sure?'), ["Yes", "No"], (output, form) => {
  1812. if (output === "Yes") {
  1813. loadDrafts();
  1814. delete drafts[adventureID][pageNum];
  1815.  
  1816. if (settings.drafts && settings.drafts[adventureID] && settings.drafts[adventureID][pageNum]) {
  1817. delete settings.drafts[adventureID][pageNum];
  1818. saveData(settings);
  1819. }
  1820.  
  1821. saveDrafts(drafts);
  1822. }
  1823. });
  1824. }, 1);
  1825. }
  1826. });
  1827. }
  1828.  
  1829. const createDraftButton = (form) => {
  1830. const draftButton = document.createElement('input');
  1831. Object.assign(draftButton, { className: 'major draft', type: 'button', value: 'Draft' });
  1832. draftButton.addEventListener('click', () => {
  1833. showDraftDialog(form.id.replace('p', ''));
  1834. });
  1835. return draftButton;
  1836. }
  1837.  
  1838. pageLoad(() => {
  1839. let allPages = document.querySelectorAll('#storypages form:not(#newpage)');
  1840. if (allPages.length !== 0) {
  1841. allPages.forEach(form => {
  1842. const prevButton = form.querySelector('input[name="preview"]');
  1843. prevButton.parentNode.insertBefore(createDraftButton(form), prevButton);
  1844. prevButton.parentNode.insertBefore(document.createTextNode(' '), prevButton);
  1845.  
  1846. // Preview
  1847. const previewButton = form.querySelector('input[value=Preview]');
  1848. const previewLink = addLink(previewButton, getPreviewLink(form), '_blank');
  1849. previewButton.addEventListener('mousedown', () => {
  1850. previewLink.href = getPreviewLink(form);
  1851. });
  1852.  
  1853. // "Enable keyboard shortcuts" label
  1854. const shortcutCheck = form.querySelector('input[type="checkbox"]');
  1855. shortcutCheck.previousSibling.textContent = '';
  1856. shortcutCheck.id = `key-${form.id}`;
  1857. shortcutCheck.parentNode.insertBefore(createLabel('Enable keyboard shortcuts: ', shortcutCheck.id), shortcutCheck);
  1858. });
  1859. document.querySelector('input[value="Add"]').addEventListener('click', () => {
  1860. allPages = document.querySelectorAll('#storypages form:not(#newpage)');
  1861. const form = document.querySelector(`#p${allPages.length}`);
  1862. const prevButton = form.querySelector('input[name="preview"]');
  1863. prevButton.parentNode.insertBefore(createDraftButton(form), prevButton);
  1864. prevButton.parentNode.insertBefore(document.createTextNode(' '), prevButton);
  1865.  
  1866. // Preview link
  1867. const previewButton = form.querySelector('input[value=Preview]');
  1868. const previewLink = addLink(previewButton, getPreviewLink(form), '_blank');
  1869. previewButton.addEventListener('mousedown', () => {
  1870. previewLink.href = getPreviewLink(form);
  1871. });
  1872.  
  1873. // "Enable keyboard shortcuts" label
  1874. const shortcutCheck = form.querySelector('input[type="checkbox"]');
  1875. shortcutCheck.previousSibling.textContent = '';
  1876. shortcutCheck.id = `key-${form.id}`;
  1877. shortcutCheck.parentNode.insertBefore(createLabel('Enable keyboard shortcuts: ', shortcutCheck.id), shortcutCheck);
  1878. });
  1879. const newForm = document.querySelector('#newpage');
  1880. {
  1881. // "Enable keyboard shortcuts" label
  1882. const shortcutCheck = newForm.querySelector('input[type="checkbox"]');
  1883. shortcutCheck.previousSibling.textContent = '';
  1884. shortcutCheck.id = `key-${newForm.id}`;
  1885. shortcutCheck.parentNode.insertBefore(createLabel('Enable keyboard shortcuts: ', shortcutCheck.id), shortcutCheck);
  1886. }
  1887. const newPreviewButton = newForm.querySelector('input[value=Preview]');
  1888. const newPreviewLink = addLink(newPreviewButton, getPreviewLink(newForm), '_blank');
  1889. newPreviewButton.addEventListener('mousedown', () => {
  1890. newPreviewLink.href = getPreviewLink(newForm);
  1891. });
  1892. return true;
  1893. }
  1894. });
  1895.  
  1896. if (params.click) {
  1897. if (params.click === 's') {
  1898. spoilerButton.click();
  1899. } else if (params.click === 'd') {
  1900. accessDraftsButton.click();
  1901. }
  1902. }
  1903.  
  1904. // Don't scroll after pressing a BBToolbar button (awesome)
  1905. let lastScroll = window.scrollY;
  1906. pageLoad(() => {
  1907. if (document.querySelectorAll('#storypages textarea').length > 1) {
  1908. document.querySelectorAll('#storypages textarea').forEach(textarea => {
  1909. textarea.addEventListener('focus', () => {
  1910. window.scrollTo(window.scrollX, lastScroll);
  1911. });
  1912. });
  1913.  
  1914. document.addEventListener('scroll', evt => {
  1915. lastScroll = window.scrollY;
  1916. });
  1917. return true;
  1918. }
  1919. });
  1920.  
  1921. // Focus on the text input when clicking on the Color or Background Color BBToolbar buttons
  1922. const colourButtons = [document.querySelector('#bbtoolbar input[data-tag=color]'), document.querySelector('#bbtoolbar input[data-tag=background]')];
  1923.  
  1924. let prevColour;
  1925.  
  1926. colourButtons[0].addEventListener('click', () => {
  1927. const inputs = document.querySelectorAll('#dialog input');
  1928. document.querySelector('button[data-value="Okay"]').addEventListener('click', () => {
  1929. prevColour = inputs[0].value;
  1930. });
  1931. if (prevColour) {
  1932. inputs[0].value = prevColour;
  1933. inputs[1].value = prevColour;
  1934. }
  1935. });
  1936.  
  1937. colourButtons.forEach(button => {
  1938. button.addEventListener('click', () => {
  1939. document.querySelector('#dialog input[type=text]').select();
  1940. });
  1941. });
  1942. }
  1943. else if (location.pathname === "/my/profile/") {
  1944. // Nothing
  1945. }
  1946. else if (location.pathname === "/user/") {
  1947. // Button links
  1948. pageLoad(() => {
  1949. const msgButton = document.querySelector('#sendmsg');
  1950. if (msgButton) {
  1951. addLink(msgButton, `/my/messages/new/?u=${params.u}`);
  1952. addLink(document.querySelector('#favstories'), `/favs/?u=${params.u}`);
  1953. return true;
  1954. }
  1955. });
  1956.  
  1957. // Add extra user stats
  1958. pageLoad(() => {
  1959. if (window.MSPFA) {
  1960. const stats = document.querySelector('#userinfo table');
  1961.  
  1962. const joinTr = stats.insertRow(1);
  1963. const joinTextTd = joinTr.insertCell(0);
  1964. joinTextTd.appendChild(document.createTextNode("Account created:"));
  1965. const joinDate = joinTr.insertCell(1);
  1966. const joinTime = document.createElement('b');
  1967. joinTime.textContent = "Loading...";
  1968. joinDate.appendChild(joinTime);
  1969.  
  1970. const advCountTr = stats.insertRow(2);
  1971. const advTextTd = advCountTr.insertCell(0);
  1972. advTextTd.appendChild(document.createTextNode("Adventures created:"));
  1973. const advCount = advCountTr.insertCell(1);
  1974. const advCountText = document.createElement('b');
  1975. advCountText.textContent = "Loading...";
  1976. advCount.appendChild(advCountText);
  1977.  
  1978. // Show user creation date
  1979. window.MSPFA.request(0, {
  1980. do: "user",
  1981. u: params.u
  1982. }, user => {
  1983. if (typeof user !== "undefined") {
  1984. joinTime.textContent = new Date(user.d).toString().split(' ').splice(1, 4).join(' ');
  1985. }
  1986.  
  1987. // Show created adventures
  1988. window.MSPFA.request(0, {
  1989. do: "editor",
  1990. u: params.u
  1991. }, s => {
  1992. if (typeof s !== "undefined") {
  1993. advCountText.textContent = s.length;
  1994. }
  1995.  
  1996. // Show favourites
  1997. if (document.querySelector('#favstories').style.display !== 'none') {
  1998. const favCountTr = stats.insertRow(3);
  1999. const favTextTd = favCountTr.insertCell(0);
  2000. favTextTd.appendChild(document.createTextNode("Adventures favorited:"));
  2001. const favCount = favCountTr.insertCell(1);
  2002. const favCountText = document.createElement('b');
  2003. favCountText.textContent = "Loading...";
  2004. window.MSPFA.request(0, {
  2005. do: "favs",
  2006. u: params.u
  2007. }, s => {
  2008. if (typeof s !== "undefined") {
  2009. favCountText.textContent = s.length;
  2010. }
  2011. });
  2012. favCount.appendChild(favCountText);
  2013. }
  2014. });
  2015. });
  2016.  
  2017. return true;
  2018. }
  2019. });
  2020. }
  2021. else if (location.pathname === "/favs/" && location.search) {
  2022. const toggleButton = document.createElement('input');
  2023. Object.assign(toggleButton, { className: "major", type: "button", value: "Hide Muted Adventures", title: 'Cycle through muted/unmuted adventures' });
  2024. const buttonRow = document.querySelector('table.container.alt').insertRow(2);
  2025. const actionSpan = document.createElement('span');
  2026.  
  2027. let stories = [];
  2028. // Button links
  2029. pageLoad(() => {
  2030. stories = document.querySelectorAll('#stories tr');
  2031. let favCount = 0;
  2032.  
  2033. if (stories.length > 0) {
  2034. stories.forEach(story => {
  2035. favCount++;
  2036. const id = story.querySelector('a').href.replace('https://mspfa.com/', '');
  2037. pageLoad(() => {
  2038. if (window.MSPFA.me.i) {
  2039. addLink(story.querySelector('.edit.major'), `/my/stories/info/${id}`);
  2040. return true;
  2041. }
  2042. if (pageLoaded) return true;
  2043. });
  2044. addLink(story.querySelector('.rss.major'), `/rss/${id}`);
  2045. });
  2046.  
  2047. // Fav count
  2048. const username = document.querySelector('#username');
  2049. username.parentNode.appendChild(newBr());
  2050. username.parentNode.appendChild(newBr());
  2051. username.parentNode.appendChild(document.createTextNode(`Favorited adventures: ${favCount}`));
  2052.  
  2053. return true;
  2054. }
  2055. if (pageLoaded) return true;
  2056. });
  2057.  
  2058. pageLoad(() => {
  2059. if (window.MSPFA && window.MSPFA.me) {
  2060. if (window.MSPFA.me.i === params.u) {
  2061. const cell = buttonRow.insertCell(0);
  2062. cell.appendChild(toggleButton);
  2063. cell.appendChild(newBr());
  2064. cell.appendChild(actionSpan);
  2065. return true;
  2066. }
  2067. }
  2068. if (pageLoaded) return true;
  2069. });
  2070.  
  2071. let type = 0;
  2072.  
  2073. toggleButton.addEventListener('click', () => {
  2074. type++;
  2075. if (type > 2) type = 0;
  2076.  
  2077. stories.forEach(story => {
  2078. const unmuted = story.querySelector('.notify').className.includes(' lit');
  2079. story.style.display = '';
  2080. if (type === 2 && unmuted || type === 1 && !unmuted) {
  2081. story.style.display = 'none';
  2082. }
  2083. });
  2084.  
  2085. if (type === 0) {
  2086. // show all
  2087. actionSpan.textContent = '';
  2088. }
  2089. else if (type === 1) {
  2090. // hide muted
  2091. toggleButton.value = 'Hide Unmuted Adventures';
  2092. }
  2093. else {
  2094. // only muted
  2095. toggleButton.value = 'Show All Adventures';
  2096. }
  2097. });
  2098. }
  2099. else if (location.pathname === "/search/" && location.search) {
  2100. // Character and word statistics
  2101. const statTable = document.createElement('table');
  2102. const statTbody = document.createElement('tbody');
  2103. const statTr = statTbody.insertRow(0);
  2104. const charCount = statTr.insertCell(0);
  2105. const wordCount = statTr.insertCell(0);
  2106. const statParentTr = document.querySelector('#pages').parentNode.parentNode.insertRow(2);
  2107. const statParentTd = statParentTr.insertCell(0);
  2108.  
  2109. const statHeaderTr = statTbody.insertRow(0);
  2110. const statHeader = document.createElement('th');
  2111. statHeader.colSpan = '2';
  2112.  
  2113. statHeaderTr.appendChild(statHeader);
  2114. statHeader.textContent = 'Statistics may not be entirely accurate.';
  2115.  
  2116. statTable.style.width = "100%";
  2117.  
  2118. charCount.textContent = "Character count: loading...";
  2119. wordCount.textContent = "Word count: loading...";
  2120.  
  2121. statTable.appendChild(statTbody);
  2122. statParentTd.appendChild(statTable);
  2123.  
  2124. pageLoad(() => {
  2125. if (document.querySelector('#pages br')) {
  2126. const bbc = window.MSPFA.BBC.slice();
  2127. bbc.splice(0, 3);
  2128.  
  2129. window.MSPFA.request(0, {
  2130. do: "story",
  2131. s: params.s
  2132. }, story => {
  2133. if (typeof story !== "undefined") {
  2134. const pageContent = [];
  2135. story.p.forEach(p => {
  2136. pageContent.push(p.c);
  2137. pageContent.push(p.b);
  2138. });
  2139.  
  2140. const storyText = pageContent.join(' ')
  2141. .replace(/\n/g, ' ')
  2142. .replace(bbc[0][0], '$1')
  2143. .replace(bbc[1][0], '$1')
  2144. .replace(bbc[2][0], '$1')
  2145. .replace(bbc[3][0], '$1')
  2146. .replace(bbc[4][0], '$2')
  2147. .replace(bbc[5][0], '$3')
  2148. .replace(bbc[6][0], '$3')
  2149. .replace(bbc[7][0], '$3')
  2150. .replace(bbc[8][0], '$3')
  2151. .replace(bbc[9][0], '$3')
  2152. .replace(bbc[10][0], '$2')
  2153. .replace(bbc[11][0], '$1')
  2154. .replace(bbc[12][0], '$3')
  2155. .replace(bbc[13][0], '$3')
  2156. .replace(bbc[14][0], '')
  2157. .replace(bbc[16][0], '$1')
  2158. .replace(bbc[17][0], '$2 $4 $5')
  2159. .replace(bbc[18][0], '$2 $4 $5')
  2160. .replace(bbc[19][0], '')
  2161. .replace(bbc[20][0], '')
  2162. .replace(/<(.*?)>/g, '');
  2163.  
  2164. wordCount.textContent = `Word count: ${storyText.split(/ +/g).length}`;
  2165. charCount.textContent = `Character count: ${storyText.replace(/ +/g, '').length}`;
  2166. }
  2167. });
  2168. return true;
  2169. }
  2170. });
  2171. }
  2172. else if (location.pathname === "/stories/" && location.search) {
  2173.  
  2174. // Add a button to hide adventures with a tag
  2175. const tagHide = document.createElement('input');
  2176. Object.assign(tagHide, { id: 'taghide', value: '-', className: 'major', type: 'button', style: 'padding: 0;', title: 'Hide Tag' });
  2177.  
  2178. const tagAdd = document.querySelector('#tagadd');
  2179. tagAdd.parentNode.insertBefore(tagHide, tagAdd.nextSibling);
  2180. tagAdd.parentNode.insertBefore(document.createTextNode(' '), tagAdd.nextSibling);
  2181.  
  2182. const tagselect = document.querySelector('#tagselect');
  2183. const taglist = document.querySelector('textarea[name=tags]');
  2184. tagHide.addEventListener('click', () => {
  2185. let tags = [];
  2186. if(taglist.value) {
  2187. tags = taglist.value.split(",");
  2188. }
  2189. if(tagselect.value && tags.indexOf('-'+tagselect.value) == -1) {
  2190. tags.push('-'+tagselect.value);
  2191. }
  2192. taglist.value = tags.join(",");
  2193. tagselect.options[0].selected = true;
  2194. });
  2195.  
  2196. // Add titles on hover to the [?] and [+] buttons
  2197. document.querySelector('#taghelp').title = 'Tip';
  2198. tagAdd.title = 'Add Tag';
  2199.  
  2200. // Click text to check/uncheck boxes
  2201. ['Ongoing', 'Complete', 'Inactive'].forEach(t => {
  2202. const check = document.querySelector(`input[name="${t.toLowerCase()}"]`);
  2203. check.id = `check_${t.toLowerCase()}`;
  2204. const label = createLabel(' ' + t + ' ', check.id);
  2205. check.nextSibling.textContent = '';
  2206. check.parentNode.insertBefore(label, check.nextSibling);
  2207. });
  2208.  
  2209. const adventureList = document.querySelector('#doit');
  2210. const resultAmount = document.createElement('span');
  2211. adventureList.parentNode.appendChild(resultAmount);
  2212.  
  2213. pageLoad(() => {
  2214. if (window.MSPFA) {
  2215. window.MSPFA.request(0, {
  2216. do: "stories",
  2217. n: params.n,
  2218. t: params.t,
  2219. h: params.h,
  2220. o: params.o,
  2221. p: params.p,
  2222. m: 20000
  2223. }, (s) => {
  2224. resultAmount.textContent = `Number of results: ${s.length}`;
  2225. return true;
  2226. });
  2227. return true;
  2228. }
  2229. },1);
  2230.  
  2231. pageLoad(() => {
  2232. const stories = document.querySelector('#stories');
  2233. if (stories.childNodes.length > 0) {
  2234. if (params.load && stories.childNodes.length === 1) {
  2235. stories.querySelector('a').click();
  2236. }
  2237.  
  2238. stories.querySelectorAll('tr').forEach(story => {
  2239. const storyID = story.querySelector('a.major').href.split('&')[0].replace(/\D/g, '');
  2240. addLink(story.querySelector('.rss'), `/rss/?s=${storyID}`);
  2241.  
  2242. pageLoad(() => {
  2243. if (window.MSPFA.me.i) {
  2244. addLink(story.querySelector('.edit.major'), `/my/stories/info/?s=${storyID}`);
  2245. return true;
  2246. }
  2247. if (pageLoaded) return true;
  2248. });
  2249. });
  2250. return true;
  2251. }
  2252. if (pageLoaded) return true;
  2253. });
  2254. }
  2255. })();