(function(){
var select = document.getElementById('mw-cat-select');
if(!select) return;
// Navigate on change
select.addEventListener('change', function(){
var val = this.value;
if(!val) return;
// Build absolute URL when relative path used
var url = (val.indexOf('http') === 0) ? val : (window.location.origin.replace(/\/$/,'') + val);
window.location.href = url;
});
// Auto-select the current category if on a category page
try{
var path = window.location.pathname.replace(/\/$/,'');
for(var i=0;i<select.options.length;i++){
var optVal = select.options[i].value;
if(!optVal) continue;
var check = optVal.replace(/\/$/,'');
if(path.indexOf(check) !== -1){
select.selectedIndex = i;
break;
}
}
}catch(e){}
})();