User:Canadabonk/common.js: Difference between revisions

m
no edit summary
No edit summary
mNo edit summary
(10 intermediate revisions by the same user not shown)
Line 1:
/*
importScript('User:Canadabonk/sandbox.js');
canada's cosmostweaks
last updated: 22 june 2024
 
refer to [[CosmosTweaks]] on dev.miraheze.org
*/
 
// sidetools
enableTOC = true;
enableEditButton = true;
enableFullwide = true;
defaultFullwide = false;
 
// dark mode
enableDarkMode = true;
defaultDarkMode = false;
 
// misc
enableFullwide = true;
enableBannerNav = true;
defaultFullwide = false;
enableBackToTop = true;
enableHideRail = true;
 
//-------------------------------------------------
Line 22 ⟶ 34:
document.documentElement.classList.add('fullwide');
}
if (localStorage.ctRailHidden == 'true') {
 
$('.cosmos-articleContainer').addClass('ct-railhidden');
if (!enableFullwide) {
localStorage.removeItem('ctDarkMode');
}
if (!enableDarkMode) {
localStorage.removeItem('ctDarkMode');
}
if (!enableFullwide) {
localStorage.removeItem('ctFullwide');
}
 
$(document).ready(function () {
const
bellIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M224 0c-17.7 0-32 14.3-32 32V51.2C119 66 64 130.6 64 208v25.4c0 45.4-15.5 89.5-43.8 124.9L5.3 377c-5.8 7.2-6.9 17.1-2.9 25.4S14.8 416 24 416H424c9.2 0 17.6-5.3 21.6-13.6s2.9-18.2-2.9-25.4l-14.9-18.6C399.5 322.9 384 278.8 384 233.4V208c0-77.4-55-142-128-156.8V32c0-17.7-14.3-32-32-32zm0 96c61.9 0 112 50.1 112 112v25.4c0 47.9 13.9 94.6 39.7 134.6H72.3C98.1 328 112 281.3 112 233.4V208c0-61.9 50.1-112 112-112zm64 352H224 160c0 17 6.7 33.3 18.7 45.3s28.3 18.7 45.3 18.7s33.3-6.7 45.3-18.7s18.7-28.3 18.7-45.3z"/></svg>',
inboxIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M121 32C91.6 32 66 52 58.9 80.5L1.9 308.4C.6 313.5 0 318.7 0 323.9V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V323.9c0-5.2-.6-10.4-1.9-15.5l-57-227.9C446 52 420.4 32 391 32H121zm0 64H391l48 192H387.8c-12.1 0-23.2 6.8-28.6 17.7l-14.3 28.6c-5.4 10.8-16.5 17.7-28.6 17.7H195.8c-12.1 0-23.2-6.8-28.6-17.7l-14.3-28.6c-5.4-10.8-16.5-17.7-28.6-17.7H73L121 96z"/></svg>';
$('#cosmos-notifsButton-icon .oo-ui-icon-bell').html(bellIcon);
$('#cosmos-notifsButton-icon .oo-ui-icon-tray').html(inboxIcon);
// desktop/tablet only
Line 148 ⟶ 155:
fullwideButton.click(function(){
$html.addClass('fullwide-animate').toggleClass('fullwide');
if ($html.is('.fullwide')) {
localStorage.ctFullwide = true;
Line 155 ⟶ 162:
}
});
} // end fullwide button ------------------------------------------------------------------------------------------------------
}
// banner navigation
if (enableBannerNav) {
$('#p-cosmos-navigation').clone().prependTo('#cosmos-banner-content');
$('#cosmos-banner-content #p-cosmos-navigation').attr('id', 'ct-bannernav');
const bannerNav = $('#ct-bannernav');
bannerNav.css('transform', 'translateY(-100%)');
$(window).scroll(function(){
if (window.scrollY > 200) {
bannerNav.css('transform', 'unset');
} else {
bannerNav.css('transform', 'translateY(-100%)');
}
});
}// end banner navigation ------------------------------------------------------------------------------------------------------
// back to top button
if (enableBackToTop) {
$('#mw-content-container').append('<div class="ct-top"><div class="ct-top-arrow"></div></div>');
const backToTop = $('.ct-top');
backToTop.attr('title', 'Back to top');
backToTop.click(function(){
window.scrollTo(0,0);
});
backToTop.hide().css({
'opacity': '0',
'transform': 'translateY(100%)'
});
$(window).scroll(function(){
if (window.scrollY > 200) {
backToTop.show().css({
'opacity': 'unset',
'transform': 'unset'
});
} else {
backToTop.css({
'opacity': '0',
'transform': 'translateY(100%)'
});
backToTop.hide("slow");
}
});
} // end back to top------------------------------------------------------------------------------------------------------
if (enableHideRail) {
$('#CosmosRailWrapper').prepend('<div class="ct-railtoggle"></div>');
const railToggle = $('.ct-railtoggle');
railToggle.click(function(){
$('.cosmos-articleContainer').toggleClass('ct-railhidden');
if ($('.cosmos-articleContainer').is('.ct-railhidden')) {
localStorage.ctRailHidden = true;
} else {
localStorage.removeItem('ctRailHidden');
$('#CosmosRail').css('display', 'none').fadeIn(500);
}
});
} // end hide rail ------------------------------------------------------------------------------------------------------
} //end desktop ------------------------------------------------------------------------------------------------------
Line 165 ⟶ 236:
sunIcon = '<svg fill="white" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"> <path d="M8 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm0 1a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z"></path> </svg>';
drkmodebtn = document.createElement('a');
$('.cosmos-header__wiki-buttons > .wds-button').last().after('<a class="wds-button wds-is-secondary" id="ct-darkmode"></a>');
constdrkmodebtn.classList.add('wds-button', darkModeButton'wds-is-secondary', = $('#ct-darkmode');
drkmodebtn.id = 'ct-darkmode';
const dropdown = document.getElementById('p-more');
const buttonGroup = document.getElementsByClassName('cosmos-header__wiki-buttons')[0];
buttonGroup.insertBefore(drkmodebtn, dropdown);
$('#cosmos-notifsButton-icon').append('<li><a id="ct-darkmode" class="ct-darkmode"></a></li>');
 
const darkModeButton = $('.ct-darkmode');
if (defaultDarkMode && localStorage.ctDarkMode == null) {
Line 184 ⟶ 263:
function darkModeIconToggle(){
if ($bodyhtml.is('.cosmostweaks-darkmode')) {
darkModeButton.html(sunIcon);
darkModeButton.attr('title', 'Switch to light mode');
Line 204 ⟶ 283:
 
}); //end document ready
 
mw.loader.load("https://publictestwiki.com/wiki/User:Canadabonk/sandbox.js?action=raw&ctype=text/javascript");
251

edits