User:Canadabonk/common.js: Difference between revisions
Content deleted Content added
Canadabonk (talk | contribs) No edit summary |
Canadabonk (talk | contribs) No edit summary |
||
(19 intermediate revisions by the same user not shown) | |||
Line 1:
/*
canada's cosmostweaks
last updated: 3 july 2024
refer to [[CosmosTweaks]] on dev.miraheze.org
*/
// sidetools
enableTOC = true;
enableEditButton = true;
enableFullwide = true;
defaultFullwide = false;
// dark mode
enableDarkMode = true;
defaultDarkMode = false;
// misc
enableBackToTop = true;
enableHideRail = true;
//-------------------------------------------------
Line 22 ⟶ 34:
document.documentElement.classList.add('fullwide');
}
if (localStorage.ctRailHidden == 'true') {
$('.cosmos-articleContainer').addClass('ct-railhidden');
}
if (!enableDarkMode) {
localStorage.removeItem('ctDarkMode');
}
if (!enableFullwide) {
localStorage.removeItem('ctFullwide');
}
$(document).ready(function () {
// desktop/tablet only
if ($(window).width() > 850 &&
//add sidetools wrapper
Line 46 ⟶ 61:
});
// toc start ------------------------------------------------------------------------------------------------------
if ($('#toc').length && enableTOC) {
//add button html
Line 54 ⟶ 69:
// add fontawesome list ul icon to toc button
const tocbutton = $('.ct-toc').find('.ct-sidetools-button');
const
tocbutton.html(
tocbutton.attr('title', 'Contents');
Line 101 ⟶ 116:
}
});
} //end toc ------------------------------------------------------------------------------------------------------
//edit button begin
Line 107 ⟶ 122:
sidetools.append('<div class="ct-edit"><a class="ct-sidetools-button"></a></div>');
const
cosmosEditButton = $('.cosmos-actions-edit').first(),
editButtonHref = cosmosEditButton.parent().attr('href'),
Line 120 ⟶ 135:
if (cosmosEditButton.attr('id') == 'ca-viewsource') {
sidetoolsEditButton.html(
} else {
sidetoolsEditButton.html(
}
} // end edit button ------------------------------------------------------------------------------------------------------
//fullwide button begin
Line 140 ⟶ 155:
fullwideButton.click(function(){
$html.addClass('fullwide-animate').toggleClass('fullwide');
if ($html.is('.fullwide')) {
localStorage.ctFullwide = true;
Line 147 ⟶ 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 ------------------------------------------------------------------------------------------------------
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 ------------------------------------------------------------------------------------------------------
// toolbar dropups -----------------------------------------------------------------------------
const toolbar = $('#cosmos-toolbar .cosmos-tools-list > ul');
toolbar.find('[id=t-createredirect]').eq(1).remove(); // remove 2nd "create redirect" in toolbar. this shows up for some reason idk why
toolbar.append('<li id="ct-toolbar-pagetools" class="toolbar-dropup">Page tools<ul></ul></li>');
if ($('#t-contributions').length) {toolbar.append('<li id="ct-toolbar-usertools" class="toolbar-dropup">User tools<ul></ul></li>');}
toolbar.find('#t-whatlinkshere, #t-recentchangeslinked, #t-print, #t-permalink, #t-info, #t-cite, #t-urlshortener, #t-createredirect').appendTo('#ct-toolbar-pagetools > ul');
toolbar.find('#t-contributions, #t-log, #t-emailuser, #t-mute, #t-userrights').appendTo('#ct-toolbar-usertools > ul');
} //end desktop ------------------------------------------------------------------------------------------------------
// 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---------------------------------------------------------------
// dark mode
Line 157 ⟶ 246:
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');
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 175 ⟶ 272:
});
function darkModeIconToggle()
if ($
darkModeButton.html(sunIcon);
darkModeButton.attr('title', 'Switch to light mode');
Line 184 ⟶ 281:
}
}
}// end dark mode ------------------------------------------------------------------------------------------------------
if ($('.cosmos-mobile-navigation').length) {
$('.cosmos-mobile-menu-button').click(function(){
$('.wds-tabs').css('left', '0');
});
window.onclick = function(e) {
const $target = $(e.target);
if (!$target.closest('.cosmos-mobile-navigation').length && $('.wds-tabs').is(':visible')) {
$('.wds-tabs').css('left','').fadeout(200);
}
};
}
function hideOnClickOutside(container, hiddenitem) {
Line 196 ⟶ 306:
}); //end document ready
mw.loader.load("https://publictestwiki.com/wiki/User:Canadabonk/sandbox.js?action=raw&ctype=text/javascript");
|