MediaWiki:Gadget-DarkModeVector2010.js
Замечание: Возможно, после публикации вам придётся очистить кэш своего браузера, чтобы увидеть изменения.
- Firefox / Safari: Удерживая клавишу Shift, нажмите на панели инструментов Обновить либо нажмите Ctrl+F5 или Ctrl+R (⌘+R на Mac)
- Google Chrome: Нажмите Ctrl+Shift+R (⌘+Shift+R на Mac)
- Edge: Удерживая Ctrl, нажмите Обновить либо нажмите Ctrl+F5
- Opera: Нажмите Ctrl+F5.
/* Гаджет: Ночная тема для Vector 2010 */
( 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 = [
'/* ==== Свежие правки: поля выбора и ввода ==== */',
'body.darkmode-vector2010 select,',
'body.darkmode-vector2010 input[type="text"],',
'body.darkmode-vector2010 input[type="search"],',
'body.darkmode-vector2010 input[type="number"],',
'body.darkmode-vector2010 input[type="date"],',
'body.darkmode-vector2010 textarea,',
'body.darkmode-vector2010 .mw-ui-input,',
'body.darkmode-vector2010 .oo-ui-inputWidget-input {',
' background: #2a2a2a !important;',
' background-image: none !important;',
' color: #d0d0d0 !important;',
' border: 1px solid #555 !important;',
' border-radius: 3px !important;',
'}',
'body.darkmode-vector2010 select,',
'body.darkmode-vector2010 .oo-ui-dropdownWidget-handle,',
'body.darkmode-vector2010 .oo-ui-inputWidget-input {',
' -webkit-appearance: none !important;',
' -moz-appearance: none !important;',
' appearance: none !important;',
'}',
'/* Стрелочка у select */',
'body.darkmode-vector2010 select {',
' background-image: linear-gradient(45deg, transparent 50%, #6cb6ff 50%),',
' linear-gradient(135deg, #6cb6ff 50%, transparent 50%) !important;',
' background-position: calc(100% - 14px) center, calc(100% - 9px) center !important;',
' background-size: 5px 5px, 5px 5px !important;',
' background-repeat: no-repeat !important;',
' padding-right: 24px !important;',
'}',
'/* Опции внутри select */',
'body.darkmode-vector2010 select option,',
'body.darkmode-vector2010 select optgroup {',
' background: #2a2a2a !important;',
' color: #d0d0d0 !important;',
'}',
'body.darkmode-vector2010 select option:checked,',
'body.darkmode-vector2010 select option:hover {',
' background: #3a3a3a !important;',
' color: #ffffff !important;',
'}',
'/* Чекбоксы и радиокнопки */',
'body.darkmode-vector2010 input[type="checkbox"],',
'body.darkmode-vector2010 input[type="radio"] {',
' accent-color: #6cb6ff !important;',
' background: #2a2a2a !important;',
' border-color: #555 !important;',
'}',
'/* Кнопки в фильтрах */',
'body.darkmode-vector2010 button,',
'body.darkmode-vector2010 input[type="submit"],',
'body.darkmode-vector2010 input[type="button"],',
'body.darkmode-vector2010 .oo-ui-buttonElement-button,',
'body.darkmode-vector2010 .mw-ui-button {',
' background: #333 !important;',
' color: #d0d0d0 !important;',
' border: 1px solid #555 !important;',
'}',
'body.darkmode-vector2010 button:hover,',
'body.darkmode-vector2010 input[type="submit"]:hover,',
'body.darkmode-vector2010 .oo-ui-buttonElement-button:hover,',
'body.darkmode-vector2010 .mw-ui-button:hover {',
' background: #444 !important;',
' color: #ffffff !important;',
'}',
'/* Обёртки вокруг полей (Label, FieldLayout) */',
'body.darkmode-vector2010 .oo-ui-fieldLayout,',
'body.darkmode-vector2010 .oo-ui-labelElement-label,',
'body.darkmode-vector2010 label,',
'body.darkmode-vector2010 legend {',
' color: #d0d0d0 !important;',
'}',
'/* Выпадающие меню OOUI (свежие правки в новых версиях) */',
'body.darkmode-vector2010 .oo-ui-dropdownWidget,',
'body.darkmode-vector2010 .oo-ui-menuSelectWidget,',
'body.darkmode-vector2010 .oo-ui-optionWidget {',
' background: #2a2a2a !important;',
' color: #d0d0d0 !important;',
' border-color: #555 !important;',
'}',
'body.darkmode-vector2010 .oo-ui-optionWidget-selected,',
'body.darkmode-vector2010 .oo-ui-optionWidget-highlighted {',
' background: #3a3a3a !important;',
' color: #ffffff !important;',
'}',
'/* ==== Загрузка файла: вкладки Файл/История/Использование ==== */',
'body.darkmode-vector2010 #filetoc,',
'body.darkmode-vector2010 #filetoc ul,',
'body.darkmode-vector2010 .filehistory,',
'body.darkmode-vector2010 .filehistory ul,',
'body.darkmode-vector2010 #mw-imagepage-section-filehistory,',
'body.darkmode-vector2010 #mw-imagepage-section-globalusage,',
'body.darkmode-vector2010 #mw-imagepage-section-linkstoimage,',
'body.darkmode-vector2010 .mw-imagepage-section {',
' background: #222 !important;',
' background-image: none !important;',
' color: #d0d0d0 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 #filetoc a,',
'body.darkmode-vector2010 .filehistory a,',
'body.darkmode-vector2010 #mw-imagepage-section-filehistory a,',
'body.darkmode-vector2010 .mw-imagepage-section a {',
' color: #6cb6ff !important;',
'}',
'/* Современная разметка (новые версии MediaWiki) */',
'body.darkmode-vector2010 .mw-imagepage-content,',
'body.darkmode-vector2010 .mw-imagepage-content ul,',
'body.darkmode-vector2010 .mw-imagepage-content li,',
'body.darkmode-vector2010 .mw-imagepage-content table {',
' background: #222 !important;',
' color: #d0d0d0 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .mw-imagepage-content th,',
'body.darkmode-vector2010 .mw-imagepage-content td {',
' background: #1a1a1a !important;',
' color: #d0d0d0 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .mw-imagepage-content tr:hover {',
' background: #2a2a2a !important;',
'}',
'/* ==== Изображения: рамка, подпись, увеличение ==== */',
'body.darkmode-vector2010 .thumb,',
'body.darkmode-vector2010 .thumbinner,',
'body.darkmode-vector2010 figure[typeof~="mw:File/Thumb"],',
'body.darkmode-vector2010 figure[typeof~="mw:File/Frame"],',
'body.darkmode-vector2010 .mw-halign-none,',
'body.darkmode-vector2010 .mw-halign-left,',
'body.darkmode-vector2010 .mw-halign-right,',
'body.darkmode-vector2010 .mw-halign-center {',
' background: #222 !important;',
' border-color: #444 !important;',
' color: #d0d0d0 !important;',
'}',
'body.darkmode-vector2010 .thumbcaption,',
'body.darkmode-vector2010 figcaption,',
'body.darkmode-vector2010 .thumbcaption .magnify,',
'body.darkmode-vector2010 figure > figcaption {',
' background: #222 !important;',
' color: #b8b8b8 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .thumbcaption a,',
'body.darkmode-vector2010 figcaption a {',
' color: #6cb6ff !important;',
'}',
'/* Лупа «увеличить» */',
'body.darkmode-vector2010 .magnify a,',
'body.darkmode-vector2010 .magnify img {',
' filter: invert(1) hue-rotate(180deg);',
'}',
'/* Рамка вокруг самого изображения */',
'body.darkmode-vector2010 .thumbimage,',
'body.darkmode-vector2010 figure img {',
' border-color: #444 !important;',
' background: #111 !important;',
'}',
'/* Современная разметка <figure> */',
'body.darkmode-vector2010 figure[typeof~="mw:File"] {',
' background: #222 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 figure[typeof~="mw:File"] > figcaption {',
' background: #222 !important;',
' color: #b8b8b8 !important;',
'}',
'/* ==== Свежие правки: легенда ==== */',
'body.darkmode-vector2010 .mw-changeslist-legend,',
'body.darkmode-vector2010 .mw-specialpage-legend,',
'body.darkmode-vector2010 .mw-changeslist-legend-inner,',
'body.darkmode-vector2010 .rclistfrom,',
'body.darkmode-vector2010 #mw-indicator,',
'body.darkmode-vector2010 .mw-indicators {',
' background: #222 !important;',
' color: #d0d0d0 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .mw-changeslist-legend a,',
'body.darkmode-vector2010 .mw-specialpage-legend a {',
' color: #6cb6ff !important;',
'}',
'/* Плашка «Свежие правки за последние X дней» и фильтры */',
'body.darkmode-vector2010 .mw-specialpage-summary,',
'body.darkmode-vector2010 .mw-recentchanges-filters,',
'body.darkmode-vector2010 .rcoptions,',
'body.darkmode-vector2010 fieldset {',
' background: #222 !important;',
' color: #d0d0d0 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 legend {',
' color: #e0e0e0 !important;',
'}',
'/* Строки списка правок */',
'body.darkmode-vector2010 .mw-changeslist-line,',
'body.darkmode-vector2010 .mw-changeslist-line-inner,',
'body.darkmode-vector2010 .special li,',
'body.darkmode-vector2010 .mw-recentchanges-list li {',
' background: #1a1a1a !important;',
' border-color: #333 !important;',
'}',
'/* Подсветка «свежих» и «моих» правок */',
'body.darkmode-vector2010 .mw-changeslist-line-watched,',
'body.darkmode-vector2010 .mw-changeslist-line-not-watched {',
' background: #1a1a1a !important;',
'}',
'body.darkmode-vector2010 .mw-plusminus-pos { color: #7bd88f !important; }',
'body.darkmode-vector2010 .mw-plusminus-neg { color: #ff7b7b !important; }',
'body.darkmode-vector2010 .mw-plusminus-null { color: #b0b0b0 !important; }',
'/* ==== Ночная тема 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 #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 #left-navigation,',
'body.darkmode-vector2010 #right-navigation,',
'body.darkmode-vector2010 #p-views,',
'body.darkmode-vector2010 #p-namespaces,',
'body.darkmode-vector2010 #p-actions,',
'body.darkmode-vector2010 .vectorTabs,',
'body.darkmode-vector2010 .vectorMenu,',
'body.darkmode-vector2010 .vector-menu,',
'body.darkmode-vector2010 .mw-vector-tabs {',
' background: #1a1a1a !important;',
' background-image: none !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .vectorTabs ul,',
'body.darkmode-vector2010 .vector-menu-content,',
'body.darkmode-vector2010 .mw-vector-tabs ul {',
' background: #1a1a1a !important;',
' background-image: none !important;',
'}',
'body.darkmode-vector2010 .vectorTabs li,',
'body.darkmode-vector2010 .vectorMenu li {',
' background: #2a2a2a !important;',
' background-image: none !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .vectorTabs li a,',
'body.darkmode-vector2010 .vectorMenu h3 span,',
'body.darkmode-vector2010 .vectorMenu h3 a,',
'body.darkmode-vector2010 .mw-vector-tabs li a {',
' color: #6cb6ff !important;',
' background: transparent !important;',
' background-image: none !important;',
'}',
'body.darkmode-vector2010 .vectorTabs li a:hover,',
'body.darkmode-vector2010 .vectorMenu h3:hover span {',
' color: #ffffff !important;',
' background: #333 !important;',
'}',
'/* Активная вкладка (та, что сейчас открыта) */',
'body.darkmode-vector2010 .vectorTabs li.selected,',
'body.darkmode-vector2010 .vectorTabs li.selected a,',
'body.darkmode-vector2010 .vector-menu-tabs .selected a {',
' background: #1a1a1a !important;',
' background-image: none !important;',
' color: #ffffff !important;',
' border-bottom-color: #1a1a1a !important;',
'}',
'/* Иконки-«звёздочки» и стрелки меню */',
'body.darkmode-vector2010 .vectorTabs li.icon a,',
'body.darkmode-vector2010 .vectorMenu h3 span:after {',
' filter: invert(1) hue-rotate(180deg);',
'}',
'/* Выпадающие меню (Ещё, Действия) */',
'body.darkmode-vector2010 .vectorMenu .menu,',
'body.darkmode-vector2010 .vectorMenu .vector-menu-content-list {',
' background: #222 !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .vectorMenu .menu a {',
' color: #6cb6ff !important;',
'}',
'body.darkmode-vector2010 .vectorMenu .menu a:hover {',
' background: #333 !important;',
'}',
'body.darkmode-vector2010 #footer {',
' background: #1a1a1a !important;',
' border-top-color: #444 !important;',
' color: #a0a0a0 !important;',
'}',
'/* ==== Вкладки: универсальный блок ==== */',
'body.darkmode-vector2010 .mw-portlet,',
'body.darkmode-vector2010 .mw-portlet-body,',
'body.darkmode-vector2010 .mw-portlet-views,',
'body.darkmode-vector2010 .mw-portlet-namespaces,',
'body.darkmode-vector2010 .mw-portlet-actions,',
'body.darkmode-vector2010 .mw-portlet-cactions,',
'body.darkmode-vector2010 .vector-menu-tabs,',
'body.darkmode-vector2010 .vector-menu-content,',
'body.darkmode-vector2010 .vector-menu-content-list {',
' background: #1a1a1a !important;',
' background-image: none !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .mw-portlet h3,',
'body.darkmode-vector2010 .mw-portlet .mw-portlet-heading,',
'body.darkmode-vector2010 .vector-menu-heading {',
' background: #2a2a2a !important;',
' background-image: none !important;',
' color: #6cb6ff !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .mw-portlet li,',
'body.darkmode-vector2010 .vector-menu-tabs li,',
'body.darkmode-vector2010 .vector-menu-content-list li {',
' background: #2a2a2a !important;',
' background-image: none !important;',
' border-color: #444 !important;',
'}',
'body.darkmode-vector2010 .mw-portlet li a,',
'body.darkmode-vector2010 .vector-menu-tabs li a,',
'body.darkmode-vector2010 .vector-menu-content-list li a,',
'body.darkmode-vector2010 .mw-portlet a {',
' color: #6cb6ff !important;',
' background: transparent !important;',
' background-image: none !important;',
'}',
'body.darkmode-vector2010 .mw-portlet li a:hover,',
'body.darkmode-vector2010 .vector-menu-tabs li a:hover {',
' background: #333 !important;',
' color: #ffffff !important;',
'}',
'/* Активная вкладка */',
'body.darkmode-vector2010 .mw-portlet li.selected,',
'body.darkmode-vector2010 .mw-portlet li.selected a,',
'body.darkmode-vector2010 .vector-menu-tabs li.selected,',
'body.darkmode-vector2010 .vector-menu-tabs li.selected a {',
' background: #1a1a1a !important;',
' background-image: none !important;',
' color: #ffffff !important;',
' border-color: #1a1a1a !important;',
'}',
'/* Ссылки внутри вкладок, которые ещё не созданы */',
'body.darkmode-vector2010 .mw-portlet li a.new,',
'body.darkmode-vector2010 .vector-menu-tabs li a.new {',
' color: #ff7b7b !important;',
'}',
'/* Обёртки вокруг вкладок */',
'body.darkmode-vector2010 #p-namespaces,',
'body.darkmode-vector2010 #p-views,',
'body.darkmode-vector2010 #p-cactions,',
'body.darkmode-vector2010 #p-actions {',
' background: #1a1a1a !important;',
' background-image: none !important;',
'}',
'body.darkmode-vector2010 #p-namespaces ul,',
'body.darkmode-vector2010 #p-views ul,',
'body.darkmode-vector2010 #p-cactions ul,',
'body.darkmode-vector2010 #p-actions ul {',
' background: #1a1a1a !important;',
' background-image: none !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 ) );