User:Bluemorpho/common.js

$( 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 = $('body img[data-image-name*="Render"]');    renders.each(function { var filename = $(this).attr('data-image-name'); var name = ""; var firstName = ""; var squareFileName = ""; if(filename.charAt(0) === "!"){ // console.log(filename.split("!")); name = filename.split("!")[1]; squareFileName = 'https://ensemble-stars.fandom.com/wiki/Special:Redirect/file/' + filename.split("!")[2]; firstName = filename.split("!")[3]; } else if ( $(this).attr('title') === "???" ) { name = "???"; squareFileName = 'https://ensemble-stars.fandom.com/wiki/Special:Redirect/file/Mystery Icon.png'; firstName = "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;                    firstName = chName.replace(/ .*/,'');                }            }); squareFileName = "https://ensemble-stars.fandom.com/wiki/Special:Redirect/file/"+firstName+" ES.png";

}       // console.log(filename + " -> " + name + " / " + firstName); $(this) .wrap(" ") .parent('.character-render-full') .attr('data-char-name', name) ;       const cri = document.createElement('div'); cri.setAttribute('class', 'character-render-icon'); cri.setAttribute('alt', name); cri.innerHTML = '<img src="'+squareFileName+'">'; $(cri).insertBefore( $(this).parent ); var cell = $(this).closest('td'); var attr = cell.attr('alt'); // console.log(attr); if(typeof attr !== 'undefined' && attr !== false){ cell.attr('alt', attr + ' & ' + name); } else { cell.attr('alt', name); }

var colorClass = 'pi-theme-' + firstName.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 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'); }

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

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

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 );    } ); }