父节点
6d8f86338c
当前提交
44bcedaba3
|
@ -10,5 +10,5 @@
|
|||
"space-in-parens": 0,
|
||||
"mediawiki/msg-doc": "off"
|
||||
},
|
||||
"ignorePatterns": ["resources/ext.DarkMode.EmojiWrap.js"]
|
||||
"ignorePatterns": [ "resources/ext.DarkMode.EmojiWrap.js" ]
|
||||
}
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
.*.swp
|
||||
*~
|
||||
/composer.lock
|
||||
/vendor
|
||||
/node_modules
|
||||
.eslintcache
|
||||
vendor
|
||||
node_modules
|
||||
composer.lock
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = ( grunt ) => {
|
||||
const conf = grunt.file.readJSON( 'extension.json' );
|
||||
module.exports = function ( grunt ) {
|
||||
var conf = grunt.file.readJSON( 'extension.json' );
|
||||
|
||||
grunt.loadNpmTasks( 'grunt-banana-checker' );
|
||||
grunt.loadNpmTasks( 'grunt-eslint' );
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "DarkMode",
|
||||
"version": "0.4.0",
|
||||
"author": ["MusikAnimal", "R4356th", "AnYi", "WaitSpring"],
|
||||
"author": [ "MusikAnimal", "R4356th", "安忆", "WaitSpring" ],
|
||||
"url": "https://git.qiuwen.net.cn/Fork/mediawiki-extensions-DarkMode",
|
||||
"descriptionmsg": "darkmode-desc",
|
||||
"license-name": "GPL-3.0",
|
||||
|
@ -18,15 +18,15 @@
|
|||
"HookHandlers": {
|
||||
"main": {
|
||||
"class": "MediaWiki\\Extension\\DarkMode\\Hooks",
|
||||
"services": ["MainConfig"]
|
||||
"services": [ "MainConfig" ]
|
||||
}
|
||||
},
|
||||
"MessagesDirs": {
|
||||
"DarkMode": ["i18n"]
|
||||
"DarkMode": [ "i18n" ]
|
||||
},
|
||||
"ResourceModules": {
|
||||
"ext.DarkMode": {
|
||||
"packageFiles": ["ext.DarkMode.js"],
|
||||
"packageFiles": [ "ext.DarkMode.js" ],
|
||||
"messages": [
|
||||
"darkmode-link",
|
||||
"darkmode-link-tooltip",
|
||||
|
@ -36,10 +36,10 @@
|
|||
},
|
||||
"ext.DarkMode.EmojiWrap": {
|
||||
"es6": true,
|
||||
"packageFiles": ["ext.DarkMode.EmojiWrap.js"]
|
||||
"packageFiles": [ "ext.DarkMode.EmojiWrap.js" ]
|
||||
},
|
||||
"ext.DarkMode.css": {
|
||||
"styles": ["ext.DarkMode.less"]
|
||||
"styles": [ "ext.DarkMode.less" ]
|
||||
}
|
||||
},
|
||||
"ResourceFileModulePaths": {
|
||||
|
|
文件差异因一行或多行过长而隐藏
|
@ -5,8 +5,9 @@
|
|||
* @license GPL-3.0
|
||||
*/
|
||||
(function () {
|
||||
var COOKIE_NAME = 'usedarkmode',
|
||||
ICON = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='50' height='50' viewBox='0 0 13.229 13.229'%3E%3Ccircle cx='6.614' cy='6.614' fill='%23fff' stroke='%2336c' stroke-width='1.322' r='5.953'/%3E%3Cpath d='M6.88 11.377a4.762 4.762 0 0 1-4.125-7.144 4.762 4.762 0 0 1 4.124-2.38v4.762z' fill='%2336c' paint-order='markers stroke fill'/%3E%3C/svg%3E",
|
||||
var COOKIE_NAME = 'ext.DarkMode_usedarkmode',
|
||||
ICON =
|
||||
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='50' height='50' viewBox='0 0 13.229 13.229'%3E%3Ccircle cx='6.614' cy='6.614' fill='%23fff' stroke='%2336c' stroke-width='1.322' r='5.953'/%3E%3Cpath d='M6.88 11.377a4.762 4.762 0 0 1-4.125-7.144 4.762 4.762 0 0 1 4.124-2.38v4.762z' fill='%2336c' paint-order='markers stroke fill'/%3E%3C/svg%3E",
|
||||
message = function (key) {
|
||||
return mw.message('darkmode-' + key).plain();
|
||||
};
|
||||
|
@ -15,12 +16,18 @@
|
|||
button.id = 'darkmode-button';
|
||||
button.src = ICON;
|
||||
button.draggable = false;
|
||||
button.alt = (document.documentElement.classList.contains('client-darkmode')) ? message('default-link') : message('link');
|
||||
button.title = (document.documentElement.classList.contains('client-darkmode')) ? message('default-link-tooltip') : message('link-tooltip');
|
||||
button.alt = document.documentElement.classList.contains('client-darkmode') ?
|
||||
message('default-link') :
|
||||
message('link');
|
||||
button.title = document.documentElement.classList.contains(
|
||||
'client-darkmode'
|
||||
) ?
|
||||
message('default-link-tooltip') :
|
||||
message('link-tooltip');
|
||||
button.style.opacity = '0.7';
|
||||
button.style.bottom = '120px';
|
||||
|
||||
var hoverListener = function (event) {
|
||||
var hoverListener = function hoverListener(event) {
|
||||
button.style.opacity = event.type === 'mouseenter' ? '1' : '0.7';
|
||||
};
|
||||
button.addEventListener('mouseenter', hoverListener);
|
||||
|
@ -28,24 +35,27 @@
|
|||
|
||||
document.body.appendChild(button);
|
||||
|
||||
function windowEventFunction() {
|
||||
button.style.bottom = (document.getElementById('cat_a_lot') ||
|
||||
var windowEventFunction = function windowEventFunction() {
|
||||
button.style.bottom =
|
||||
document.getElementById('cat_a_lot') ||
|
||||
document.getElementById('proveit') ||
|
||||
document.getElementsByClassName('wordcount')[ 0 ]) ? '162px' : '120px';
|
||||
}
|
||||
document.getElementsByClassName('wordcount')[ 0 ] ?
|
||||
'162px' :
|
||||
'120px';
|
||||
};
|
||||
window.addEventListener('scroll', windowEventFunction);
|
||||
window.addEventListener('selectionchange', windowEventFunction);
|
||||
|
||||
var getCookie = function (name) {
|
||||
return ('; '
|
||||
var getCookie = function getCookie(name) {
|
||||
return '; '
|
||||
.concat(decodeURIComponent(document.cookie))
|
||||
.split('; '.concat(name, '='))
|
||||
.pop()
|
||||
.split(';')
|
||||
.shift());
|
||||
.shift();
|
||||
};
|
||||
|
||||
var setCookie = function (object) {
|
||||
var setCookie = function setCookie(object) {
|
||||
var name = object.name,
|
||||
value = object.value,
|
||||
hour = object.hour || 0,
|
||||
|
@ -68,13 +78,16 @@
|
|||
document.cookie = base;
|
||||
} else {
|
||||
date.setTime(date.getTime() + hour * 60 * 60 * 1000);
|
||||
document.cookie = ''.concat(base, ';expires=').concat(date.toGMTString());
|
||||
document.cookie = ''
|
||||
.concat(base, ';expires=')
|
||||
.concat(date.toGMTString());
|
||||
}
|
||||
};
|
||||
|
||||
var setMetaContent = function (metaContent) {
|
||||
var setMetaContent = function setMetaContent(metaContent) {
|
||||
if (document.getElementsByTagName('meta')[ 'color-scheme' ]) {
|
||||
document.getElementsByTagName('meta')[ 'color-scheme' ].setAttribute('content', metaContent);
|
||||
document
|
||||
.getElementsByTagName('meta')[ 'color-scheme' ].setAttribute('content', metaContent);
|
||||
} else {
|
||||
var meta = document.createElement('meta');
|
||||
meta.name = 'color-scheme';
|
||||
|
@ -104,14 +117,22 @@
|
|||
}
|
||||
};
|
||||
|
||||
var checkDarkMode = function () {
|
||||
var checkDarkMode = function checkDarkMode() {
|
||||
if (getCookie(COOKIE_NAME) === '') {
|
||||
if (matchMedia('( prefers-color-scheme: dark )').matches) {
|
||||
setCookie({ name: COOKIE_NAME, value: '1', hour: 24 * 365 * 1000 });
|
||||
setCookie({
|
||||
name: COOKIE_NAME,
|
||||
value: '1',
|
||||
hour: 24 * 365 * 1000
|
||||
});
|
||||
document.documentElement.classList.remove('client-lightmode');
|
||||
document.documentElement.classList.add('client-darkmode');
|
||||
} else {
|
||||
setCookie({ name: COOKIE_NAME, value: '0', hour: 24 * 365 * 1000 });
|
||||
setCookie({
|
||||
name: COOKIE_NAME,
|
||||
value: '0',
|
||||
hour: 24 * 365 * 1000
|
||||
});
|
||||
document.documentElement.classList.remove('client-darkmode');
|
||||
document.documentElement.classList.add('client-lightmode');
|
||||
}
|
||||
|
@ -125,7 +146,7 @@
|
|||
}
|
||||
};
|
||||
|
||||
var toggleMode = function () {
|
||||
var toggleMode = function toggleMode() {
|
||||
if (getCookie(COOKIE_NAME) === '') {
|
||||
checkDarkMode();
|
||||
}
|
||||
|
|
正在加载...
在新工单中引用