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
mNo edit summary |
mNo edit summary |
||
| 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 () { | ||
| Line 12: | Line 13: | ||
var current = document.title; | var current = document.title; | ||
var base = t | var base = t; | ||
if (!current.startsWith(base)) { | if (!current.startsWith(base)) { | ||
document.title = base + SITE_SUFFIX; | document.title = base + SITE_SUFFIX; | ||
| Line 20: | 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) { | ||
Revision as of 02:47, 8 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 = ' – Walkscape Walkthrough';
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 });
}
})();
