Tip of the Day
Make sure you equip your items to get their effects, most don't work from inventory alone.
MediaWiki:Gadget-TranslatedTabTitle.js: Difference between revisions
From Walkscape Walkthrough
Created page with "→* * Gadget: TranslatedTabTitle * Updates the browser tab title to match the translated page title.: (function () { var SITE_SUFFIX = ' – Walkscape Walkthrough'; function computeTitle() { var $h = $('#firstHeading, .firstHeading, .mw-first-heading, .mw-page-title-main').first(); var t = $h.text().trim(); if (!t) return; // Optional: show language tag if on /lang subpage var m = mw.config.get('wgPageName').match(/\/([a-z0-9\-]+)$/i);..." |
mNo edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
/** | /** | ||
* Gadget: TranslatedTabTitle | * Gadget: TranslatedTabTitle | ||
* Updates the browser tab title to match the translated | * Updates the browser tab title to match the visible page heading. | ||
* Works on all namespaces and translated pages. | |||
*/ | */ | ||
(function () { | (function () { | ||
var SITE_SUFFIX = ' | var SITE_SUFFIX = '- The Walkscape Wiki'; | ||
function computeTitle() { | function computeTitle() { | ||
| Line 11: | Line 12: | ||
if (!t) return; | if (!t) return; | ||
var current = document.title; | |||
var | var base = t; | ||
var | |||
if (!current.startsWith(base)) { | if (!current.startsWith(base)) { | ||
document.title = base + SITE_SUFFIX; | document.title = base + SITE_SUFFIX; | ||
| Line 24: | Line 22: | ||
} | } | ||
// Run when the | // Run when the DOM is ready | ||
$(computeTitle); | $(computeTitle); | ||
// Re-run when MediaWiki reloads content dynamically | |||
mw.hook('wikipage.content').add(computeTitle); | mw.hook('wikipage.content').add(computeTitle); | ||
// | // Also observe heading changes | ||
var h = document.getElementById('firstHeading'); | var h = document.getElementById('firstHeading'); | ||
if (h && window.MutationObserver) { | if (h && window.MutationObserver) { | ||
Latest revision as of 00:48, 28 November 2025
/**
* Gadget: TranslatedTabTitle
* Updates the browser tab title to match the visible page heading.
* Works on all namespaces and translated pages.
*/
(function () {
var SITE_SUFFIX = '- The Walkscape Wiki';
function computeTitle() {
var $h = $('#firstHeading, .firstHeading, .mw-first-heading, .mw-page-title-main').first();
var t = $h.text().trim();
if (!t) return;
var current = document.title;
var base = t;
if (!current.startsWith(base)) {
document.title = base + SITE_SUFFIX;
} else if (!current.endsWith(SITE_SUFFIX)) {
document.title = current + SITE_SUFFIX;
}
}
// Run when the DOM is ready
$(computeTitle);
// Re-run when MediaWiki reloads content dynamically
mw.hook('wikipage.content').add(computeTitle);
// Also observe heading changes
var h = document.getElementById('firstHeading');
if (h && window.MutationObserver) {
new MutationObserver(function () { computeTitle(); })
.observe(h, { childList: true, characterData: true, subtree: true });
}
})();
