MediaWiki:Gadget-ViewerMode.js:修订间差异
LocalAdmin(留言 | 贡献) 读者模式切换 JS |
LocalAdmin(留言 | 贡献) 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 | * 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 | ||
var portlets = [ 'p-vector-user-menu-overflow', 'p-personal' ]; | |||
var portletLink = null; | |||
for ( var i = 0; i < portlets.length; i++ ) { | |||
portletLink = mw.util.addPortletLink( | |||
portlets[ i ], | |||
'#', | |||
active ? '⚙ 编辑者模式' : '👁 读者模式', | |||
'pt-viewer-mode', | |||
active ? '切换回编辑者模式(当前:读者视图)' : '切换到读者模式,预览访客视图' | |||
); | |||
if ( portletLink ) { | |||
break; | |||
} | |||
} | |||
if ( portletLink ) { | if ( portletLink ) { | ||