MediaWiki:Gadget-ViewerMode.js:修订间差异

读者模式切换 JS
 
Fix portlet ID for Vector 2022
第1行: 第1行:
/**
/**
  * ViewerMode gadget — toggles a "visitor view" for editors.
  * ViewerMode gadget — toggles a "visitor view" for editors.
  * Hides all editing UI so editors can see how the site looks to visitors.
  * Hides all editing UI so editors can preview the site as a regular visitor.
  */
  */
( function () {
( function () {
第13行: 第13行:
     var active = localStorage.getItem( STORAGE_KEY ) === '1';
     var active = localStorage.getItem( STORAGE_KEY ) === '1';


    // Apply class immediately to prevent flash of edit elements on load
     if ( active ) {
     if ( active ) {
         document.documentElement.classList.add( 'viewer-mode' );
         document.documentElement.classList.add( 'viewer-mode' );
第39行: 第40行:
             a.textContent = '⚙ 编辑者模式';
             a.textContent = '⚙ 编辑者模式';
             a.title = '切换回编辑者模式(当前:读者视图)';
             a.title = '切换回编辑者模式(当前:读者视图)';
            a.style.fontWeight = 'bold';
         } else {
         } else {
             a.textContent = '👁 读者模式';
             a.textContent = '👁 读者模式';
             a.title = '切换到读者模式,查看访客视图';
             a.title = '切换到读者模式,预览访客视图';
            a.style.fontWeight = '';
         }
         }
     }
     }


     mw.loader.using( [ 'mediawiki.util' ] ).then( function () {
     mw.loader.using( [ 'mediawiki.util' ] ).then( function () {
         var portletLink = mw.util.addPortletLink(
        // Vector 2022 uses p-vector-user-menu-overflow for extra user menu items
            'p-personal',
         var portlets = [ 'p-vector-user-menu-overflow', 'p-personal' ];
            '#',
        var portletLink = null;
            active ? '⚙ 编辑者模式' : '👁 读者模式',
 
            'pt-viewer-mode',
        for ( var i = 0; i < portlets.length; i++ ) {
            active ? '切换回编辑者模式(当前:读者视图)' : '切换到读者模式,查看访客视图',
            portletLink = mw.util.addPortletLink(
             null,
                portlets[ i ],
             '#pt-preferences'
                '#',
         );
                active ? '⚙ 编辑者模式' : '👁 读者模式',
                'pt-viewer-mode',
                active ? '切换回编辑者模式(当前:读者视图)' : '切换到读者模式,预览访客视图'
             );
            if ( portletLink ) {
                break;
             }
         }


         if ( portletLink ) {
         if ( portletLink ) {