|
|
| Line 1: |
Line 1: |
| /** | | /* OSRS Custom JS Framework */ |
| * Winds of Valen Wiki — Common JS
| |
| */
| |
|
| |
|
| /* 1. Force light color scheme immediately (before paint) */ | | // 1. Asynchronous Calculator Loader |
| (function () { | | $(function() { |
| document.documentElement.style.colorScheme = 'light'; | | if ($('.jcConfig').length > 0) { |
| }());
| | // Asynchronously pull in calculator scripts |
| | | mw.loader.getScript('/resources/assets/calc.js').then(function() { |
| /* 2. Fix Vector 2022 sidebar: switch pinned-disabled → pinned-enabled */ | | mw.loader.load('/resources/assets/calc.css', 'text/css'); |
| (function () {
| | console.log("OSRS calculators loaded."); |
| var h = document.documentElement;
| | }); |
| h.className = h.className
| |
| .replace('vector-feature-main-menu-pinned-disabled', 'vector-feature-main-menu-pinned-enabled');
| |
| }());
| |
| | |
| /* 3. Load Cinzel + Inter fonts */
| |
| (function () { | |
| if (!document.getElementById('wov-fonts')) {
| |
| var l = document.createElement('link');
| |
| l.id = 'wov-fonts';
| |
| l.rel = 'stylesheet';
| |
| l.href = 'https://fonts.googleapis.com/css2?family=Cinzel:wght@700&family=PT+Serif:ital,wght@0,400;0,700;1,400&family=Inter:wght@400;600&display=swap';
| |
| document.head.appendChild(l); | |
| } | | } |
| }()); | | }); |
| | |
| document.addEventListener('DOMContentLoaded', function () {
| |
|
| |
|
| /* 4. Move main menu from hamburger dropdown into pinned sidebar slot */
| | // 2. Reader Mode Toggle |
| var pinned = document.getElementById('vector-main-menu-pinned-container'); | | $(function() { |
| var unpinned = document.getElementById('vector-main-menu-unpinned-container'); | | var isReaderMode = localStorage.getItem('osrs-reader-mode') === 'true'; |
| if (pinned && unpinned && unpinned.children.length > 0 && pinned.children.length === 0) {
| | |
| while (unpinned.firstChild) { | | function toggleReaderMode() { |
| pinned.appendChild(unpinned.firstChild);
| | isReaderMode = !isReaderMode; |
| }
| | localStorage.setItem('osrs-reader-mode', isReaderMode); |
| | $('body').toggleClass('reader-mode-active', isReaderMode); |
| } | | } |
| | | |
| /* 5. Hide hamburger button since sidebar is now always visible */
| | if (isReaderMode) { |
| var ham = document.getElementById('vector-main-menu-dropdown');
| | $('body').addClass('reader-mode-active'); |
| if (ham) ham.style.display = 'none';
| |
| | |
| /* 6. Inject Logo banner + Discord button at top of sidebar */
| |
| var sidebarEl = pinned || document.getElementById('vector-main-menu'); | |
| if (sidebarEl) { | |
| var logoImg = document.querySelector('#p-logo img, #p-logo .mw-logo-icon'); | |
| var logoSrc = logoImg ? logoImg.src : '';
| |
| | |
| /* Logo Banner */
| |
| var logoDiv = document.createElement('div');
| |
| logoDiv.className = 'wov-sidebar-logo';
| |
| logoDiv.innerHTML =
| |
| '<a href="/wiki/Main_Page">' +
| |
| (logoSrc ? '<img src="' + logoSrc + '" alt="Winds of Valen Wiki" />' : '') +
| |
| '<div class="wov-sidebar-logo-title">Winds of Valen</div>' +
| |
| '<div class="wov-sidebar-logo-sub">Wiki</div>' +
| |
| '</a>';
| |
| sidebarEl.insertBefore(logoDiv, sidebarEl.firstChild);
| |
| | |
| /* Simple HTML Discord Button */
| |
| var discordDiv = document.createElement('div');
| |
| discordDiv.style.padding = "10px";
| |
| discordDiv.innerHTML = '<a href="https://discord.gg/xxzDqg9xWc" class="wov-discord-btn-link" target="_blank" rel="noopener">Chat on Discord</a>';
| |
| sidebarEl.insertBefore(discordDiv, sidebarEl.children[1]);
| |
| } | | } |
| | | |
| /* 7. Hide "Main Page" h1 on the Main Page only */ | | // Insert toggle button into personal nav |
| if (mw && mw.config && mw.config.get('wgPageName') === 'Main_Page') { | | var btn = $('<li><a href="#" id="pt-reader-mode">Toggle Reader Mode</a></li>'); |
| var h1 = document.getElementById('firstHeading');
| | btn.on('click', function(e) { |
| if (h1) h1.style.display = 'none';
| | e.preventDefault(); |
| var mh = document.querySelector('.mw-first-heading');
| | toggleReaderMode(); |
| if (mh) mh.style.display = 'none';
| |
| }
| |
| | |
| /* 8. Make .wov-popular-btn spans behave as full-block links */ | |
| document.querySelectorAll('.wov-popular-grid a').forEach(function (a) {
| |
| a.style.display = 'block'; | |
| a.style.textDecoration = 'none';
| |
| var span = a.querySelector('.wov-popular-btn');
| |
| if (span) { | |
| span.style.display = 'block';
| |
| }
| |
| }); | | }); |
| | | $('#p-personal ul').prepend(btn); |
| }); | | }); |