MediaWiki:Common.js: Difference between revisions

From MU Bless Online Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 10: Line 10:
              
              
             if(myVariable == "true"){
             if(myVariable == "true"){
             var newTab = $('<li id="ca-custom"><a>Wiki dark</a></li>');
             var newTab = $('<li id="ca-custom"><a>Wiki dark theme</a></li>');
             } else{
             } else{
             var newTab = $('<li id="ca-custom"><a>Wiki light</a></li>');
             var newTab = $('<li id="ca-custom"><a>Wiki light theme</a></li>');
             }
             }
              
              

Revision as of 12:38, 9 July 2024

/* Any JavaScript here will be loaded for all users on every page load. */

var myVariable = localStorage.getItem("isLightTheme");

mw.loader.using('mediawiki.util', function() {
    $(document).ready(function() {
        // Проверяем, что элемент существует

            // Создаем новую вкладку
            
            if(myVariable == "true"){
            	var newTab = $('<li id="ca-custom"><a>Wiki dark theme</a></li>');
            } else{
            	var newTab = $('<li id="ca-custom"><a>Wiki light theme</a></li>');
            }
            
            // Добавляем новую вкладку после вкладки "Читать"
            $('#ca-nstab-main').after(newTab);
               //if ($('#ca-nstab-main').length) { }
    });
});

$(document).ready(function(){
	
	if(myVariable == "true"){
		// Применение стилей для светлой темы
        document.documentElement.style.setProperty('--main-bg-color', '#f6f6f6');
        document.documentElement.style.setProperty('--mw-head-back-image', '-webkit-gradient(linear,left top,left bottom,color-stop(50%,#f6f6f6),color-stop(50%, #ffffff))');
        document.documentElement.style.setProperty('--secondary-bg-color', '#f6f6f6');
        document.documentElement.style.setProperty('--bodycontent-bg-color', '#ffffff');
        document.documentElement.style.setProperty('--table-bg-color', '#f6f6f6');
        document.documentElement.style.setProperty('--main-table-td-border', '1px solid var(--border-color-subtle, #c8ccd1)');
        document.documentElement.style.setProperty('--main-table-td-box-shadow', '0 1px 1px rgba(0,0,0,0.15)');
        document.documentElement.style.setProperty('--videoguides-bg-color', '#f6f6f6');
        document.documentElement.style.setProperty('--video-guides-border', '1px solid var(--border-color-subtle, #c8ccd1)');
        document.documentElement.style.setProperty('--video-guides-box-shadow', '0 1px 1px rgba(0, 0, 0, 0.15)');
        document.documentElement.style.setProperty('--a-ul-span-color', '#0b0080');
        document.documentElement.style.setProperty('--p-span-li-color', 'black');
        document.documentElement.style.setProperty('--h1-span-h2-span-h3-span-h4-span-color', 'black');
        document.documentElement.style.setProperty('--h1-h2-h3-h4-h5-h6-color', 'black');
        document.documentElement.style.setProperty('--title-p-color', 'initial');
        document.documentElement.style.setProperty('--b-color', 'initial');
        document.documentElement.style.setProperty('--toc-background-color', 'var(--background-color-neutral-subtle,#f8f9fa)');
        document.documentElement.style.setProperty('--toc-border', '1px solid var(--border-color-base,#a2a9b1)');
        document.documentElement.style.setProperty('--toc-border-color', '#a2a9b1');
        document.documentElement.style.setProperty('--toc-h2-color', 'initial');
        document.documentElement.style.setProperty('--p-banner-label-color', 'initial');
        document.documentElement.style.setProperty('--catlinks-background-color', 'initial');
        document.documentElement.style.setProperty('--catlinks-border-color', '#a2a9b1');
        document.documentElement.style.setProperty('--mw-body-color', 'initial');
        document.documentElement.style.setProperty('--mw-body-border', '1px solid #a7d7f9');
        document.documentElement.style.setProperty('--vector-menu-content-list-background-color', 'initial');
        document.documentElement.style.setProperty('--div-simpleSearch-searchInput-background-color', 'initial');
        document.documentElement.style.setProperty('--vector-menu-tabs-vector-menu-tabs-a-mw-head-vector-menu-dropdown-vector-menu-heading-background-image', 'linear-gradient(to bottom,rgba(167,215,249,0) 0,#a7d7f9 100%)');
        document.documentElement.style.setProperty('--vector-menu-tabs-legacy-selected-background-color', 'none');
        document.documentElement.style.setProperty('--vector-menu-tabs-legacy-li-background-image', 'linear-gradient(to top,#77c1f6 0,#e8f2f8 1px,#fff 100%)');
        document.documentElement.style.setProperty('--project-settings-background-color', '#f3f5f7');
        document.documentElement.style.setProperty('--project-settings-border', '1px solid var(--border-color-base,#a2a9b1)');
        document.documentElement.style.setProperty('--logo-div-background-image', 'url(https://upload.wikimedia.org/wikipedia/commons/e/e3/Wikipedia_logo_letters_banner.svg)');
        document.documentElement.style.setProperty('--logo-div-background-color', 'var(--background-color-neutral-subtle, #f8f9fa)');
        document.documentElement.style.setProperty('--logo-div-border', '1px solid var(--border-color-subtle, #c8ccd1)');
        document.documentElement.style.setProperty('--logo-div-border-radius', '2px');
        document.documentElement.style.setProperty('--logo-div-box-shadow', '0 1px 1px rgba(0, 0, 0, .15)');
        document.documentElement.style.setProperty('--a-visited', '#0b0080');
	}

            // Сохранение переменной в localStorage
            $("#ca-custom").click(function(){
            	if(myVariable == "true"){
            	 	localStorage.setItem("isLightTheme", "false");
            	 } else{
            	 	localStorage.setItem("isLightTheme", "true");
            	 }
            	location.reload(true);
            	console.log(typeof localStorage.getItem("isLightTheme"));
            });
            
});

document.body.style.display= "block";