MediaWiki:Gadget-GameHighlight.js

// Highlighting for tabs on game pages var selfLink = document.getElementsByClassName("mw-selflink"); if (selfLink.length > 2) { if (selfLink[1].firstChild.nodeName == 'SPAN') { selfLink[1].firstChild.classList.add(selfLink[1].firstChild.classList[2].replace('2', '')); selfLink[1].firstChild.classList.remove(selfLink[1].firstChild.classList[2]); } }

function compareText(item1, item2) { return item1.trim === item2.trim; // Use trim to remove leading/trailing whitespace }

function highlightTab(item) { item.classList.add(item.classList[2].replace('2', '')); item.classList.remove(item.classList[2]); }

// Check if the page title contains "/Games" if (mw.config.get('wgTitle').includes('/Games')) { var gameTab = document.getElementsByClassName('mcbutton'); var headers = document.getElementsByClassName('mw-headline');

window.onload = function { for (var i = 0; i < headers.length; i++) { if (typeof headers[i].firstChild.textContent !== "undefined") { for (var j = 0; j < gameTab.length; j++) { if (compareText(headers[i].firstChild.textContent, gameTab[j].textContent)) { highlightTab(gameTab[j]); }       }      }    }  }; }