跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
MediaWiki帮助
槌基百科
搜索
搜索
外观
登录
个人工具
登录
查看“︁MediaWiki:Gadget-ThemeSwitch.js”︁的源代码
系统消息
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
常规
链入页面
相关更改
特殊页面
页面信息
外观
移至侧栏
隐藏
←
MediaWiki:Gadget-ThemeSwitch.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于这些用户组的用户执行:
Superadmin
、editor
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
/** * ThemeSwitch gadget — floating theme picker for all visitors. */ ( function () { 'use strict'; var STORAGE_KEY = 'mw-theme'; var THEMES = [ { id: '', label: 'Classic', swatch: '#f8f9fa', text: '#333' }, { id: 'slate', label: 'Slate', swatch: '#4a7fa5', text: '#fff' }, { id: 'dark', label: 'Dark', swatch: '#1a1d27', text: '#90cdf4' }, { id: 'warm', label: 'Warm', swatch: '#c8922a', text: '#fff' } ]; var current = localStorage.getItem( STORAGE_KEY ) || ''; function applyTheme( id ) { THEMES.forEach( function ( t ) { document.documentElement.classList.remove( 'theme-' + t.id ); } ); if ( id ) { document.documentElement.classList.add( 'theme-' + id ); } current = id; localStorage.setItem( STORAGE_KEY, id ); updateSwatch(); } // Apply stored theme immediately (before DOM ready, to avoid flash) applyTheme( current ); function updateSwatch() { var btn = document.getElementById( 'theme-toggle-btn' ); if ( !btn ) { return; } var theme = THEMES.find( function(t){ return t.id === current; } ) || THEMES[0]; btn.style.background = theme.swatch; btn.style.color = theme.text; btn.title = 'Theme: ' + theme.label; } $( function () { // Build the floating picker var wrapper = document.createElement( 'div' ); wrapper.id = 'theme-picker'; var btn = document.createElement( 'button' ); btn.id = 'theme-toggle-btn'; btn.innerHTML = '◐'; // half circle / palette symbol btn.setAttribute( 'aria-label', 'Switch theme' ); wrapper.appendChild( btn ); var menu = document.createElement( 'div' ); menu.id = 'theme-picker-menu'; menu.setAttribute( 'aria-hidden', 'true' ); var label = document.createElement( 'div' ); label.className = 'theme-picker-heading'; label.textContent = 'Theme'; menu.appendChild( label ); THEMES.forEach( function ( theme ) { var opt = document.createElement( 'button' ); opt.className = 'theme-option'; opt.dataset.theme = theme.id; var swatch = document.createElement( 'span' ); swatch.className = 'theme-swatch'; swatch.style.background = theme.swatch; swatch.style.border = theme.id === '' ? '1px solid #ccc' : 'none'; var name = document.createElement( 'span' ); name.textContent = theme.label; opt.appendChild( swatch ); opt.appendChild( name ); opt.addEventListener( 'click', function () { applyTheme( theme.id ); menu.classList.remove( 'open' ); menu.setAttribute( 'aria-hidden', 'true' ); } ); menu.appendChild( opt ); } ); wrapper.appendChild( menu ); document.body.appendChild( wrapper ); // Toggle open/close btn.addEventListener( 'click', function ( e ) { e.stopPropagation(); var isOpen = menu.classList.toggle( 'open' ); menu.setAttribute( 'aria-hidden', String( !isOpen ) ); } ); document.addEventListener( 'click', function () { menu.classList.remove( 'open' ); menu.setAttribute( 'aria-hidden', 'true' ); } ); updateSwatch(); } ); }() );
返回
MediaWiki:Gadget-ThemeSwitch.js
。