<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans">
	<id>https://chuihub.com/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AGadget-ThemeSwitch.js</id>
	<title>MediaWiki:Gadget-ThemeSwitch.js - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://chuihub.com/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AGadget-ThemeSwitch.js"/>
	<link rel="alternate" type="text/html" href="https://chuihub.com/index.php?title=MediaWiki:Gadget-ThemeSwitch.js&amp;action=history"/>
	<updated>2026-04-28T03:34:39Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://chuihub.com/index.php?title=MediaWiki:Gadget-ThemeSwitch.js&amp;diff=374&amp;oldid=prev</id>
		<title>LocalAdmin：​Theme switcher gadget JS</title>
		<link rel="alternate" type="text/html" href="https://chuihub.com/index.php?title=MediaWiki:Gadget-ThemeSwitch.js&amp;diff=374&amp;oldid=prev"/>
		<updated>2026-03-12T11:00:41Z</updated>

		<summary type="html">&lt;p&gt;Theme switcher gadget JS&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;/**&lt;br /&gt;
 * ThemeSwitch gadget — floating theme picker for all visitors.&lt;br /&gt;
 */&lt;br /&gt;
( function () {&lt;br /&gt;
    &amp;#039;use strict&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
    var STORAGE_KEY = &amp;#039;mw-theme&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
    var THEMES = [&lt;br /&gt;
        { id: &amp;#039;&amp;#039;,      label: &amp;#039;Classic&amp;#039;, swatch: &amp;#039;#f8f9fa&amp;#039;, text: &amp;#039;#333&amp;#039; },&lt;br /&gt;
        { id: &amp;#039;slate&amp;#039;, label: &amp;#039;Slate&amp;#039;,   swatch: &amp;#039;#4a7fa5&amp;#039;, text: &amp;#039;#fff&amp;#039; },&lt;br /&gt;
        { id: &amp;#039;dark&amp;#039;,  label: &amp;#039;Dark&amp;#039;,    swatch: &amp;#039;#1a1d27&amp;#039;, text: &amp;#039;#90cdf4&amp;#039; },&lt;br /&gt;
        { id: &amp;#039;warm&amp;#039;,  label: &amp;#039;Warm&amp;#039;,    swatch: &amp;#039;#c8922a&amp;#039;, text: &amp;#039;#fff&amp;#039; }&lt;br /&gt;
    ];&lt;br /&gt;
&lt;br /&gt;
    var current = localStorage.getItem( STORAGE_KEY ) || &amp;#039;&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
    function applyTheme( id ) {&lt;br /&gt;
        THEMES.forEach( function ( t ) {&lt;br /&gt;
            document.documentElement.classList.remove( &amp;#039;theme-&amp;#039; + t.id );&lt;br /&gt;
        } );&lt;br /&gt;
        if ( id ) {&lt;br /&gt;
            document.documentElement.classList.add( &amp;#039;theme-&amp;#039; + id );&lt;br /&gt;
        }&lt;br /&gt;
        current = id;&lt;br /&gt;
        localStorage.setItem( STORAGE_KEY, id );&lt;br /&gt;
        updateSwatch();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Apply stored theme immediately (before DOM ready, to avoid flash)&lt;br /&gt;
    applyTheme( current );&lt;br /&gt;
&lt;br /&gt;
    function updateSwatch() {&lt;br /&gt;
        var btn = document.getElementById( &amp;#039;theme-toggle-btn&amp;#039; );&lt;br /&gt;
        if ( !btn ) { return; }&lt;br /&gt;
        var theme = THEMES.find( function(t){ return t.id === current; } ) || THEMES[0];&lt;br /&gt;
        btn.style.background = theme.swatch;&lt;br /&gt;
        btn.style.color      = theme.text;&lt;br /&gt;
        btn.title = &amp;#039;Theme: &amp;#039; + theme.label;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $( function () {&lt;br /&gt;
        // Build the floating picker&lt;br /&gt;
        var wrapper = document.createElement( &amp;#039;div&amp;#039; );&lt;br /&gt;
        wrapper.id = &amp;#039;theme-picker&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
        var btn = document.createElement( &amp;#039;button&amp;#039; );&lt;br /&gt;
        btn.id = &amp;#039;theme-toggle-btn&amp;#039;;&lt;br /&gt;
        btn.innerHTML = &amp;#039;&amp;amp;#9680;&amp;#039;; // half circle / palette symbol&lt;br /&gt;
        btn.setAttribute( &amp;#039;aria-label&amp;#039;, &amp;#039;Switch theme&amp;#039; );&lt;br /&gt;
        wrapper.appendChild( btn );&lt;br /&gt;
&lt;br /&gt;
        var menu = document.createElement( &amp;#039;div&amp;#039; );&lt;br /&gt;
        menu.id = &amp;#039;theme-picker-menu&amp;#039;;&lt;br /&gt;
        menu.setAttribute( &amp;#039;aria-hidden&amp;#039;, &amp;#039;true&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
        var label = document.createElement( &amp;#039;div&amp;#039; );&lt;br /&gt;
        label.className = &amp;#039;theme-picker-heading&amp;#039;;&lt;br /&gt;
        label.textContent = &amp;#039;Theme&amp;#039;;&lt;br /&gt;
        menu.appendChild( label );&lt;br /&gt;
&lt;br /&gt;
        THEMES.forEach( function ( theme ) {&lt;br /&gt;
            var opt = document.createElement( &amp;#039;button&amp;#039; );&lt;br /&gt;
            opt.className  = &amp;#039;theme-option&amp;#039;;&lt;br /&gt;
            opt.dataset.theme = theme.id;&lt;br /&gt;
&lt;br /&gt;
            var swatch = document.createElement( &amp;#039;span&amp;#039; );&lt;br /&gt;
            swatch.className = &amp;#039;theme-swatch&amp;#039;;&lt;br /&gt;
            swatch.style.background = theme.swatch;&lt;br /&gt;
            swatch.style.border = theme.id === &amp;#039;&amp;#039; ? &amp;#039;1px solid #ccc&amp;#039; : &amp;#039;none&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
            var name = document.createElement( &amp;#039;span&amp;#039; );&lt;br /&gt;
            name.textContent = theme.label;&lt;br /&gt;
&lt;br /&gt;
            opt.appendChild( swatch );&lt;br /&gt;
            opt.appendChild( name );&lt;br /&gt;
&lt;br /&gt;
            opt.addEventListener( &amp;#039;click&amp;#039;, function () {&lt;br /&gt;
                applyTheme( theme.id );&lt;br /&gt;
                menu.classList.remove( &amp;#039;open&amp;#039; );&lt;br /&gt;
                menu.setAttribute( &amp;#039;aria-hidden&amp;#039;, &amp;#039;true&amp;#039; );&lt;br /&gt;
            } );&lt;br /&gt;
&lt;br /&gt;
            menu.appendChild( opt );&lt;br /&gt;
        } );&lt;br /&gt;
&lt;br /&gt;
        wrapper.appendChild( menu );&lt;br /&gt;
        document.body.appendChild( wrapper );&lt;br /&gt;
&lt;br /&gt;
        // Toggle open/close&lt;br /&gt;
        btn.addEventListener( &amp;#039;click&amp;#039;, function ( e ) {&lt;br /&gt;
            e.stopPropagation();&lt;br /&gt;
            var isOpen = menu.classList.toggle( &amp;#039;open&amp;#039; );&lt;br /&gt;
            menu.setAttribute( &amp;#039;aria-hidden&amp;#039;, String( !isOpen ) );&lt;br /&gt;
        } );&lt;br /&gt;
&lt;br /&gt;
        document.addEventListener( &amp;#039;click&amp;#039;, function () {&lt;br /&gt;
            menu.classList.remove( &amp;#039;open&amp;#039; );&lt;br /&gt;
            menu.setAttribute( &amp;#039;aria-hidden&amp;#039;, &amp;#039;true&amp;#039; );&lt;br /&gt;
        } );&lt;br /&gt;
&lt;br /&gt;
        updateSwatch();&lt;br /&gt;
    } );&lt;br /&gt;
}() );&lt;/div&gt;</summary>
		<author><name>LocalAdmin</name></author>
	</entry>
</feed>