MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary Tag: Reverted |
||
| Line 107: | Line 107: | ||
} | } | ||
} | } | ||
}() ); | |||
/* ════════════════════════════════════════════════ | |||
Grantha — Site chrome (hide wiki UI, inject top bar) | |||
Edit at: yourdomain.com/wiki/MediaWiki:Common.js | |||
════════════════════════════════════════════════ */ | |||
( function () { | |||
'use strict'; | |||
/* Only run on NS_MAIN pages, skip Special pages */ | |||
if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 ) return; | |||
/* ── 1. Inject hide-chrome CSS immediately ── */ | |||
var css = [ | |||
/* Sidebar */ | |||
'#mw-navigation,#mw-panel,.mw-sidebar,.vector-sidebar-container,', | |||
'.vector-sidebar-container-no-toc,#p-logo,.mw-portlet-logo{display:none!important}', | |||
/* Page action tabs */ | |||
'#p-views,#p-cactions,.mw-portlet-views,.vector-page-tools,', | |||
'.vector-page-tools-landmark,#ca-edit,#ca-ve-edit,#ca-history,', | |||
'#ca-talk,#ca-nstab-main,.page-actions-menu,', | |||
'.vector-page-titlebar-toc{display:none!important}', | |||
/* User/personal tools */ | |||
'#p-personal,.vector-user-links,.vector-user-menu,', | |||
'#pt-createaccount,#pt-login,#pt-logout,', | |||
'.mw-portlet-personal,.vector-client-prefs-landmark{display:none!important}', | |||
/* Header search */ | |||
'#p-search,.vector-search-box,.mw-header .cdx-search-input{display:none!important}', | |||
/* Top header strip */ | |||
'.vector-header-start,.vector-header-end,.mw-header{display:none!important}', | |||
/* Footer */ | |||
'#footer,.mw-footer,.vector-footer,.page-footer{display:none!important}', | |||
/* Misc */ | |||
'#siteNotice,#localNotice,.usermessage,#catlinks,.catlinks,', | |||
'.printfooter,.mw-indicators{display:none!important}', | |||
/* Remove sidebar margin, full-width content */ | |||
'#mw-content-text,#content,.mw-body,.mw-body-content,', | |||
'.vector-body,#bodyContent{margin-left:0!important;padding-left:0!important}', | |||
'#content,#mw-content-container,.mw-page-container,', | |||
'.vector-page-container,.mw-body{max-width:100%!important;padding:0!important;margin:0!important}', | |||
'#mw-content-text,#bodyContent{margin-top:0!important}', | |||
/* Top bar */ | |||
'#grantha-topbar{', | |||
' position:fixed;top:0;left:0;right:0;z-index:10000;height:50px;', | |||
' background:#1a2e40;display:flex;align-items:center;', | |||
' justify-content:space-between;padding:0 24px;', | |||
' box-shadow:0 1px 0 rgba(255,255,255,0.06);', | |||
' font-family:system-ui,sans-serif;', | |||
'}', | |||
'#grantha-topbar .gt-brand{', | |||
' display:flex;align-items:center;gap:10px;text-decoration:none;', | |||
'}', | |||
'#grantha-topbar .gt-favicon{', | |||
' width:22px;height:22px;border-radius:4px;object-fit:contain;', | |||
' filter:brightness(0) invert(1);opacity:.9;', | |||
'}', | |||
'#grantha-topbar .gt-name{', | |||
' color:#fff;font-size:15px;font-weight:700;letter-spacing:-.01em;', | |||
'}', | |||
'#grantha-topbar .gt-right{display:flex;align-items:center;gap:10px;}', | |||
'#grantha-topbar .gt-btn{', | |||
' font-size:12.5px;padding:6px 16px;border-radius:20px;', | |||
' border:1.5px solid rgba(255,255,255,0.3);', | |||
' background:rgba(255,255,255,0.08);color:#fff;', | |||
' cursor:pointer;font-family:inherit;font-weight:600;', | |||
' transition:background .15s,border-color .15s;white-space:nowrap;', | |||
'}', | |||
'#grantha-topbar .gt-btn:hover{', | |||
' background:rgba(255,255,255,0.18);border-color:rgba(255,255,255,0.55);', | |||
'}', | |||
'body{padding-top:50px!important}', | |||
'@media print{#grantha-topbar{display:none!important}body{padding-top:0!important}}' | |||
].join( '' ); | |||
if ( !document.getElementById( 'grantha-chrome-css' ) ) { | |||
var style = document.createElement( 'style' ); | |||
style.id = 'grantha-chrome-css'; | |||
style.textContent = css; | |||
( document.head || document.documentElement ).appendChild( style ); | |||
} | |||
/* ── 2. Build the top bar ── */ | |||
mw.hook( 'wikipage.content' ).add( function () { | |||
if ( document.getElementById( 'grantha-topbar' ) ) return; | |||
/* Hide topbar on edit pages — the editor toolbar takes over */ | |||
var action = mw.config.get( 'wgAction' ); | |||
if ( action === 'edit' || action === 'submit' ) return; | |||
var mainPage = ( mw.config.get( 'wgArticlePath' ) || '/wiki/$1' ) | |||
.replace( '$1', encodeURIComponent( | |||
mw.config.get( 'wgMainPageTitle' ) || 'Main_Page' | |||
) ); | |||
var bar = document.createElement( 'div' ); | |||
bar.id = 'grantha-topbar'; | |||
bar.innerHTML = | |||
'<a class="gt-brand" href="' + mainPage + '">' + | |||
' <img class="gt-favicon" src="/favicon.ico" alt="" />' + | |||
' <span class="gt-name">Grantha</span>' + | |||
'</a>' + | |||
'<div class="gt-right">' + | |||
' <button class="gt-btn" id="gt-newdoc">✚ New Document</button>' + | |||
'</div>'; | |||
document.body.prepend( bar ); | |||
document.getElementById( 'gt-newdoc' ).addEventListener( 'click', function () { | |||
/* NewPageDialog is provided by the Editor extension */ | |||
if ( window.NewPageDialog ) NewPageDialog.show(); | |||
} ); | |||
} ); | |||
}() ); | }() ); | ||