MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
(Blanked the page) Tags: Blanking Reverted |
No edit summary Tag: Manual revert |
||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | |||
function loadCustomCSS() { | |||
const link = document.createElement('link'); | |||
link.rel = 'stylesheet'; | |||
link.type = 'text/css'; | |||
link.href = 'custom-theme.css'; | |||
link.id = 'custom-theme'; | |||
document.head.appendChild(link); | |||
} | |||
//document.body.classList.add('custom-theme'); | |||
//loadCustomCSS(); | |||
// Google Analytics gtag.js tracking code | |||
(function() { | |||
var gtagScript = document.createElement('script'); | |||
gtagScript.async = true; | |||
gtagScript.src = "https://www.googletagmanager.com/gtag/js?id=G-J726V56N70"; | |||
document.head.appendChild(gtagScript); | |||
window.dataLayer = window.dataLayer || []; | |||
function gtag(){ dataLayer.push(arguments); } | |||
gtag('js', new Date()); | |||
gtag('config', 'G-J726V56N70'); | |||
})(); | |||
//Удаление активного языка | |||
var currlang; | |||
const usedLanguage = $('.mw-pt-languages-selected'); | |||
if (usedLanguage) { | |||
currlang = usedLanguage.attr('lang'); | |||
const parentElement = usedLanguage.parent(); | |||
if (parentElement) { | |||
parentElement.remove(); | |||
} | |||
} | |||
// Смена ссылки на главную по языкам | |||
var logoLink = document.getElementsByClassName('mw-wiki-logo')[0]; | |||
var logoLinkHref = logoLink.getAttribute('href'); | |||
// Проверяем, что элемент существует | |||
var myVariable = localStorage.getItem("isLightTheme"); | |||
// Смена ссылки у Заглавной страницы | |||
var mainInscr = document.getElementById("n-mainpage-description"); | |||
var userLang = mw.config.get('wgUserLanguage'); | |||
console.log(userLang); | |||
mw.loader.using('mediawiki.util', function() { | |||
//document.body.style.backgroundColor = 'green'; | |||
$(document).ready(function() { | |||
if(myVariable == "true"){ | |||
if(userLang == 'ru'){ | |||
mainInscr.firstElementChild.setAttribute("href", logoLinkHref + '/ru'); | |||
logoLink.setAttribute('href', logoLinkHref + '/ru'); | |||
var newTab = $('<li id="ca-custom"><a>Тёмная тема</a></li>'); | |||
} else if(userLang == 'vi'){ | |||
mainInscr.firstElementChild.setAttribute("href", logoLinkHref + '/vi'); | |||
logoLink.setAttribute('href', logoLinkHref + '/vi'); | |||
var newTab = $('<li id="ca-custom"><a>Chủ đề tối</a></li>'); | |||
} | |||
else{ | |||
var newTab = $('<li id="ca-custom"><a>Dark theme</a></li>'); | |||
} | |||
} else{ | |||
if(userLang == 'ru'){ | |||
mainInscr.firstElementChild.setAttribute("href", logoLinkHref + '/ru'); | |||
logoLink.setAttribute('href', logoLinkHref + '/ru'); | |||
var newTab = $('<li id="ca-custom"><a>Светлая тема</a></li>'); | |||
} else if(userLang == 'vi'){ | |||
mainInscr.firstElementChild.setAttribute("href", logoLinkHref + '/vi'); | |||
logoLink.setAttribute('href', logoLinkHref + '/vi'); | |||
var newTab = $('<li id="ca-custom"><a>Chủ đề nhẹ nhàng</a></li>'); | |||
} | |||
else{ | |||
var newTab = $('<li id="ca-custom"><a>Light theme</a></li>'); | |||
} | |||
} | |||
// Добавляем новую вкладку после вкладки "Читать" | |||
$('#ca-nstab-main').after(newTab); | |||
$('#ca-nstab-special').after(newTab); | |||
}); | |||
}); | |||
$(document).ready(function(){ | |||
//var iframes = document.querySelectorAll('.youtube-iframe'); | |||
var iframes = document.querySelectorAll('iframe'); | |||
Array.prototype.forEach.call(iframes, function(iframe) { | |||
iframe.src = iframe.getAttribute('data-src'); | |||
}); | |||
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(10%,#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', '#fff'); | |||
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', '#0645ad'); | |||
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', '#f8f9fa'); | |||
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'); | |||
document.querySelector('.mw-wiki-logo').style.setProperty('color', '#0645ad', 'important'); | |||
} | |||
// Сохранение переменной в localStorage | |||
$("#ca-custom").click(function(){ | |||
if(myVariable == "true"){ | |||
localStorage.setItem("isLightTheme", "false"); | |||
} else{ | |||
localStorage.setItem("isLightTheme", "true"); | |||
} | |||
location.reload(true); | |||
}); | |||
}); | |||
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 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'); | |||
var img; | |||
if (langValue == 'vi'){ | |||
img = '/images/c/cf/Vi.png'; | |||
} | |||
else if(langValue == 'ru'){ | |||
img = '/images/f/fb/Ru.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'); | |||
} |
Revision as of 22:25, 5 November 2024
/* Any JavaScript here will be loaded for all users on every page load. */
function loadCustomCSS() {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'custom-theme.css';
link.id = 'custom-theme';
document.head.appendChild(link);
}
//document.body.classList.add('custom-theme');
//loadCustomCSS();
// Google Analytics gtag.js tracking code
(function() {
var gtagScript = document.createElement('script');
gtagScript.async = true;
gtagScript.src = "https://www.googletagmanager.com/gtag/js?id=G-J726V56N70";
document.head.appendChild(gtagScript);
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-J726V56N70');
})();
//Удаление активного языка
var currlang;
const usedLanguage = $('.mw-pt-languages-selected');
if (usedLanguage) {
currlang = usedLanguage.attr('lang');
const parentElement = usedLanguage.parent();
if (parentElement) {
parentElement.remove();
}
}
// Смена ссылки на главную по языкам
var logoLink = document.getElementsByClassName('mw-wiki-logo')[0];
var logoLinkHref = logoLink.getAttribute('href');
// Проверяем, что элемент существует
var myVariable = localStorage.getItem("isLightTheme");
// Смена ссылки у Заглавной страницы
var mainInscr = document.getElementById("n-mainpage-description");
var userLang = mw.config.get('wgUserLanguage');
console.log(userLang);
mw.loader.using('mediawiki.util', function() {
//document.body.style.backgroundColor = 'green';
$(document).ready(function() {
if(myVariable == "true"){
if(userLang == 'ru'){
mainInscr.firstElementChild.setAttribute("href", logoLinkHref + '/ru');
logoLink.setAttribute('href', logoLinkHref + '/ru');
var newTab = $('<li id="ca-custom"><a>Тёмная тема</a></li>');
} else if(userLang == 'vi'){
mainInscr.firstElementChild.setAttribute("href", logoLinkHref + '/vi');
logoLink.setAttribute('href', logoLinkHref + '/vi');
var newTab = $('<li id="ca-custom"><a>Chủ đề tối</a></li>');
}
else{
var newTab = $('<li id="ca-custom"><a>Dark theme</a></li>');
}
} else{
if(userLang == 'ru'){
mainInscr.firstElementChild.setAttribute("href", logoLinkHref + '/ru');
logoLink.setAttribute('href', logoLinkHref + '/ru');
var newTab = $('<li id="ca-custom"><a>Светлая тема</a></li>');
} else if(userLang == 'vi'){
mainInscr.firstElementChild.setAttribute("href", logoLinkHref + '/vi');
logoLink.setAttribute('href', logoLinkHref + '/vi');
var newTab = $('<li id="ca-custom"><a>Chủ đề nhẹ nhàng</a></li>');
}
else{
var newTab = $('<li id="ca-custom"><a>Light theme</a></li>');
}
}
// Добавляем новую вкладку после вкладки "Читать"
$('#ca-nstab-main').after(newTab);
$('#ca-nstab-special').after(newTab);
});
});
$(document).ready(function(){
//var iframes = document.querySelectorAll('.youtube-iframe');
var iframes = document.querySelectorAll('iframe');
Array.prototype.forEach.call(iframes, function(iframe) {
iframe.src = iframe.getAttribute('data-src');
});
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(10%,#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', '#fff');
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', '#0645ad');
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', '#f8f9fa');
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');
document.querySelector('.mw-wiki-logo').style.setProperty('color', '#0645ad', 'important');
}
// Сохранение переменной в localStorage
$("#ca-custom").click(function(){
if(myVariable == "true"){
localStorage.setItem("isLightTheme", "false");
} else{
localStorage.setItem("isLightTheme", "true");
}
location.reload(true);
});
});
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 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');
var img;
if (langValue == 'vi'){
img = '/images/c/cf/Vi.png';
}
else if(langValue == 'ru'){
img = '/images/f/fb/Ru.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');
}