MSPFA extras

Adds custom features to MSPFA.

当前为 2020-07-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MSPFA extras
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3.2
  5. // @description Adds custom features to MSPFA.
  6. // @author seymour schlong
  7. // @match https://mspfa.com/
  8. // @match https://mspfa.com/*/
  9. // @match https://mspfa.com/*/?*
  10. // @match https://mspfa.com/?s=*
  11. // @match https://mspfa.com/my/*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. /**
  20. * https://github.com/GrantGryczan/MSPFA/projects/1?fullscreen=true
  21. * Github to-do completion list
  22. *
  23. * https://github.com/GrantGryczan/MSPFA/issues/26 - Dropdown menu
  24. * https://github.com/GrantGryczan/MSPFA/issues/18 - MSPFA themes
  25. * https://github.com/GrantGryczan/MSPFA/issues/32 - Adventure creation dates
  26. * https://github.com/GrantGryczan/MSPFA/issues/32 - User creation dates
  27. * https://github.com/GrantGryczan/MSPFA/issues/40 - Turn certain buttons into links
  28. * https://github.com/GrantGryczan/MSPFA/issues/41 - Word and character count
  29. *
  30. * Extension to-do... maybe...
  31. * https://github.com/GrantGryczan/MSPFA/issues/57 - Default spoiler values (might be very difficult unless i can detect when any spoiler button on the bbtoolbar is clicked. EACH ONE)
  32. * https://github.com/GrantGryczan/MSPFA/issues/62 - Buttonless spoilers (may also be extremely tough, as you have to add a button to each toolbar (or add an option in the regular spoiler))
  33. */
  34.  
  35. // A general function that allows for waiting until a certain element appears on the page.
  36. const pageLoad = (fn) => {
  37. let interval = setInterval(() => {
  38. if (fn()) clearInterval(interval);
  39. }, 500);
  40. };
  41.  
  42. // Saves the options data for the script.
  43. const saveData = (data) => {
  44. localStorage.mspfaextra = JSON.stringify(data);
  45. //console.log("Saved cookies under mspfaextra.");
  46. };
  47.  
  48. // Encases an element within a link
  49. const addLink = (elm, url) => {
  50. let link = document.createElement('a');
  51. link.href = url;
  52. elm.parentNode.insertBefore(link, elm);
  53. link.appendChild(elm);
  54. };
  55.  
  56. let settings = {};
  57.  
  58. if (localStorage.mspfaextra) {
  59. settings = JSON.parse(localStorage.mspfaextra);
  60. } else {
  61. settings.autospoiler = false;
  62. settings.style = 0;
  63. settings.styleURL = "";
  64. settings.night = false;
  65. settings.auto502 = true;
  66. saveData(settings);
  67. }
  68. // If any settings are undefined, re-set to their default state. (For older users when new things get stored)
  69. if (typeof settings.autospoiler === "undefined") {
  70. settings.autospoiler = false;
  71. }
  72. if (typeof settings.style === "undefined") {
  73. settings.style = 0;
  74. }
  75. if (typeof settings.styleURL === "undefined") {
  76. settings.styleURL = "";
  77. }
  78. if (typeof settings.night === "undefined") {
  79. settings.night = false;
  80. }
  81. if (typeof settings.auto502 === "undefined") {
  82. settings.auto502 = true;
  83. }
  84. if (typeof settings.textFix === "undefined") {
  85. settings.textFix = false;
  86. }
  87. if (typeof settings.pixelFix === "undefined") {
  88. settings.pixelFix = false;
  89. }
  90.  
  91. //console.log(settings);
  92.  
  93. let styleOptions = ["Standard", "Low Contrast", "Light", "Dark", "Felt", "Trickster", "Custom"];
  94. let styleUrls = ['', '/css/theme1.css', '/css/theme2.css', '/css/?s=36237', '/css/theme4.css', '/css/theme5.css'];
  95.  
  96. let myLink = document.querySelector('nav a[href="/my/"]');
  97. let dropDiv = document.createElement('div');
  98. dropDiv.className = 'dropdown';
  99. Object.assign(dropDiv.style, {
  100. position: 'relative',
  101. display: 'inline-block',
  102. backgroundColor: 'inherit'
  103. });
  104.  
  105. let dropContent = document.createElement('div');
  106. dropContent.className = 'dropdown-content';
  107. Object.assign(dropContent.style, {
  108. display: 'none',
  109. backgroundColor: 'inherit',
  110. position: 'absolute',
  111. textAlign: 'left',
  112. minWidth: '100px',
  113. marginLeft: '-5px',
  114. padding: '2px',
  115. zIndex: '1',
  116. borderRadius: '0 0 5px 5px'
  117. });
  118.  
  119. dropDiv.addEventListener('mouseenter', evt => {
  120. dropContent.style.display = 'block';
  121. dropContent.style.color = getComputedStyle(myLink).color;
  122. });
  123. dropDiv.addEventListener('mouseleave', evt => {
  124. dropContent.style.display = 'none';
  125. });
  126.  
  127. if (myLink) {
  128. myLink.parentNode.insertBefore(dropDiv, myLink);
  129. dropDiv.appendChild(myLink);
  130. dropDiv.appendChild(dropContent);
  131.  
  132. let dLinks = [];
  133. dLinks[0] = [ 'Messages', 'My Adventures', 'Settings' ];
  134. dLinks[1] = [ '/my/messages/', '/my/stories/', '/my/settings/' ];
  135.  
  136. for (let i = 0; i < dLinks[0].length; i++) {
  137. let newLink = document.createElement('a');
  138. newLink.textContent = dLinks[0][i];
  139. newLink.href = dLinks[1][i];
  140. dropContent.appendChild(newLink);
  141. }
  142. }
  143.  
  144. window.addEventListener("load", () => {
  145. // Reload the page if 502 CloudFlare error page appears
  146. if (settings.auto502 && document.querySelector('.cf-error-overview')) {
  147. window.location.reload();
  148. }
  149.  
  150. // Append "My Profile" to the dropdown list if you're signed in
  151. pageLoad(() => {
  152. if (window.MSPFA) {
  153. if (window.MSPFA.me.n) {
  154. let newLink = document.createElement('a');
  155. newLink.textContent = "My Profile";
  156. newLink.href = `/user/?u=${window.MSPFA.me.i}`;
  157. dropContent.appendChild(newLink);
  158. return true;
  159. }
  160. return true;
  161. }
  162. });
  163. });
  164.  
  165. let pixelFixText = 'img, .mspfalogo, .arrow, #flashytitle, .heart, .fav, .edit, .rss { image-rendering: pixelated !important; }'
  166. let dropStyleText = `#notification { z-index: 2; } .dropdown-content a { color: inherit; padding: 2px; text-decoration: underline; display: block;}`;
  167. let dropStyle = document.createElement('style');
  168. dropStyle.id = 'dropdown-style';
  169. dropStyle.textContent = dropStyleText + (settings.pixelFix ? ' '+pixelFixText : '');
  170. //dropdownStyle.textContent = '#notification { z-index: 2;}.dropdown:hover .dropdown-content { display: block;}.dropdown { position: relative; display: inline-block; background-color: inherit;}.dropdown-content { display: none; position: absolute; text-align: left; background-color: inherit; min-width: 100px; margin-left: -5px; padding: 2px; z-index: 1; border-radius: 0 0 5px 5px;}.dropdown-content a { color: #fffa36; padding: 2px 2px; text-decoration: underline; display: block;}';
  171.  
  172. let theme = document.createElement('link');
  173. Object.assign(theme, { id: 'theme', type: 'text/css', rel: 'stylesheet' });
  174.  
  175. if (!document.querySelector('#theme') && !/^\/css\/|^\/js\//.test(location.pathname)) {
  176. document.querySelector('head').appendChild(theme);
  177. }
  178. if (!document.querySelector('#dropdown-style')) {
  179. document.querySelector('head').appendChild(dropStyle);
  180. }
  181.  
  182. const updateTheme = (src) => {
  183. theme.href = src;
  184. }
  185.  
  186. if (settings.night) {
  187. updateTheme('/css/?s=36237');
  188. } else {
  189. updateTheme(settings.style == styleOptions.length - 1 ? settings.styleURL : styleUrls[settings.style]);
  190. }
  191.  
  192. pageLoad(() => {
  193. if (window.MSPFA) {
  194. if (window.MSPFA.story && window.MSPFA.story.y && window.MSPFA.story.y.length > 0) {
  195. updateTheme('');
  196. }
  197. return true;
  198. }
  199. });
  200.  
  201. pageLoad(() => {
  202. if (document.querySelector('footer .mspfalogo')) {
  203. document.querySelector('footer .mspfalogo').addEventListener('dblclick', evt => {
  204. if (evt.button === 0) {
  205. settings.night = !settings.night;
  206. saveData(settings);
  207.  
  208. if (settings.night) {
  209. updateTheme('/css/?s=36237');
  210. } else {
  211. updateTheme(settings.style == styleOptions.length - 1 ? settings.styleURL : styleUrls[settings.style]);
  212. }
  213.  
  214. dropStyle.textContent = dropStyleText + '';
  215. dropStyle.textContent = dropStyleText + '*{transition:1s}';
  216. setTimeout(() => {
  217. dropStyle.textContent = dropStyleText;
  218. }, 1000);
  219.  
  220. console.log(`Night mode turned ${settings.night ? 'on' : 'off'}.`);
  221. }
  222. });
  223. return true;
  224. }
  225. });
  226.  
  227. if (location.pathname === "/" || location.pathname === "/preview/") {
  228. if (settings.autospoiler) {
  229. window.MSPFA.slide.push((p) => {
  230. document.querySelectorAll('#slide .spoiler:not(.open) > div:first-child > input').forEach(sb => sb.click());
  231. });
  232. }
  233. if (location.search) {
  234. pageLoad(() => {
  235. if (document.querySelector('#infobox tr td:nth-child(2)')) {
  236. document.querySelector('#infobox tr td:nth-child(2)').appendChild(document.createTextNode('Creation date: ' + new Date(window.MSPFA.story.d).toString().split(' ').splice(1, 3).join(' ')));
  237. return true;
  238. }
  239. });
  240. if (settings.textFix) {
  241. pageLoad(() => {
  242. if (window.MSPFA.story && window.MSPFA.story.p) {
  243. // russian/bulgarian is not possible =(
  244. let currentPage = parseInt(/^\?s(?:.*?)&p=([\d]*)$/.exec(location.search)[1]);
  245. let library = [
  246. ["&acirc;��", "'"],
  247. ["&Atilde;�", "Ñ"],
  248. ["&Atilde;&plusmn;", "ñ"],
  249. ["&Atilde;&sup3;", "ó"],
  250. ["&Atilde;&iexcl;", "á"],
  251. ["&Atilde;&shy;", "í"],
  252. ["&Atilde;&ordm;", "ú"],
  253. ["&Atilde;&copy;", "é"],
  254. ["&Acirc;&iexcl;", "¡"],
  255. ["&Acirc;&iquest;", "¿"],
  256. ["N&Acirc;&ordm;", "#"]
  257. ];
  258. // https://mspfa.com/?s=5280&p=51 -- unknown error
  259.  
  260. const replaceTerms = (p) => {
  261. library.forEach(term => {
  262. if (window.MSPFA.story.p[p]) {
  263. window.MSPFA.story.p[p].c = window.MSPFA.story.p[p].c.replace(new RegExp(term[0], 'g'), term[1]);
  264. window.MSPFA.story.p[p].b = window.MSPFA.story.p[p].b.replace(new RegExp(term[0], 'g'), term[1]);
  265. }
  266. });
  267. };
  268.  
  269. replaceTerms(currentPage-1);
  270.  
  271. window.MSPFA.slide.push(p => {
  272. replaceTerms(p);
  273. replaceTerms(p-2);
  274. });
  275. window.MSPFA.page(currentPage);
  276. return true;
  277. }
  278. });
  279. }
  280. pageLoad(() => {
  281. let infoButton = document.querySelector('.edit.major');
  282. if (infoButton) {
  283. pageLoad(() => {
  284. if (window.MSPFA.me.i) {
  285. addLink(infoButton, `/my/stories/info/${location.search.split('&p=')[0]}`);
  286. return;
  287. }
  288. });
  289. addLink(document.querySelector('.rss.major'), `/rss/${location.search.split('&p=')[0]}`);
  290. return true;
  291. }
  292. });
  293. /*
  294. pageLoad(() => {
  295. let infoButton = document.querySelector('.edit.major');
  296. if (infoButton) {
  297. let editPages = document.createElement('button');
  298. Object.assign(editPages, { className: 'editpages major edit', title: 'Edit pages'});
  299. //infoButton.parentNode.insertBefore(editPages, infoButton);
  300. return true;
  301. }
  302. });/**/
  303. }
  304. }
  305. else if (location.pathname === "/my/settings/") { // Custom settings
  306. let saveBtn = document.querySelector('#savesettings');
  307.  
  308. let table = document.querySelector("#editsettings tbody");
  309. let saveTr = table.querySelectorAll("tr");
  310. saveTr = saveTr[saveTr.length - 1];
  311.  
  312. let headerTr = document.createElement('tr');
  313. let header = document.createElement('th');
  314. header.textContent = "Extra Settings";
  315. headerTr.appendChild(header);
  316.  
  317. let moreTr = document.createElement('tr');
  318. let more = document.createElement('td');
  319. more.textContent = "* 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.";
  320. moreTr.appendChild(more);
  321.  
  322. let settingsTr = document.createElement('tr');
  323. let localMsg = document.createElement('span');
  324. let settingsTd = document.createElement('td');
  325. localMsg.innerHTML = "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!";
  326. let plusTable = document.createElement('table');
  327. let plusTbody = document.createElement('tbody');
  328. plusTable.appendChild(plusTbody);
  329. settingsTd.appendChild(localMsg);
  330. settingsTd.appendChild(document.createElement('br'));
  331. settingsTd.appendChild(document.createElement('br'));
  332. settingsTd.appendChild(plusTable);
  333. settingsTr.appendChild(settingsTd);
  334.  
  335. let spoilerTr = plusTbody.insertRow(plusTbody.childNodes.length);
  336. let spoilerTextTd = spoilerTr.insertCell(0);
  337. let spoilerInputTd = spoilerTr.insertCell(1);
  338. let spoilerInput = document.createElement('input');
  339. spoilerInputTd.appendChild(spoilerInput);
  340.  
  341. let errorTr = plusTbody.insertRow(plusTbody.childNodes.length);
  342. let errorTextTd = errorTr.insertCell(0);
  343. let errorInputTd = errorTr.insertCell(1);
  344. let errorInput = document.createElement('input');
  345. errorInputTd.appendChild(errorInput);
  346.  
  347. let pixelFixTr = plusTbody.insertRow(plusTbody.childNodes.length);
  348. let pixelFixTextTd = pixelFixTr.insertCell(0);
  349. let pixelFixInputTd = pixelFixTr.insertCell(1);
  350. let pixelFixInput = document.createElement('input');
  351. pixelFixInputTd.appendChild(pixelFixInput);
  352.  
  353. let textFixTr = plusTbody.insertRow(plusTbody.childNodes.length);
  354. let textFixTextTd = textFixTr.insertCell(0);
  355. let textFixInputTd = textFixTr.insertCell(1);
  356. let textFixInput = document.createElement('input');
  357. textFixInputTd.appendChild(textFixInput);
  358.  
  359. let cssTr = plusTbody.insertRow(plusTbody.childNodes.length);
  360. let cssTextTd = cssTr.insertCell(0);
  361. let cssSelectTd = cssTr.insertCell(1);
  362. let cssSelect = document.createElement('select');
  363. cssSelectTd.appendChild(cssSelect);
  364.  
  365. let customTr = plusTbody.insertRow(plusTbody.childNodes.length);
  366. let customTextTd = customTr.insertCell(0);
  367. let customCssTd = customTr.insertCell(1);
  368. let customCssInput = document.createElement('input');
  369. customCssTd.appendChild(customCssInput);
  370.  
  371. plusTable.style = "text-align: center;";
  372. spoilerTextTd.textContent = "Automatically open spoilers:";
  373. spoilerInput.name = "p1";
  374. spoilerInput.type = "checkbox";
  375. spoilerInput.checked = settings.autospoiler;
  376.  
  377. errorTextTd.textContent = "Automatically reload Cloudflare 502 error pages:";
  378. errorInput.name = "p2";
  379. errorInput.type = "checkbox";
  380. errorInput.checked = settings.auto502;
  381.  
  382. pixelFixTextTd.textContent = "Change pixel scaling to nearest neighbour:";
  383. pixelFixInput.name = "p3";
  384. pixelFixInput.type = "checkbox";
  385. pixelFixInput.checked = settings.pixelFix;
  386.  
  387. textFixTextTd.textContent = "Attempt to fix text errors (experimental)*:";
  388. textFixInput.name = "p4";
  389. textFixInput.type = "checkbox";
  390. textFixInput.checked = settings.textFix;
  391.  
  392. cssTextTd.textContent = "Change style:";
  393.  
  394. customTextTd.textContent = "Custom CSS URL:";
  395. customCssInput.style.width = "99px";
  396. customCssInput.value = settings.styleURL;
  397.  
  398. styleOptions.forEach(o => cssSelect.appendChild(new Option(o, o)));
  399.  
  400. // Enable the save button
  401. spoilerInput.addEventListener("change", () => {
  402. saveBtn.disabled = false;
  403. });
  404. errorInput.addEventListener("change", () => {
  405. saveBtn.disabled = false;
  406. });
  407. pixelFixInput.addEventListener("change", () => {
  408. saveBtn.disabled = false;
  409. });
  410. textFixInput.addEventListener("change", () => {
  411. saveBtn.disabled = false;
  412. });
  413. cssSelect.addEventListener("change", () => {
  414. saveBtn.disabled = false;
  415. });
  416. customCssInput.addEventListener("keydown", () => {
  417. saveBtn.disabled = false;
  418. });
  419.  
  420. saveTr.parentNode.insertBefore(headerTr, saveTr);
  421. saveTr.parentNode.insertBefore(settingsTr, saveTr);
  422. saveTr.parentNode.insertBefore(moreTr, saveTr);
  423. cssSelect.selectedIndex = settings.style;
  424.  
  425. saveBtn.addEventListener('mouseup', () => {
  426. settings.autospoiler = spoilerInput.checked;
  427. settings.style = cssSelect.selectedIndex;
  428. settings.styleURL = customCssInput.value;
  429. settings.auto502 = errorInput.checked;
  430. settings.textFix = textFixInput.checked;
  431. settings.pixelFix = pixelFixInput.checked;
  432. settings.night = false;
  433. console.log(settings);
  434. saveData(settings);
  435.  
  436. updateTheme(settings.style == styleOptions.length - 1 ? settings.styleURL : styleUrls[settings.style]);
  437.  
  438. dropStyle.textContent = dropStyleText + (settings.pixelFix ? ' '+pixelFixText : '');
  439.  
  440. dropStyle.textContent = dropStyleText + (settings.pixelFix ? ' '+pixelFixText : '') + ' *{transition:1s}';
  441. setTimeout(() => {
  442. dropStyle.textContent = dropStyleText + (settings.pixelFix ? ' '+pixelFixText : '');
  443. }, 1000);
  444. });
  445. }
  446. else if (location.pathname === "/my/messages/") { // New buttons
  447. let btnStyle = "margin: 10px 5px;";
  448.  
  449. // Select all read messages button.
  450. const selRead = document.createElement('input');
  451. selRead.style = btnStyle;
  452. selRead.value = "Select Read";
  453. selRead.id = "selectread";
  454. selRead.classList.add("major");
  455. selRead.type = "button";
  456.  
  457. // On click, select all messages with the style attribute indicating it as read.
  458. selRead.addEventListener('mouseup', () => {
  459. document.querySelectorAll('td[style="border-left: 8px solid rgb(221, 221, 221);"] > input').forEach((m) => m.click());
  460. });
  461.  
  462. // Select duplicate message (multiple update notifications).
  463. const selDupe = document.createElement('input');
  464. selDupe.style = btnStyle;
  465. selDupe.value = "Select Same";
  466. selDupe.id = "selectdupe";
  467. selDupe.classList.add("major");
  468. selDupe.type = "button";
  469.  
  470. selDupe.addEventListener('mouseup', evt => {
  471. let temp = document.querySelectorAll('#messages > tr');
  472. let msgs = [];
  473. for (let i = temp.length - 1; i >= 0; i--) {
  474. msgs.push(temp[i]);
  475. }
  476. let titles = [];
  477. msgs.forEach((msg) => {
  478. let title = msg.querySelector('a.major').textContent;
  479. if (/^New update: /.test(title)) { // Select only adventure updates
  480. if (titles.indexOf(title) === -1) {
  481. if (msg.querySelector('td').style.cssText !== "border-left: 8px solid rgb(221, 221, 221);") {
  482. titles.push(title);
  483. }
  484. } else {
  485. msg.querySelector('input').click();
  486. }
  487. }
  488. });
  489. });
  490.  
  491. // Add buttons to the page.
  492. let del = document.querySelector('#deletemsgs');
  493. del.parentNode.appendChild(document.createElement('br'));
  494. del.parentNode.appendChild(selRead);
  495. del.parentNode.appendChild(selDupe);
  496. }
  497. else if (location.pathname === "/my/stories/") {
  498. pageLoad(() => {
  499. let adventures = document.querySelectorAll('#stories tr');
  500. if (adventures.length > 0) {
  501. adventures.forEach(story => {
  502. let buttons = story.querySelectorAll('input.major');
  503. let id = story.querySelector('a').href.replace('https://mspfa.com/', '').replace('&p=1', '');
  504. addLink(buttons[0], `/my/stories/info/${id}`);
  505. addLink(buttons[1], `/my/stories/pages/${id}`);
  506. });
  507. return true;
  508. }
  509. });
  510.  
  511. let guides = ["MSPFA Etiquette", "Fanventure Guide for Dummies", "CSS Guide", "HTML and CSS Things"];
  512. let ids = ["27631", "29299", "21099", "23711"];
  513. let authors = ["Radical Dude 42", "nzar", "MadCreativity", "seymour schlong"];
  514.  
  515. let parentTd = document.querySelector('.container > tbody > tr:last-child > td');
  516. let unofficial = parentTd.querySelector('span');
  517. unofficial.textContent = "Unofficial Guides";
  518. let guideTable = document.createElement('table');
  519. let guideTbody = document.createElement('tbody');
  520. guideTable.style.width = "100%";
  521. guideTable.style.textAlign = "center";
  522.  
  523. guideTable.appendChild(guideTbody);
  524. parentTd.appendChild(guideTable);
  525.  
  526. for (let i = 0; i < guides.length; i++) {
  527. let guideTr = guideTbody.insertRow(i);
  528. let guideTd = guideTr.insertCell(0);
  529. let guideLink = document.createElement('a');
  530. guideLink.href = '/?s='+ids[i];
  531. guideLink.textContent = guides[i];
  532. guideLink.className = "major";
  533. guideTd.appendChild(guideLink);
  534. guideTd.appendChild(document.createElement('br'));
  535. guideTd.appendChild(document.createTextNode('by '+authors[i]));
  536. guideTd.appendChild(document.createElement('br'));
  537. guideTd.appendChild(document.createElement('br'));
  538. }
  539. }
  540. else if (location.pathname === "/my/stories/info/" && location.search) {
  541. addLink(document.querySelector('#userfavs'), `/readers/${location.search}`);
  542. addLink(document.querySelector('#editpages'), `/my/stories/pages/${location.search}`);
  543. }
  544. else if (location.pathname === "/my/stories/pages/" && location.search) {
  545. addLink(document.querySelector('#editinfo'), `/my/stories/info/${location.search}`);
  546. }
  547. else if (location.pathname === "/user/") {
  548. pageLoad(() => {
  549. let msgButton = document.querySelector('#sendmsg');
  550. if (msgButton) {
  551. addLink(msgButton, '/my/messages/new/'); // note: doesn't input the desired user's id
  552. addLink(document.querySelector('#favstories'), `/favs/${location.search}`);
  553. }
  554. });
  555.  
  556. pageLoad(() => {
  557. if (window.MSPFA) {
  558. window.MSPFA.request(0, {
  559. do: "user",
  560. u: location.search.slice(3)
  561. }, user => {
  562. if (typeof user !== "undefined") {
  563. let stats = document.querySelector('#userinfo table');
  564. let joinTr = stats.insertRow(1);
  565. let joinTextTd = joinTr.insertCell(0);
  566. joinTextTd.appendChild(document.createTextNode("Account created:"));
  567. let d = new Date(user.d).toString().split(' ').splice(1, 4).join(' ');
  568. let joinDate = joinTr.insertCell(1);
  569. let joinTime = document.createElement('b');
  570. joinTime.appendChild(document.createTextNode(d));
  571. joinDate.appendChild(joinTime);
  572. }
  573. }, status => {
  574. console.log(status);
  575. }, true);
  576. return true;
  577. }
  578. });
  579. }
  580. else if (location.pathname === "/favs/" && location.search) {
  581. pageLoad(() => {
  582. let stories = document.querySelectorAll('#stories tr');
  583.  
  584. if (stories.length > 0) {
  585. stories.forEach(story => {
  586. let id = story.querySelector('a').href.replace('https://mspfa.com/', '');
  587. pageLoad(() => {
  588. if (window.MSPFA.me.i) {
  589. addLink(story.querySelector('.edit.major'), `/my/stories/info/${id}`);
  590. return;
  591. }
  592. });
  593. addLink(story.querySelector('.rss.major'), `/rss/${id}`);
  594. });
  595. return true;
  596. }
  597. });
  598. }
  599. else if (location.pathname === "/search/" && location.search) {
  600. let pages = document.querySelector('#pages');
  601. let statTable = document.createElement('table');
  602. let statTbody = document.createElement('tbody');
  603. let statTr = statTbody.insertRow(0);
  604. let charCount = statTr.insertCell(0);
  605. let wordCount = statTr.insertCell(0);
  606. let statParentTr = pages.parentNode.parentNode.insertRow(2);
  607. let statParentTd = statParentTr.insertCell(0);
  608.  
  609. let statHeaderTr = statTbody.insertRow(0);
  610. let statHeader = document.createElement('th');
  611. statHeader.colSpan = '2';
  612.  
  613. statHeaderTr.appendChild(statHeader);
  614. statHeader.textContent = 'Statistics may not be entirely accurate.';
  615.  
  616. statTable.style.width = "100%";
  617.  
  618. charCount.textContent = "Character count: loading...";
  619. wordCount.textContent = "Word count: loading...";
  620.  
  621. statTable.appendChild(statTbody);
  622. statParentTd.appendChild(statTable);
  623.  
  624. pageLoad(() => {
  625. if (document.querySelector('#pages br')) {
  626. let bbc = window.MSPFA.BBC.slice();
  627. bbc.splice(0, 3);
  628.  
  629. window.MSPFA.request(0, {
  630. do: "story",
  631. s: location.search.replace('?s=', '')
  632. }, story => {
  633. if (typeof story !== "undefined") {
  634. let pageContent = [];
  635. story.p.forEach(p => {
  636. pageContent.push(p.c);
  637. pageContent.push(p.b);
  638. });
  639.  
  640. let storyText = pageContent.join(' ')
  641. .replace(/\n/g, ' ')
  642. .replace(bbc[0][0], '$1')
  643. .replace(bbc[1][0], '$1')
  644. .replace(bbc[2][0], '$1')
  645. .replace(bbc[3][0], '$1')
  646. .replace(bbc[4][0], '$2')
  647. .replace(bbc[5][0], '$3')
  648. .replace(bbc[6][0], '$3')
  649. .replace(bbc[7][0], '$3')
  650. .replace(bbc[8][0], '$3')
  651. .replace(bbc[9][0], '$3')
  652. .replace(bbc[10][0], '$2')
  653. .replace(bbc[11][0], '$1')
  654. .replace(bbc[12][0], '$3')
  655. .replace(bbc[13][0], '$3')
  656. .replace(bbc[14][0], '')
  657. .replace(bbc[16][0], '$1')
  658. .replace(bbc[17][0], '$2 $4 $5')
  659. .replace(bbc[18][0], '$2 $4 $5')
  660. .replace(bbc[19][0], '')
  661. .replace(bbc[20][0], '')
  662. .replace(/<(.*?)>/g, '');
  663.  
  664. wordCount.textContent = `Word count: ${storyText.split(/ +/g).length}`;
  665. charCount.textContent = `Character count: ${storyText.replace(/ +/g, '').length}`;
  666. }
  667. }, status => {
  668. console.log(status);
  669. }, true);
  670. return true;
  671. }
  672. });
  673. }
  674. })();