MediaWiki:Common.js
From Luminys WIKI
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
// http://mediawiki.i.donnie.fun:8085/MediaWiki:Common.js /* Any JavaScript here will be loaded for all users on every page load. */ let getCookie = function(name) { let cookie = {}; document.cookie.split(';').forEach(function(el) { let split = el.split('='); cookie[split[0].trim()] = split.slice(1).join("="); }) return cookie[name];https://wiki.luminyscorp.com/index.php?title=MediaWiki:Common.js&action=edit } let Run = function(){ let title = $("#firstHeading").text() if(title == "Main Page") title = "Luminys Knowledge Base (Wiki)" if(title.indexOf('/') >= 0) title = title.replace("/", "<br/>") $("#mw-header-container").prepend("<div id='mw-header-lm-title'><div>"+title+"</div></div>") $("#mw-header-container").prepend(` <div style="background:white;position: absolute;top: 0;width: 100%;"> <div style="display:flex; flex-direction:row; align-content: center; align-items:baseline;align-self: center; margin: 0 auto; width: 1280px"> <!--<div style="width:14em;"></div>--> <a href="/" style="height:66px;margin-right:10px"><img src="https://blog.luminyscorp.com/content/images/2024/07/luminys-logo-1.png" style="height:26px;margin:20px 20px 20px 0;" alt="Luminys Logo"> </a> <div class=""> <div class="hidden md:block ml-6 font-medium w-full lg:flex lg:w-auto "> <ul id="lm-header"> <li><a href='/Main_Page'>Home</a></li> <li><a href="/Main_Page#How-to_Instructions">Instructions</a></li> <li><a href="/Main_Page#Data_Sheets_&_Downloads">Product Support</a></li> <li><a href="/Main_Page#How-to_Videos">Videos</a></li> </ul> </div> </div> </div> </div> `); if(window.mediaWiki && window.mediaWiki.user && window.mediaWiki.user.getName){ //let logined = getCookie('my_wikiUserID'); let logined = !!window.mediaWiki.user.getName() if(logined){ $("#mw-page-header-links ").show(); $("#mw-site-navigation ").show(); $("#mw-related-navigation").show(); } } if($(".lm-banner img").length > 0){ $("#mw-header-container").css("background", "url("+ $(".lm-banner img").attr('src') +")"). css("background-size", "cover").css('background-repeat', 'no-repeat'). css('background-position','top 66px right 0') } } $(function () { Run(); }); /* Inserts Back to Top button toward the bottom right of the pages on each page */ $(document).ready(function () { // Define the wikitext to render var backToTopWikitext = '[[File:Back_to_Top.png|60px|link=#top|Back to Top]]'; // Use the MediaWiki API to parse the wikitext into HTML new mw.Api().post({ action: 'parse', text: backToTopWikitext, contentmodel: 'wikitext', format: 'json' }).done(function (data) { // Extract the rendered HTML var renderedHTML = data.parse.text['*']; // Append the rendered HTML to the end of the content area $('#mw-content-text').append('<div style="float: right;">' + renderedHTML + '</div>'); }).fail(function () { console.error('Failed to parse wikitext'); }); }); document.addEventListener('scroll', function () { const searchBar = document.querySelector('#p-search'); const originalTop = 340; // Original position from the top of the page if (window.scrollY > originalTop) { searchBar.style.position = 'fixed'; searchBar.style.top = '0'; searchBar.style.width = '100%'; searchBar.style.zIndex = '999'; searchBar.style.backgroundColor = '#f5f5f5'; searchBar.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.1)'; } else { searchBar.style.position = 'absolute'; searchBar.style.top = originalTop + 'px'; searchBar.style.width = '100%'; searchBar.style.boxShadow = 'none'; } });