MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 60: | Line 60: | ||
updateCalendar(); | updateCalendar(); | ||
} | } | ||
})();/* GoodToKnow restored right sidebar */ | |||
(function () { | |||
'use strict'; | |||
function restoreSidebar() { | |||
if (document.body.classList.contains('action-view') === false) { | |||
return; | |||
} | |||
var main = document.querySelector('#mw-content-text'); | |||
var appearance = document.querySelector('.vector-column-end'); | |||
var content = document.querySelector('.mw-body'); | |||
if (!main || !content || document.getElementById('gtk-restored-sidebar')) { | |||
return; | |||
} | |||
var sidebar = document.createElement('aside'); | |||
sidebar.id = 'gtk-restored-sidebar'; | |||
sidebar.setAttribute('aria-label', 'GoodToKnow sidebar'); | |||
var history = document.createElement('section'); | |||
history.className = 'gtk-history-panel'; | |||
var heading = document.createElement('h3'); | |||
heading.textContent = 'Today in history:'; | |||
history.appendChild(heading); | |||
var historyText = document.createElement('p'); | |||
historyText.textContent = | |||
'This content comes from the Today in history wiki page.'; | |||
history.appendChild(historyText); | |||
sidebar.appendChild(history); | |||
var navigation = document.createElement('nav'); | |||
navigation.className = 'gtk-navigation-panel'; | |||
navigation.setAttribute('aria-label', 'Navigation'); | |||
var navHeading = document.createElement('h3'); | |||
navHeading.textContent = 'Navigation'; | |||
navigation.appendChild(navHeading); | |||
var links = document.createElement('ul'); | |||
[ | |||
['Main page', 'Main_Page'], | |||
['Recent changes', 'Special:RecentChanges'], | |||
['Random page', 'Special:Random'], | |||
['Help about MediaWiki', 'Help:Contents'], | |||
['Edit', 'Main_Page'] | |||
].forEach(function (item) { | |||
var li = document.createElement('li'); | |||
var a = document.createElement('a'); | |||
a.textContent = item[0]; | |||
a.href = mw.util.getUrl(item[1]); | |||
if (item[0] === 'Edit') { | |||
a.href = mw.util.getUrl('Main_Page', { | |||
action: 'edit' | |||
}); | |||
} | |||
li.appendChild(a); | |||
links.appendChild(li); | |||
}); | |||
navigation.appendChild(links); | |||
sidebar.appendChild(navigation); | |||
content.appendChild(sidebar); | |||
content.classList.add('gtk-sidebar-layout'); | |||
if (appearance) { | |||
appearance.classList.add('gtk-hide-appearance'); | |||
} | |||
} | |||
mw.hook('wikipage.content').add(restoreSidebar); | |||
})(); | })(); | ||
Latest revision as of 01:16, 3 November 2026
/* GoodToKnow original daily observances calendar */
(function () {
'use strict';
function updateCalendar() {
var dateElement = document.getElementById('date-today');
var observancesElement = document.getElementById('today-in-history');
var sourceElement = document.querySelector('.todayisurl');
if (!dateElement || !observancesElement) {
return;
}
var now = new Date();
var months = [
'jan', 'feb', 'mar', 'apr', 'may', 'jun',
'jul', 'aug', 'sep', 'oct', 'nov', 'dec'
];
var month = months[now.getMonth()];
var day = String(now.getDate());
dateElement.textContent = 'Today is: ' +
now.toLocaleDateString('en-US', {
month: 'long',
day: 'numeric'
});
if (sourceElement) {
sourceElement.textContent =
'- Source: https://nationaldaycalendar.com/' +
now.toLocaleDateString('en-US', { month: 'long' }).toLowerCase() + '/';
}
fetch('/resources/assets/todayis.json')
.then(function (response) {
if (!response.ok) {
throw new Error('Calendar HTTP ' + response.status);
}
return response.json();
})
.then(function (data) {
var entries = (data.month && data.month[month]) || [];
var entry = entries.find(function (item) {
return String(item.date) === day;
});
observancesElement.textContent =
entry && Array.isArray(entry.day)
? entry.day.join(', ')
: '';
})
.catch(function (error) {
console.error('GoodToKnow calendar:', error);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', updateCalendar);
} else {
updateCalendar();
}
})();/* GoodToKnow restored right sidebar */
(function () {
'use strict';
function restoreSidebar() {
if (document.body.classList.contains('action-view') === false) {
return;
}
var main = document.querySelector('#mw-content-text');
var appearance = document.querySelector('.vector-column-end');
var content = document.querySelector('.mw-body');
if (!main || !content || document.getElementById('gtk-restored-sidebar')) {
return;
}
var sidebar = document.createElement('aside');
sidebar.id = 'gtk-restored-sidebar';
sidebar.setAttribute('aria-label', 'GoodToKnow sidebar');
var history = document.createElement('section');
history.className = 'gtk-history-panel';
var heading = document.createElement('h3');
heading.textContent = 'Today in history:';
history.appendChild(heading);
var historyText = document.createElement('p');
historyText.textContent =
'This content comes from the Today in history wiki page.';
history.appendChild(historyText);
sidebar.appendChild(history);
var navigation = document.createElement('nav');
navigation.className = 'gtk-navigation-panel';
navigation.setAttribute('aria-label', 'Navigation');
var navHeading = document.createElement('h3');
navHeading.textContent = 'Navigation';
navigation.appendChild(navHeading);
var links = document.createElement('ul');
[
['Main page', 'Main_Page'],
['Recent changes', 'Special:RecentChanges'],
['Random page', 'Special:Random'],
['Help about MediaWiki', 'Help:Contents'],
['Edit', 'Main_Page']
].forEach(function (item) {
var li = document.createElement('li');
var a = document.createElement('a');
a.textContent = item[0];
a.href = mw.util.getUrl(item[1]);
if (item[0] === 'Edit') {
a.href = mw.util.getUrl('Main_Page', {
action: 'edit'
});
}
li.appendChild(a);
links.appendChild(li);
});
navigation.appendChild(links);
sidebar.appendChild(navigation);
content.appendChild(sidebar);
content.classList.add('gtk-sidebar-layout');
if (appearance) {
appearance.classList.add('gtk-hide-appearance');
}
}
mw.hook('wikipage.content').add(restoreSidebar);
})();