MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 85: | Line 85: | ||
var firstChild = parent.firstElementChild; | var firstChild = parent.firstElementChild; | ||
firstChild.innerHTML = 'About MU Bless Online Wikipedia'; | firstChild.innerHTML = 'About MU Bless Online Wikipedia'; | ||
//Удаление активного языка | |||
const usedLanguage = document.querySelector(".mw-pt-languages-selected"); | |||
if (usedLanguage) { | |||
const parentElement = usedLanguage.parentElement; | |||
if (parentElement) { | |||
parentElement.remove(); | |||
} | |||
} | |||
//Изменение языков на флажки | |||
const selectedElement = $('.mw-pt-languages-list'); | |||
if (selectedElement.length) { | |||
selectedElement.children('li').each(function() { | |||
const anchor = $(this).find('a'); | |||
if (anchor.length) { | |||
const hrefValue = anchor.attr('href'); | |||
const langValue = anchor.attr('lang'); | |||
console.log('hrefValue:', hrefValue); | |||
console.log('langValue:', langValue); | |||
var img; | |||
if (langValue == 'vi'){ | |||
img = '/images/f/f0/Vietnam.png'; | |||
} | |||
else if(langValue == 'ru'){ | |||
img = 'images/e/ee/Russia.png'; | |||
} | |||
else if(langValue == 'en'){ | |||
img = '/images/0/0a/Usa.png'; | |||
} | |||
$('<a>', { | |||
href: hrefValue | |||
}).append($('<img>', { | |||
class: 'languageimg', | |||
src: img, | |||
alt: langValue | |||
})).appendTo(selectedElement); | |||
} | |||
$(this).remove(); | |||
}); | |||
} else { | |||
console.log('Element not found'); | |||
} | |||
document.body.style.display= "block"; | document.body.style.display= "block"; |
Revision as of 10:17, 17 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, #f6f6f6)');
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');
document.documentElement.style.setProperty('--kbd-background-color', 'white');
}
// Сохранение переменной в 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"));
});
});
var element1 = document.getElementsByClassName('vector-search-box-input')[0];
element1.placeholder = 'MU Bless Online Wikipedia';
var parent = document.getElementById('footer-places-about');
var firstChild = parent.firstElementChild;
firstChild.innerHTML = 'About MU Bless Online Wikipedia';
//Удаление активного языка
const usedLanguage = document.querySelector(".mw-pt-languages-selected");
if (usedLanguage) {
const parentElement = usedLanguage.parentElement;
if (parentElement) {
parentElement.remove();
}
}
//Изменение языков на флажки
const selectedElement = $('.mw-pt-languages-list');
if (selectedElement.length) {
selectedElement.children('li').each(function() {
const anchor = $(this).find('a');
if (anchor.length) {
const hrefValue = anchor.attr('href');
const langValue = anchor.attr('lang');
console.log('hrefValue:', hrefValue);
console.log('langValue:', langValue);
var img;
if (langValue == 'vi'){
img = '/images/f/f0/Vietnam.png';
}
else if(langValue == 'ru'){
img = 'images/e/ee/Russia.png';
}
else if(langValue == 'en'){
img = '/images/0/0a/Usa.png';
}
$('<a>', {
href: hrefValue
}).append($('<img>', {
class: 'languageimg',
src: img,
alt: langValue
})).appendTo(selectedElement);
}
$(this).remove();
});
} else {
console.log('Element not found');
}
document.body.style.display= "block";