MediaWiki:Gadget-darkmode.js: Skirtumas tarp puslapio versijų
Pereiti į navigaciją
Jump to search
SNėra keitimo santraukos |
SNėra keitimo santraukos |
||
| 18 eilutė: | 18 eilutė: | ||
init: function () { | init: function () { | ||
$.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'}); | $.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'}); | ||
console.log('test1') | |||
portletLink = mw.util.addPortletLink( | portletLink = mw.util.addPortletLink( | ||
| 31 eilutė: | 33 eilutė: | ||
$(portletLink).find('a').click(function(e) { | $(portletLink).find('a').click(function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
console.log('test2') | |||
isUsingDarkmode = !isUsingDarkmode; | isUsingDarkmode = !isUsingDarkmode; | ||
| 37 eilutė: | 41 eilutė: | ||
if (isUsingDarkmode === true) { | if (isUsingDarkmode === true) { | ||
console.log('test3') | |||
mw.loader.using(['wgl.theme.dark']).then(function() { | mw.loader.using(['wgl.theme.dark']).then(function() { | ||
$('body').addClass('wgl-theme-dark') | $('body').addClass('wgl-theme-dark') | ||
| 43 eilutė: | 48 eilutė: | ||
}); | }); | ||
} else { | } else { | ||
console.log('test4') | |||
$('body').addClass('wgl-theme-light') | $('body').addClass('wgl-theme-light') | ||
$('body').removeClass('wgl-theme-dark') | $('body').removeClass('wgl-theme-dark') | ||
mw.hook('wgl.themeChanged').fire('light') | mw.hook('wgl.themeChanged').fire('light') | ||
} | } | ||
console.log('test5') | |||
}); | }); | ||
} | } | ||
21:41, 13 balandžio 2025 versija
/**
* Toggle for dark mode
*
* @author [[User:Jayden]]
* @see Based on https://runescape.wiki/w/MediaWiki:Gadget-skinTogglesNew.js
*/
;(function($, mw){
var DARK_COOKIE = 'darkmode',
THEME_COOKIE = 'theme',
isUsingDarkmode = $.cookie(THEME_COOKIE) === 'dark' || ($.cookie(THEME_COOKIE) == null && $.cookie(DARK_COOKIE) === 'true'),
isMobile = mw.config.get('wgMFMode') !== null,
portletLink;
console.log("Dark mode toggle initialized");
var self = {
init: function () {
$.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'});
console.log('test1')
portletLink = mw.util.addPortletLink(
( isMobile ? 'p-navigation' : 'p-personal' ),
'',
( isMobile ? 'Toggle dark mode' : '' ),
'pt-dm-toggle',
'Toggle dark mode',
null,
$('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0]
);
$(portletLink).find('a').click(function(e) {
e.preventDefault();
console.log('test2')
isUsingDarkmode = !isUsingDarkmode;
$.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'});
$.cookie(DARK_COOKIE, isUsingDarkmode, {expires: 365, path: '/'});
if (isUsingDarkmode === true) {
console.log('test3')
mw.loader.using(['wgl.theme.dark']).then(function() {
$('body').addClass('wgl-theme-dark')
$('body').removeClass('wgl-theme-light')
mw.hook('wgl.themeChanged').fire('dark')
});
} else {
console.log('test4')
$('body').addClass('wgl-theme-light')
$('body').removeClass('wgl-theme-dark')
mw.hook('wgl.themeChanged').fire('light')
}
console.log('test5')
});
}
}
$(self.init);
}(jQuery, mediaWiki));