MediaWiki:Common.js
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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
mw.loader.using('mediawiki.util').then(function () {
console.log("Common.js script is running...");
// Custom navbar
if (!document.getElementById('custom-navbar')) {
console.log("Injecting custom navbar...");
var navbar = document.createElement('div');
navbar.id = 'custom-navbar';
navbar.className = 'custom-navbar';
navbar.innerHTML = `
<div class="navbar-logo">
<a href="https://datagoats.org">
<img src="https://cdn.prod.website-files.com/67c1f80e330217623037cf74/67d856616b0626b8d2786449_GOATs%20Site%20Logo%20Short.png"
alt="Site Logo"/>
</a>
</div>
<div class="navbar-links">
<a href="https://datagoats.org/" style="color:white; margin-right:15px;">Home</a>
<a href="https://datagoats.org/blog" style="color:white; margin-right:15px;">Blog</a>
<a href="https://community.datagoats.org" style="color:white; margin-right:15px;">Community</a>
<a href="https://wiki.datagoats.org" style="color:white;">Wiki</a>
</div>
`;
document.body.prepend(navbar);
}
// Inject "Create page" link when search content loads
mw.hook('wikipage.content').add(function () {
console.log("wikipage.content triggered");
const msgBox = document.querySelector('.mw-search-nonefound');
if (!msgBox) {
console.log(".mw-search-nonefound not found in document.");
return;
}
// Remove any existing link (whether visible or ghosted)
const oldLink = msgBox.parentNode.querySelector('.mw-search-createlink');
if (oldLink) {
oldLink.remove();
console.log("Removed existing stale create link.");
}
const params = new URLSearchParams(window.location.search);
const query = params.get('search');
if (!query) {
console.log("No 'search' param in URL.");
return;
}
const normalizedTitle = query.charAt(0).toUpperCase() + query.slice(1);
console.log("Injecting create link for search: " + normalizedTitle);
const encodedQuery = encodeURIComponent(normalizedTitle);
const link = document.createElement('a');
link.href = '/index.php?title=' + encodedQuery + '&action=edit';
link.textContent = 'Create the page "' + query + '"';
link.className = 'mw-search-createlink';
link.style.display = 'block';
link.style.marginTop = '1em';
link.style.fontWeight = 'bold';
link.style.color = '#36c';
msgBox.parentNode.appendChild(link);
console.log("Create page link injected.");
});
});
$(document).ready(function () {
// Only show on normal content pages (skip special pages)
if (mw.config.get('wgNamespaceNumber') >= 0) {
const button = document.createElement('a');
button.href = '#top';
button.textContent = '↑ Back to Top';
button.id = 'back-to-top';
document.body.appendChild(button);
}
});
$(document).ready(function () {
const toc = document.getElementById('toc');
if (toc && mw.config.get('skin') === 'minerva') {
const toggle = document.createElement('div');
toggle.style.cursor = 'pointer';
toggle.style.fontWeight = 'bold';
toggle.style.marginBottom = '0.5em';
toc.parentNode.insertBefore(toggle, toc);
toggle.addEventListener('click', function () {
toc.style.display = (toc.style.display === 'none') ? 'block' : 'none';
});
// Optional: start hidden
toc.style.display = 'none';
}
});
<!-- Google tag (gtag.js) -->
var gtagScript = document.createElement('script');
console.log("gtag.js running!");
gtagScript.setAttribute('async', '');
gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=G-CV608CG538';
document.head.appendChild(gtagScript);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-CV608CG538');