User:Hajike Tobiume/common.js

// ==UserScript== // @name        enstars script NEW UPDATE VERSION WIP // @namespace   http://tampermonkey.net/ // @version     2.0.1 // @description try to take over the world! // @author      You // @match       https://ensemble-stars.fandom.com/* // @grant       none // ==/UserScript== (function {   'use strict'; console.log("Script version 2.0.1 is running!"); console.log("Contact XinChun93 on Twitter if there are any questions or concerns!"); console.log("https://github.com/yaycupcake/enstars-wiki-js"); var d = document; var fontPref = "1em"; var localFontPref = localStorage.getItem("fP"); if (localFontPref) {     fontPref = localStorage.getItem("fP"); } var readerPref = false; var localReaderPref = localStorage.getItem("rP") if (localReaderPref) {     readerPref = localStorage.getItem("rP"); } ///// //below is CUSTOM PERSONAL ONLY ///// console.log('running personal js'); console.log('aaaa123'); function toggleFontSize1p0 {    fontPref = "1em";    localStorage.setItem("fP",fontPref); } function toggleFontSize1p2 {    fontPref = "1.2em";    localStorage.setItem("fP",fontPref); } function toggleFontSize1p3 {    fontPref = "1.3em";    localStorage.setItem("fP",fontPref); } function toggleFontSize1p5 { fontPref = "1.5em"; localStorage.setItem("fP",fontPref); } function toggleFontSize2p0 { fontPref = "2em"; localStorage.setItem("fP",fontPref); } function fontCheck { alert('local storage fP is ' + localStorage.getItem('fP') + ' and fontPref is ' + fontPref); } function turnOnTheme { readerPref = true; localStorage.setItem("rP",readerPref); } function turnOffTheme { readerPref = false; localStorage.setItem("rP",readerPref); } function readerCheck { alert('local storage rP is ' + localStorage.getItem('rP') + ' and readerPref is '+ readerPref); } var btnFont1p0 = d.createElement("button"); btnFont1p0.classList.add("fontTog"); btnFont1p0.classList.add("fontTog1p0"); btnFont1p0.textContent = "set to 1em"; btnFont1p0.addEventListener("click", toggleFontSize1p0); var btnFont1p2 = d.createElement("button"); btnFont1p2.classList.add("fontTog"); btnFont1p2.classList.add("fontTog1p2"); btnFont1p2.textContent = "set to 1.2em"; btnFont1p2.addEventListener("click", toggleFontSize1p2); var btnFont1p3 = d.createElement("button"); btnFont1p3.classList.add("fontTog"); btnFont1p3.classList.add("fontTog1p3"); btnFont1p3.textContent = "set to 1.3em"; btnFont1p3.addEventListener("click", toggleFontSize1p3); var btnFont1p5 = d.createElement("button"); btnFont1p5.classList.add("fontTog"); btnFont1p5.classList.add("fontTog1p5"); btnFont1p5.textContent = "set to 1.5em"; btnFont1p5.addEventListener("click", toggleFontSize1p5); var btnFont2p0 = d.createElement("button"); btnFont2p0.classList.add("fontTog"); btnFont2p0.classList.add("fontTog2p0"); btnFont2p0.textContent = "set to 2em"; btnFont2p0.addEventListener("click", toggleFontSize2p0); var btnChecker = d.createElement("button"); btnChecker.classList.add("fontTog"); btnChecker.classList.add("fontTogChecker"); btnChecker.textContent = "check"; btnChecker.addEventListener("click", fontCheck); var btnOnToggler = d.createElement("button"); btnOnToggler.classList.add("toggler"); btnOnToggler.classList.add("onToggler"); btnOnToggler.textContent = "activate theme"; btnOnToggler.addEventListener("click", turnOnTheme); var btnOffToggler = d.createElement("button"); btnOffToggler.classList.add("toggler"); btnOffToggler.classList.add("offToggler"); btnOffToggler.textContent = "deactivate theme"; btnOffToggler.addEventListener("click", turnOffTheme); var btnChecker2 = d.createElement("button"); btnChecker2.classList.add("toggler"); btnChecker2.classList.add("readerChecker"); btnChecker2.textContent = "check"; btnChecker2.addEventListener("click", readerCheck); console.log('btns made'); var ycc = d.querySelector(".yaycupcake-table"); console.log('ycc searched'); if (ycc) { ycc.insertAdjacentElement("afterend", btnFont1p0); ycc.insertAdjacentElement("afterend", btnFont1p2); ycc.insertAdjacentElement("afterend", btnFont1p3); ycc.insertAdjacentElement("afterend", btnFont1p5); ycc.insertAdjacentElement("afterend", btnFont2p0); ycc.insertAdjacentElement("afterend", btnChecker); ycc.insertAdjacentElement("afterend", btnOnToggler); ycc.insertAdjacentElement("afterend", btnOffToggler); ycc.insertAdjacentElement("afterend", btnChecker2); } ///// //ABOVE is custom personal stuff ///// console.log('custover'); function toggleFontSize { if (fontPref === "1em") { fontPref = "1.2em"; } else { fontPref = "1em"; }   localStorage.setItem("fP",fontPref); } console.log('belowtog'); if (readerPref) { activateTheme; } var activator = d.createElement("button"); activator.classList.add("activator"); activator.style.height = "75px"; activator.textContent = "Activate Immersive Chapter View (Experimental) MONOLOGUE TEST"; activator.addEventListener("click", activateTheme); activator.setAttribute("id", "themeJump"); var activatorJumpLink = d.createElement("a"); activatorJumpLink.href = "#flytabs_0-content-wrapper"; activatorJumpLink.appendChild(activator); // custom TEST stuff here //   activator.style.position = "sticky"; //   activator.style.bottom = "0px"; //   d.querySelector("body").appendChild(activator); // custom TEST stuff ends var fontToggler = d.createElement("button"); fontToggler.classList.add("font-toggler"); fontToggler.textContent = "Change Font Size, current is " + fontPref; fontToggler.addEventListener("click",toggleFontSize); fontToggler.style.height = "24px"; fontToggler.style.color = "white"; fontToggler.style.background = "#1d3dc7"; fontToggler.style.width = "100%"; fontToggler.style.borderRadius = "0px"; var jumpToTop = d.createElement("button"); jumpToTop.classList.add("jumpToTop"); jumpToTop.style.height = "75px"; jumpToTop.textContent = "Jump To Chapter List"; var jumpToTopLink = d.createElement("a"); jumpToTopLink.href = "#themeJump"; jumpToTopLink.appendChild(jumpToTop); var body = d.querySelector("body"); body.style.position = "relative"; activator.style.width = "100%"; jumpToTop.style.width = "100%"; var tabBar = d.querySelector(".newStoryTable #flytabs_0"); if (tabBar) { tabBar.insertAdjacentElement("beforebegin", activatorJumpLink); //  tabBar.insertAdjacentElement("beforebegin", fontToggler); tabBar.insertAdjacentElement("afterend", jumpToTopLink); } function activateTheme { var charArray = [ "Kohaku Oukawa", "Aira Shiratori", "Tomoya Mashiro", "Yuta Aoi", "Hinata Aoi", "Tori Himemiya", "Hiiro Amagi", "Mitsuru Tenma", "Midori Takamine", "Hajime Shino", "Sora Harukawa", "Tetora Nagumo", "Shinobu Sengoku", "Tsukasa Suou", "Mao Isara", "Arashi Narukami", "Natsume Sakasaki", "Tatsumi Kazehaya", "Mika Kagehira", "Hokuto Hidaka", "Ibara Saegusa", "Yuzuru Fushimi", "Adonis Otogari", "Jun Sazanami", "Koga Oogami", "HiMERU", "Subaru Akehoshi", "Mayoi Ayase", "Makoto Yuuki", "Souma Kanzaki", "Wataru Hibiki", "Kuro Kiryu", "Eichi Tenshouin", "Kaoru Hakaze", "Izumi Sena", "Shu Itsuki", "Nagisa Ran", "Niki Shiina", "Ritsu Sakuma", "Chiaki Morisawa", "Keito Hasumi", "Kanata Shinkai", "Tsumugi Aoba", "Hiyori Tomoe", "Madara Mikejima", "Leo Tsukinaga", "Nazuna Nito", "Rei Sakuma", "Rinne Amagi", "Akiomi Kunugi", "Jin Sagami", "Seiya Hidaka", "Anzu" ]; function removeBorders { var tableCells = d.querySelectorAll(".article-table td"); tableCells.forEach(function(cell) {     cell.style.border = "none";    }); } removeBorders; function adjustMonologueText { var monoBox = d.querySelectorAll(".monologue td"); monoBox.forEach(function(box, index) {         if (box.style.textAlign !== "center") {            box.style.verticalAlign = "top";            box.style.paddingTop = "1em";            box.style.fontSize = fontPref;            box.style.lineHeight = "1.2em";          }      }); } adjustMonologueText; function adjustImages { var storyImgs = d.querySelectorAll("img[data-image-name*='Render']"); storyImgs.forEach(function(img, index) {     img.style.maxWidth = "100px";      img.style.height = "auto";      img.classList.add("story-image");      var charFileName = img.getAttribute("data-image-name");      var charName = findCharName(charFileName);      var speakerNameClass = "speaker-name_" + index;      var speakerNameClassSelector = "." + speakerNameClass;      if (!d.querySelector(speakerNameClassSelector)) {        var nameNode = d.createElement("p");        nameNode.classList.add(speakerNameClass);        nameNode.textContent = charName;        if (window.matchMedia("(max-width: 700px)").matches) {          nameNode.style.textAlign = "left";          nameNode.textContent += ":";        }        img.insertAdjacentElement("afterend", nameNode);      }      //select td parent of image      var parentTd = img.closest("td");      var nextTd = parentTd.nextSibling;        console.log(nextTd); if (nextTd) { if (!nextTd.classList) { nextTd = nextTd.nextSibling; }       nextTd.classList.add("nextTd"); }     else { return; }     parentTd.style.verticalAlign = "top"; parentTd.style.paddingTop = "1em"; parentTd.style.fontSize = fontPref; parentTd.style.lineHeight = "1.2em"; // console.log("showing contents") var dialogueBox = d.createElement("div"); dialogueBox.classList.add("dialigue-box"); var contents = nextTd.innerHTML; dialogueBox.innerHTML = contents; parentTd.appendChild(dialogueBox); nextTd.remove; var parentRow = parentTd.parentNode; //make every other row a different background color if (index % 2 === 0) { parentRow.style.backgroundColor = "rgba(220,220,210,0.4)"; }     else { parentRow.style.backgroundColor = "rgba(215,215,220,0.6)"; }     //remove borders parentTd.style.border = "none"; parentRow.style.border = "none"; parentTd.style.display = "flex"; parentTd.style.alignItems = "flex-start"; parentTd.style.justifyContent = "flex-start"; if (window.matchMedia("(max-width: 700px)").matches) { parentTd.style.flexDirection = "column"; }     if (window.matchMedia("(min-width: 701px)").matches) { parentTd.style.flexDirection = "row"; }     var imageDiv = img.parentNode.parentNode; if (window.matchMedia("(min-width: 701px)").matches) { imageDiv.style.width = "150px"; imageDiv.style.flex = "0 0 150px"; dialogueBox.style.paddingLeft = "2em"; }   });    if (window.matchMedia("(max-width: 700px)").matches) {      storyImgs.forEach(function(img) { img.style.display = "none"; });   }    if (window.matchMedia("(min-width: 701px)").matches) {      storyImgs.forEach(function(img) { img.style.display = "static"; });   }  }  adjustImages;  // Function for parsing file names for each character  function findCharName(file) {    if (file.includes("Render")) {      var name = "";      var parseName = function(file, chName) {        if (file.includes(chName)) {          name = chName;        }        return name;      };      charArray.forEach(function(chName) { if (parseName(file, chName)) { return name; }     });      return name;    }  } } });