MediaWiki:Gadget-DarkModeVector2010.js: различия между версиями
Перейти к навигации
Перейти к поиску
Ланселот (обсуждение | вклад) Проба |
Ланселот (обсуждение | вклад) м Ланселот переименовал страницу MediaWiki:Gadget-DarkModeVector10.js в MediaWiki:Gadget-DarkModeVector2010.js без оставления перенаправления |
||
(нет различий)
| |||
Версия от 15:45, 16 октября 2026
/* Гаджет: Ночная тема для Vector-10 */
( function ( mw, $ ) {
'use strict';
var STORAGE_KEY = 'gadget-darkmode-vector2010';
var CLASS_NAME = 'darkmode-vector2010';
function isEnabled() {
return mw.storage.get( STORAGE_KEY ) === '1';
}
function applyTheme( enable ) {
var $body = $( document.body );
if ( enable ) {
$body.addClass( CLASS_NAME );
mw.storage.set( STORAGE_KEY, '1' );
} else {
$body.removeClass( CLASS_NAME );
mw.storage.set( STORAGE_KEY, '0' );
}
updateButton( enable );
}
function updateButton( enabled ) {
var $btn = $( '#dm-toggle' );
if ( !$btn.length ) return;
$btn.text( enabled ? '☀️ День' : '🌙 Ночь' )
.attr( 'title', enabled ? 'Включить светлую тему' : 'Включить тёмную тему' );
}
function createButton() {
var $portlet = $( '#p-personal ul' );
if ( !$portlet.length ) return;
var $li = $( '<li>' ).attr( 'id', 'pt-darkmode' );
var $link = $( '<a>' )
.attr( 'href', '#' )
.attr( 'id', 'dm-toggle' )
.text( '🌙 Ночь' )
.on( 'click', function ( e ) {
e.preventDefault();
applyTheme( !isEnabled() );
} );
$li.append( $link );
$portlet.append( $li );
}
function injectStyles() {
var css = [
'/* ==== Ночная тема Vector 2010 ==== */',
'body.darkmode-vector2010 {',
' background: #1a1a1a !important;',
' color: #d0d0d0 !important;',
'}',
'body.darkmode-vector2010 #content,',
'body.darkmode-vector2010 #mw-page-base,',
'body.darkmode-vector2010 #mw-head-base {',
' background: #1a1a1a !important;',
' background-image: none !important;',
' color: #d0d0d0 !important;',
'}',
'body.darkmode-vector2010 a { color: #6cb6ff !important; }',
'body.darkmode-vector2010 a:visited { color: #b48cff !important; }',
'body.darkmode-vector2010 a.new { color: #ff7b7b !important; }',
'body.darkmode-vector2010 h1,',
'body.darkmode-vector2010 h2,',
'body.darkmode-vector2010 h3,',
'body.darkmode-vector2010 h4,',
'body.darkmode-vector2010 h5,',
'body.darkmode-vector2010 h6 {',
' color: #ffffff !important;',
' border-bottom-color: #444 !important;',
'}',
'body.darkmode-vector2010 hr { border-color: #444 !important; }',
'body.darkmode-vector2010 table,',
'body.darkmode-vector2010 th,',
'body.darkmode-vector2010 td {',
' background: #222 !important;',
' color: #d0d0d0 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .wikitable > * > tr > th {',
' background: #2d2d2d !important;',
'}',
'body.darkmode-vector2010 code,',
'body.darkmode-vector2010 pre,',
'body.darkmode-vector2010 .mw-code {',
' background: #111 !important;',
' color: #e0e0e0 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 blockquote {',
' background: #222 !important;',
' border-left-color: #555 !important;',
'}',
'body.darkmode-vector2010 #toc,',
'body.darkmode-vector2010 .toc {',
' background: #222 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 #toc a,',
'body.darkmode-vector2010 .toc a { color: #6cb6ff !important; }',
'body.darkmode-vector2010 #p-personal a,',
'body.darkmode-vector2010 #p-navigation a,',
'body.darkmode-vector2010 #p-tb a,',
'body.darkmode-vector2010 #p-search a { color: #6cb6ff !important; }',
'body.darkmode-vector2010 #left-navigation,',
'body.darkmode-vector2010 #right-navigation {',
' background: #1a1a1a !important;',
'}',
'body.darkmode-vector2010 .vectorTabs,',
'body.darkmode-vector2010 .vectorMenu {',
' background: #2a2a2a !important;',
' background-image: none !important;',
'}',
'body.darkmode-vector2010 .vectorTabs li a,',
'body.darkmode-vector2010 .vectorMenu h3 span {',
' color: #6cb6ff !important;',
'}',
'body.darkmode-vector2010 .vectorTabs li.selected a {',
' color: #ffffff !important;',
' background: #1a1a1a !important;',
'}',
'body.darkmode-vector2010 #simpleSearch input {',
' background: #2a2a2a !important;',
' color: #d0d0d0 !important;',
' border-color: #555 !important;',
'}',
'body.darkmode-vector2010 .thumbinner,',
'body.darkmode-vector2010 .thumb {',
' background: #222 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .thumbcaption { color: #b0b0b0 !important; }',
'/* Осветление SVG/PNG с прозрачностью */',
'body.darkmode-vector2010 img.mw-invertable,',
'body.darkmode-vector2010 .mw-invertable img {',
' filter: invert(1) hue-rotate(180deg);',
'}',
'/* Инверсия формул Math */',
'body.darkmode-vector2010 img.mwe-math-fallback-image-inline,',
'body.darkmode-vector2010 img.mwe-math-fallback-image-display {',
' filter: invert(1) hue-rotate(180deg);',
'}',
'body.darkmode-vector2010 .mw-warning,',
'body.darkmode-vector2010 .errorbox,',
'body.darkmode-vector2010 .successbox,',
'body.darkmode-vector2010 .messagebox {',
' background: #2d2d2d !important;',
' color: #d0d0d0 !important;',
' border-color: #555 !important;',
'}',
'body.darkmode-vector2010 .catlinks {',
' background: #222 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 #footer {',
' background: #1a1a1a !important;',
' border-top-color: #444 !important;',
' color: #a0a0a0 !important;',
'}'
].join( '\n' );
mw.util.addCSS( css );
}
// Инициализация
$( function () {
injectStyles();
createButton();
// Применяем сохранённую тему без анимации при загрузке
if ( isEnabled() ) {
$( document.body ).addClass( CLASS_NAME );
}
updateButton( isEnabled() );
// Следим за изменением темы оформления
mw.hook( 'skin.change' ).add( function () {
if ( isEnabled() ) {
$( document.body ).addClass( CLASS_NAME );
}
} );
} );
}( mediaWiki, jQuery ) );