Advertisement
XinChun93

enst js

Jun 11th, 2020
1,310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Any JavaScript here will be loaded for all users on every page load. */
  2.  
  3. /* Auto Refresh */
  4. window.ajaxPages = ['Special:RecentChanges','Special:WikiActivity'];
  5. window.AjaxRCRefreshText = 'Auto-refresh';
  6.  
  7. var oggPlayerButtonOnly = false;
  8.  
  9. var tooltips_config = {
  10.     waitForImages: false,
  11.     events: ['CustomEvent'],
  12.     noCSS: true,
  13. };
  14.  
  15. /*Story Render Themes*/
  16. console.log("Script version 1.1.0 is running!");
  17. console.log("Contact XinChun93 on Twitter if there are any questions or concerns!");
  18. console.log("https://github.com/yaycupcake/enstars-wiki-js");
  19. var d = document;
  20. var fontPref = "1em";
  21. if (localStorage.getItem("fP")) {
  22.     fontPref = localStorage.getItem("fP");
  23. }
  24.  
  25. function toggleFontSize() {
  26.     if (fontPref === "1em") {
  27.         fontPref = "1.2em";
  28.     } else {
  29.         fontPref = "1em";
  30.     }
  31.     localStorage.setItem("fP",fontPref);
  32. }
  33.  
  34. var activator = d.createElement("button");
  35. activator.classList.add("activator");
  36. activator.style.height = "75px";
  37. activator.textContent = "Activate Immersive Chapter View (Experimental)";
  38. activator.addEventListener("click", activateTheme);
  39. activator.setAttribute("id", "themeJump");
  40. var activatorJumpLink = d.createElement("a");
  41. activatorJumpLink.href = "#flytabs_0-content-wrapper";
  42. activatorJumpLink.appendChild(activator);
  43.  
  44. var fontToggler = d.createElement("button");
  45. fontToggler.classList.add("font-toggler");
  46. fontToggler.textContent = "Change Font Size, current is " + fontPref;
  47. fontToggler.addEventListener("click",toggleFontSize);
  48. fontToggler.style.height = "24px";
  49. fontToggler.style.color = "white";
  50. fontToggler.style.background = "#1d3dc7";
  51. fontToggler.style.width = "100%";
  52. fontToggler.style.borderRadius = "0px";
  53.  
  54. var jumpToTop = d.createElement("button");
  55. jumpToTop.classList.add("jumpToTop");
  56. jumpToTop.style.height = "75px";
  57. jumpToTop.textContent = "Jump To Chapter List";
  58. var jumpToTopLink = d.createElement("a");
  59. jumpToTopLink.href = "#themeJump";
  60. jumpToTopLink.appendChild(jumpToTop);
  61. var body = d.querySelector("body");
  62. body.style.position = "relative";
  63. activator.style.width = "100%";
  64. jumpToTop.style.width = "100%";
  65. var tabBar = d.querySelector(".newStoryTable #flytabs_0");
  66. if (tabBar) {
  67.   tabBar.insertAdjacentElement("beforebegin", activatorJumpLink);
  68. //   tabBar.insertAdjacentElement("beforebegin", fontToggler);
  69.   tabBar.insertAdjacentElement("afterend", jumpToTopLink);
  70. }
  71.  
  72. function activateTheme() {
  73.   var charArray = [
  74.     "Kohaku Oukawa",
  75.     "Aira Shiratori",
  76.     "Tomoya Mashiro",
  77.     "Yuta Aoi",
  78.     "Hinata Aoi",
  79.     "Tori Himemiya",
  80.     "Hiiro Amagi",
  81.     "Mitsuru Tenma",
  82.     "Midori Takamine",
  83.     "Hajime Shino",
  84.     "Sora Harukawa",
  85.     "Tetora Nagumo",
  86.     "Shinobu Sengoku",
  87.     "Tsukasa Suou",
  88.     "Mao Isara",
  89.     "Arashi Narukami",
  90.     "Natsume Sakasaki",
  91.     "Tatsumi Kazehaya",
  92.     "Mika Kagehira",
  93.     "Hokuto Hidaka",
  94.     "Ibara Saegusa",
  95.     "Yuzuru Fushimi",
  96.     "Adonis Otogari",
  97.     "Jun Sazanami",
  98.     "Koga Oogami",
  99.     "HiMERU",
  100.     "Subaru Akehoshi",
  101.     "Mayoi Ayase",
  102.     "Makoto Yuuki",
  103.     "Souma Kanzaki",
  104.     "Wataru Hibiki",
  105.     "Kuro Kiryu",
  106.     "Eichi Tenshouin",
  107.     "Kaoru Hakaze",
  108.     "Izumi Sena",
  109.     "Shu Itsuki",
  110.     "Nagisa Ran",
  111.     "Niki Shiina",
  112.     "Ritsu Sakuma",
  113.     "Chiaki Morisawa",
  114.     "Keito Hasumi",
  115.     "Kanata Shinkai",
  116.     "Tsumugi Aoba",
  117.     "Hiyori Tomoe",
  118.     "Madara Mikejima",
  119.     "Leo Tsukinaga",
  120.     "Nazuna Nito",
  121.     "Rei Sakuma",
  122.     "Rinne Amagi",
  123.     "Akiomi Kunugi",
  124.     "Jin Sagami",
  125.     "Seiya Hidaka",
  126.     "Anzu"
  127.   ];
  128.  
  129.   function removeBorders() {
  130.     var tableCells = d.querySelectorAll(".article-table td");
  131.     tableCells.forEach(function(cell) {
  132.       cell.style.border = "none";
  133.     });
  134.   }
  135.   removeBorders();
  136.  
  137.   function adjustImages() {
  138.     var storyImgs = d.querySelectorAll("img[data-image-name*='Render']");
  139.     storyImgs.forEach(function(img, index) {
  140.       img.style.maxWidth = "100px";
  141.       img.style.height = "auto";
  142.       img.classList.add("story-image");
  143.       var charFileName = img.getAttribute("data-image-name");
  144.       var charName = findCharName(charFileName);
  145.       var speakerNameClass = "speaker-name_" + index;
  146.       var speakerNameClassSelector = "." + speakerNameClass;
  147.       if (!d.querySelector(speakerNameClassSelector)) {
  148.         var nameNode = d.createElement("p");
  149.         nameNode.classList.add(speakerNameClass);
  150.         nameNode.textContent = charName;
  151.         if (window.matchMedia("(max-width: 700px)").matches) {
  152.           nameNode.style.textAlign = "left";
  153.           nameNode.textContent += ":";
  154.         }
  155.         img.insertAdjacentElement("afterend", nameNode);
  156.       }
  157.       //select td parent of image
  158.       var parentTd = img.closest("td");
  159.       var nextTd = parentTd.nextSibling;
  160.       if (nextTd) {
  161.         nextTd.classList.add("nextTd");
  162.       }
  163.       else {
  164.         return;
  165.       }
  166.       parentTd.style.verticalAlign = "top";
  167.       parentTd.style.paddingTop = "1em";
  168.       parentTd.style.fontSize = fontPref;
  169.       parentTd.style.lineHeight = "1.2em";
  170.       // console.log("showing contents")
  171.       var dialogueBox = d.createElement("div");
  172.       dialogueBox.classList.add("dialigue-box");
  173.       var contents = nextTd.innerHTML;
  174.       dialogueBox.innerHTML = contents;
  175.       parentTd.appendChild(dialogueBox);
  176.       nextTd.remove();
  177.       var parentRow = parentTd.parentNode;
  178.       //make every other row a different background color
  179.       if (index % 2 === 0) {
  180.         parentRow.style.backgroundColor = "rgba(220,220,210,0.4)";
  181.       }
  182.       else {
  183.         parentRow.style.backgroundColor = "rgba(215,215,220,0.6)";
  184.       }
  185.       //remove borders
  186.       parentTd.style.border = "none";
  187.       parentRow.style.border = "none";
  188.       parentTd.style.display = "flex";
  189.       parentTd.style.alignItems = "flex-start";
  190.       parentTd.style.justifyContent = "flex-start";
  191.       if (window.matchMedia("(max-width: 700px)").matches) {
  192.         parentTd.style.flexDirection = "column";
  193.       }
  194.       if (window.matchMedia("(min-width: 701px)").matches) {
  195.         parentTd.style.flexDirection = "row";
  196.       }
  197.       var imageDiv = img.parentNode.parentNode;
  198.       if (window.matchMedia("(min-width: 701px)").matches) {
  199.         imageDiv.style.width = "150px";
  200.         imageDiv.style.flex = "0 0 150px";
  201.         dialogueBox.style.paddingLeft = "2em";
  202.       }
  203.     });
  204.     if (window.matchMedia("(max-width: 700px)").matches) {
  205.       storyImgs.forEach(function(img) {
  206.         img.style.display = "none";
  207.       });
  208.     }
  209.     if (window.matchMedia("(min-width: 701px)").matches) {
  210.       storyImgs.forEach(function(img) {
  211.         img.style.display = "static";
  212.       });
  213.     }
  214.   }
  215.   adjustImages();
  216.   // Function for parsing file names for each character
  217.   function findCharName(file) {
  218.     if (file.includes("Render")) {
  219.       var name = "";
  220.       var parseName = function(file, chName) {
  221.         if (file.includes(chName)) {
  222.           name = chName;
  223.         }
  224.         return name;
  225.       };
  226.       charArray.forEach(function(chName) {
  227.         if (parseName(file, chName)) {
  228.           return name;
  229.         }
  230.       });
  231.       return name;
  232.     }
  233.   }
  234. }
  235.  
  236. /* Back to Top Arrow (Main code in MediaWiki:ImportJS) */
  237. window.BackToTopModern = true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement