MediaWiki:Common.js: mudanças entre as edições
Aparência
JS com menu superior, tema e últimas wikis |
Removendo lateral via JS e criando menu superior |
||
| Linha 1: | Linha 1: | ||
(function () { | (function () { | ||
function removeSidebarCompletely() { | |||
var selectors = [ | |||
'#mw-panel', | |||
'#mw-navigation', | |||
'#p-logo', | |||
'#p-navigation', | |||
'#p-tb', | |||
'#p-lang', | |||
'#p-interaction', | |||
'#p-cactions', | |||
'#p-personal', | |||
'.mw-sidebar', | |||
'.mw-portlet', | |||
'.vector-sidebar-container', | |||
'.vector-main-menu', | |||
'.vector-main-menu-landmark', | |||
'.vector-column-start', | |||
'.vector-toc-landmark', | |||
'.vector-page-toolbar', | |||
'.vector-sticky-header', | |||
'.citizen-drawer', | |||
'.citizen-sidebar', | |||
'.citizen-page-sidebar', | |||
'.citizen-toc', | |||
'.citizen-drawer__card', | |||
'.citizen-header__button--menu', | |||
'.citizen-header__button--toc', | |||
'.citizen-page-header__actions', | |||
'.citizen-page-actions' | |||
]; | |||
selectors.forEach(function (selector) { | |||
document.querySelectorAll(selector).forEach(function (el) { | |||
el.remove(); | |||
}); | |||
}); | |||
} | |||
function applyTheme(theme) { | function applyTheme(theme) { | ||
document.documentElement.setAttribute('data-td-theme', theme); | document.documentElement.setAttribute('data-td-theme', theme); | ||
| Linha 17: | Linha 55: | ||
} | } | ||
function | function mountTopbar() { | ||
if (document.getElementById('td- | if (document.getElementById('td-topbar')) return; | ||
document. | var bar = document.createElement('div'); | ||
bar.id = 'td-topbar'; | |||
var inner = document.createElement('div'); | |||
inner.className = 'td-topbar-inner'; | |||
var | var brand = document.createElement('a'); | ||
brand.className = 'td-topbar-brand'; | |||
brand.href = mw.util.getUrl('Página principal'); | |||
brand.setAttribute('aria-label', 'Wiki TokuDrive'); | |||
var | var menu = document.createElement('nav'); | ||
menu.className = 'td-topbar-menu'; | |||
var links = [ | var links = [ | ||
| Linha 50: | Linha 81: | ||
['Kaiju', 'Categoria:Kaiju'], | ['Kaiju', 'Categoria:Kaiju'], | ||
['Godzilla', 'Categoria:Godzilla'], | ['Godzilla', 'Categoria:Godzilla'], | ||
[' | ['Recentes', 'Especial:Mudanças recentes'] | ||
]; | ]; | ||
| Linha 57: | Linha 88: | ||
a.href = mw.util.getUrl(item[1]); | a.href = mw.util.getUrl(item[1]); | ||
a.textContent = item[0]; | a.textContent = item[0]; | ||
menu.appendChild(a); | |||
}); | }); | ||
var searchWrap = document.createElement('form'); | |||
searchWrap.className = 'td-topbar-search'; | |||
var | var searchInput = document.createElement('input'); | ||
searchInput.type = 'search'; | |||
searchInput.placeholder = 'Pesquisar na wiki'; | |||
searchInput.autocomplete = 'off'; | |||
searchWrap.appendChild(searchInput); | |||
searchWrap.addEventListener('submit', function (e) { | |||
} | e.preventDefault(); | ||
var q = searchInput.value.trim(); | |||
} | window.location.href = mw.util.getUrl('Especial:Pesquisar') + (q ? '?search=' + encodeURIComponent(q) : ''); | ||
}); | |||
inner.appendChild(brand); | |||
inner.appendChild(menu); | |||
inner.appendChild(searchWrap); | |||
bar.appendChild(inner); | |||
document.body.insertBefore(bar, document.body.firstChild); | |||
} | |||
function mountThemeButton() { | |||
if (document.getElementById('td-theme-toggle')) return; | |||
var btn = document.createElement('button'); | |||
btn.id = 'td-theme-toggle'; | |||
btn.type = 'button'; | |||
btn.addEventListener('click', function () { | |||
var active = document.documentElement.getAttribute('data-td-theme') || 'light'; | |||
applyTheme(active === 'dark' ? 'light' : 'dark'); | |||
}); | |||
document.body.appendChild(btn); | |||
applyTheme(getTheme()); | |||
} | } | ||
function | function mountHomeSearch() { | ||
var mount = document.getElementById('td-home-search'); | var mount = document.getElementById('td-home-search'); | ||
if (!mount) return; | if (!mount) return; | ||
| Linha 97: | Linha 153: | ||
event.preventDefault(); | event.preventDefault(); | ||
var q = input.value.trim(); | var q = input.value.trim(); | ||
window.location.href = mw.util.getUrl('Especial:Pesquisar') + (q ? '?search=' + encodeURIComponent(q) : ''); | |||
}); | }); | ||
| Linha 134: | Linha 184: | ||
+ '&rcnamespace=0' | + '&rcnamespace=0' | ||
+ '&rcprop=title|timestamp' | + '&rcprop=title|timestamp' | ||
+ '&rclimit= | + '&rclimit=16'; | ||
fetch(url, { credentials: 'same-origin' }) | fetch(url, { credentials: 'same-origin' }) | ||
| Linha 188: | Linha 238: | ||
mw.loader.using('mediawiki.util').then(function () { | mw.loader.using('mediawiki.util').then(function () { | ||
removeSidebarCompletely(); | |||
mountTopbar(); | |||
mountThemeButton(); | mountThemeButton(); | ||
mountHomeSearch(); | |||
mountLatestWikis(); | mountLatestWikis(); | ||
setTimeout(removeSidebarCompletely, 300); | |||
setTimeout(removeSidebarCompletely, 1000); | |||
setTimeout(removeSidebarCompletely, 2500); | |||
}); | }); | ||
} | } | ||
Edição das 15h03min de 28 de junho de 2026
(function () {
function removeSidebarCompletely() {
var selectors = [
'#mw-panel',
'#mw-navigation',
'#p-logo',
'#p-navigation',
'#p-tb',
'#p-lang',
'#p-interaction',
'#p-cactions',
'#p-personal',
'.mw-sidebar',
'.mw-portlet',
'.vector-sidebar-container',
'.vector-main-menu',
'.vector-main-menu-landmark',
'.vector-column-start',
'.vector-toc-landmark',
'.vector-page-toolbar',
'.vector-sticky-header',
'.citizen-drawer',
'.citizen-sidebar',
'.citizen-page-sidebar',
'.citizen-toc',
'.citizen-drawer__card',
'.citizen-header__button--menu',
'.citizen-header__button--toc',
'.citizen-page-header__actions',
'.citizen-page-actions'
];
selectors.forEach(function (selector) {
document.querySelectorAll(selector).forEach(function (el) {
el.remove();
});
});
}
function applyTheme(theme) {
document.documentElement.setAttribute('data-td-theme', theme);
localStorage.setItem('tdTheme', theme);
var btn = document.getElementById('td-theme-toggle');
if (btn) {
btn.textContent = theme === 'dark' ? '☀️ Claro' : '🌙 Escuro';
}
}
function getTheme() {
var saved = localStorage.getItem('tdTheme');
if (saved === 'dark' || saved === 'light') return saved;
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) return 'dark';
return 'light';
}
function mountTopbar() {
if (document.getElementById('td-topbar')) return;
var bar = document.createElement('div');
bar.id = 'td-topbar';
var inner = document.createElement('div');
inner.className = 'td-topbar-inner';
var brand = document.createElement('a');
brand.className = 'td-topbar-brand';
brand.href = mw.util.getUrl('Página principal');
brand.setAttribute('aria-label', 'Wiki TokuDrive');
var menu = document.createElement('nav');
menu.className = 'td-topbar-menu';
var links = [
['Início', 'Página principal'],
['Tokusatsu', 'Tokusatsu'],
['Kamen Rider', 'Categoria:Kamen Rider'],
['Super Sentai', 'Categoria:Super Sentai'],
['Ultraman', 'Categoria:Ultraman'],
['Metal Heroes', 'Categoria:Metal Heroes'],
['Kaiju', 'Categoria:Kaiju'],
['Godzilla', 'Categoria:Godzilla'],
['Recentes', 'Especial:Mudanças recentes']
];
links.forEach(function (item) {
var a = document.createElement('a');
a.href = mw.util.getUrl(item[1]);
a.textContent = item[0];
menu.appendChild(a);
});
var searchWrap = document.createElement('form');
searchWrap.className = 'td-topbar-search';
var searchInput = document.createElement('input');
searchInput.type = 'search';
searchInput.placeholder = 'Pesquisar na wiki';
searchInput.autocomplete = 'off';
searchWrap.appendChild(searchInput);
searchWrap.addEventListener('submit', function (e) {
e.preventDefault();
var q = searchInput.value.trim();
window.location.href = mw.util.getUrl('Especial:Pesquisar') + (q ? '?search=' + encodeURIComponent(q) : '');
});
inner.appendChild(brand);
inner.appendChild(menu);
inner.appendChild(searchWrap);
bar.appendChild(inner);
document.body.insertBefore(bar, document.body.firstChild);
}
function mountThemeButton() {
if (document.getElementById('td-theme-toggle')) return;
var btn = document.createElement('button');
btn.id = 'td-theme-toggle';
btn.type = 'button';
btn.addEventListener('click', function () {
var active = document.documentElement.getAttribute('data-td-theme') || 'light';
applyTheme(active === 'dark' ? 'light' : 'dark');
});
document.body.appendChild(btn);
applyTheme(getTheme());
}
function mountHomeSearch() {
var mount = document.getElementById('td-home-search');
if (!mount) return;
var form = document.createElement('form');
form.className = 'td-search-form';
var input = document.createElement('input');
input.className = 'td-search-input';
input.type = 'search';
input.placeholder = 'Pesquisar séries, filmes, personagens e franquias';
input.autocomplete = 'off';
var button = document.createElement('button');
button.className = 'td-search-button';
button.type = 'submit';
button.textContent = 'Pesquisar';
form.appendChild(input);
form.appendChild(button);
form.addEventListener('submit', function (event) {
event.preventDefault();
var q = input.value.trim();
window.location.href = mw.util.getUrl('Especial:Pesquisar') + (q ? '?search=' + encodeURIComponent(q) : '');
});
mount.innerHTML = '';
mount.appendChild(form);
}
function formatDate(iso) {
try {
return new Date(iso).toLocaleDateString('pt-BR', {
day: '2-digit',
month: 'short',
year: 'numeric'
});
} catch (e) {
return '';
}
}
function mountLatestWikis() {
var container = document.getElementById('td-latest-wikis');
if (!container) return;
var api = (mw.config.get('wgScriptPath') || '') + '/api.php';
var url = api
+ '?action=query'
+ '&format=json'
+ '&list=recentchanges'
+ '&rctype=new'
+ '&rcnamespace=0'
+ '&rcprop=title|timestamp'
+ '&rclimit=16';
fetch(url, { credentials: 'same-origin' })
.then(function (res) { return res.json(); })
.then(function (data) {
var items = (((data || {}).query || {}).recentchanges || [])
.filter(function (item) {
return item.title && item.title !== 'Página principal';
})
.slice(0, 8);
container.innerHTML = '';
if (!items.length) {
var empty = document.createElement('div');
empty.className = 'td-loading';
empty.textContent = 'Nenhuma página nova encontrada ainda.';
container.appendChild(empty);
return;
}
items.forEach(function (item) {
var a = document.createElement('a');
a.className = 'td-latest-card';
a.href = mw.util.getUrl(item.title);
var label = document.createElement('div');
label.className = 'td-latest-label';
label.textContent = 'Wiki criada/importada';
var title = document.createElement('div');
title.className = 'td-latest-title';
title.textContent = item.title;
var date = document.createElement('div');
date.className = 'td-latest-date';
date.textContent = formatDate(item.timestamp);
a.appendChild(label);
a.appendChild(title);
a.appendChild(date);
container.appendChild(a);
});
})
.catch(function () {
container.innerHTML = '<div class="td-loading">Não foi possível carregar as últimas wikis agora.</div>';
});
}
function init() {
applyTheme(getTheme());
mw.loader.using('mediawiki.util').then(function () {
removeSidebarCompletely();
mountTopbar();
mountThemeButton();
mountHomeSearch();
mountLatestWikis();
setTimeout(removeSidebarCompletely, 300);
setTimeout(removeSidebarCompletely, 1000);
setTimeout(removeSidebarCompletely, 2500);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();