User:Bluemorpho/common.js

//toggler var togglers = document.querySelectorAll('[data-toggle="tab"]');

for (var i = 0; i < togglers.length; i++) { togglers[i].addEventListener('click', function {       var tabs = document.querySelectorAll('.tab');        for(var j = 0; j < tabs.length; j++) {            tabs[j].classList.remove('active');        }        var $target = document.querySelector(this.getAttribute('data-target'));        $target.classList.add('active');    }); }

var yourbuttons = document.getElementsByClassName('buttons'); for (var i = yourbuttons.length - 1; i >= 0; i--) { var currentbtn; yourbuttons[i].onclick=function{ if(currentbtn){ currentbtn.classList.remove("highlight"); }     this.classList.add("highlight"); currentbtn=this; } };

//story stuff

var cardStickyHeight = $('.card-pair-stick').outerHeight + 20; 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", "Leona", "Kuro Kiryu", "Riddle", "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", "Gatekeeper" ];

$( document ).ready(function {   mw.loader.using('mediawiki.api', function {

console.log("%cSTORY.JS v0.4.1 — github/jeaoq/enstars-wiki", "display: inline-block; color:#3434eb; background:white; padding: 10px 40px; margin: 0px 5px 5px 0px; border-radius: 15px 5px; border: solid 2px #3434eb; box-shadow: 5px 5px 0px 0px #3434eb; font-weight: 700; font-size: 1.2em;");

$('.storyNavBar').parent.addClass('storyOptions'); ///Adds the button to the top $('.storyTopNav > tbody > tr > *:nth-child(2)').after('\       \            \                text_fields \            \        \        ');

///Adds the specific options row $('.storyTopNav > tbody').append('\       \        \        \            \                question_answer \            \            \                palette \            \            \                format_color_fill \            \            \                copy_all \            \        \        \            \                format_size \            \            \                <li id="sf-14" onclick="storyOptionsFontSize(14);">14px</li>\                <li id="sf-16" onclick="storyOptionsFontSize(16);">16px</li>\                <li id="sf-18" onclick="storyOptionsFontSize(18);">18px</li>\                <li id="sf-21" onclick="storyOptionsFontSize(21);">21px</li>\ </ul>\ \       \            \ <img src="https://static.miraheze.org/twistedwonderlandwiki/9/91/Grim_Head.png" alt="Disable Natsume Spell Font"> \ </a>\ \       \        \        ');    }); }); ///??????? maybe something to do with images, def need to update for twst function tagRenders {    const renders = $('.storytable img[data-image-name*="Render"]');    renders.each(function { var filename = $(this).attr('data-image-name'); var name = ""; var squareFileName = ""; if(filename.charAt(0) === "!"){ // console.log(filename.split("!")); name = filename.split("!")[1]; } else if ( $(this).attr('title') === "???" ) { name = "Mystery"; var render = 'url(' + $(this).attr('src'); + ')'; console.log(render); $(this).closest('td').css("--render", render);

} else { charArray.forEach(function(chName) {               if (filename.includes(chName)) {                    name = chName;                }            }); } ///??????? something to assign the specific chara colors var colorClass = 'pi-theme-' + name.toLowerCase + '-color' cell.parent.addClass(colorClass); }); }

//hides or shows options row function showOptions { $('.storyTopNav').toggleClass('storyOptions'); }

//button for switching images function resizeImg{ $('body').toggleClass('story-minimized'); setPreference('format', $('body').hasClass('story-minimized')); }

//button to show other color options function color{ $('body').toggleClass('story-color'); setPreference('color', $('body').hasClass('story-color')); }

//fills table with color button function colorFill{ $('body').toggleClass('story-colorFill'); setPreference('colorFill', $('body').hasClass('story-colorFill')); }

//fills table with light color button function colorShadow{ $('body').toggleClass('story-colorShadow'); setPreference('colorShadow', $('body').hasClass('story-colorShadow')); }

//font size changer button function storyOptionsFontSize(val) { console.log('Font size = ' + val); document.documentElement.style.setProperty('--story-font-size', val + 'px'); $('[id|="sf"]').removeClass("currentFontSize"); $('#sf-'+val).addClass("currentFontSize"); setPreference('fontSize', val); }

//font changer button function notsume{ $('body').toggleClass('notsume'); setPreference('notsume', $('body').hasClass('notsume')); }

function opendyslexic{ $('body').toggleClass('opendyslexic'); setPreference('opendyslexic', $('body').hasClass('opendyslexic')); }

//adds classes to story table maybe function initialConfigStory{ document.documentElement.style.setProperty('--content-width', $('#content').width + 'px'); var params = { action: 'query', meta: 'userinfo', uiprop: 'options', format: 'json' },       api = new mw.Api; api.get( params ).done( function ( data ) {   	var pref = data.query.userinfo;        // console.log( pref );        if(pref.options['userjs-fontSize'] === "undefined"){        	setPreference('fontSize', '16');        }        storyOptionsFontSize(pref.options['userjs-fontSize']);

if(pref.options['userjs-format'] === "undefined"){ setPreference('format', false); }       else if(pref.options['userjs-format']){ $('body').addClass('story-minimized'); }

if(pref.options['userjs-color'] === "undefined"){ setPreference('color', false); }       else if(pref.options['userjs-color']){ $('body').addClass('story-color'); }

if(pref.options['userjs-colorFill'] === "undefined"){ setPreference('colorFill', false); }       else if(pref.options['userjs-colorFill']){ $('body').addClass('story-colorFill'); }

if(pref.options['userjs-colorShadow'] === "undefined"){ setPreference('colorShadow', false); }       else if(pref.options['userjs-colorShadow']){ $('body').addClass('story-colorShadow'); }       tagRenders; } ); }

function getPreference(param){ var params = { action: 'query', meta: 'userinfo', uiprop: 'options', format: 'json' },       api = new mw.Api, pref; api.get( params ).done( function ( data ) {   	pref = data.query.userinfo.options['userjs-'+param];        // console.log( pref );    } ); }