User:LiteraGame/common.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
//All code here is from my common.js pages from the Minecarft Wikis and Meta MCW <https://minecraft.wiki/>
// HotCat
mw.loader.load('https://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&action=raw&ctype=text/javascript');
// "Back to top"
$(function(){
var i18n = {
header: 'Back to Top'
};
new ResizeObserver(function(entries) {
if (window.innerWidth <= 720) {
$('#mw-panel').css('height', '');
}
else {
$('#mw-panel').css('height', document.body.scrollHeight - 10);
}
}).observe($('#content')[0]);
new ResizeObserver(function(entries) {
if ( document.body.scrollHeight < $('#mw-panel')[0].scrollHeight ) {
$('#p-btt').css('position', 'sticky');
}
else {
$('#p-btt').css('position', '');
}
}).observe($('#mw-panel')[0]);
$('<nav id="p-btt" class="vector-menu mw-portlet mw-portlet-btt vector-menu-portal portal collapsed" aria-labelledby="p-btt-label" role="navigation">').append(
$('<h3 id="p-btt-label" class="vector-menu-heading" tabindex="0">').append(
$('<span class="vector-menu-heading-label">').text(i18n.header)
).on("keypress", function(event) {
if (event.which == 13) {
$(this).trigger("click");
event.stopImmediatePropagation()
}
}).on("click", function(event) {
var isReduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
event.stopPropagation();
window.scrollTo({top: 0, behavior: isReduced ? 'instant' : 'smooth'});
})
).appendTo('#mw-panel');
});