MediaWiki:Gadget-site-js.js:修订间差异
MediaWiki界面页面
更多操作
第2行: | 第2行: | ||
* 模块 0:vConsole 加载(移动端专用) | * 模块 0:vConsole 加载(移动端专用) | ||
**********************/ | **********************/ | ||
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && !window.localStorage.getItem('disableVConsole')) { | |||
var vConsoleScript = document.createElement('script'); | |||
vConsoleScript.src = 'https://cdn.bootcdn.net/ajax/libs/vConsole/3.15.1/vconsole.min.js'; | vConsoleScript.src = 'https://cdn.bootcdn.net/ajax/libs/vConsole/3.15.1/vconsole.min.js'; | ||
vConsoleScript.onload = function() { | vConsoleScript.onload = function() { | ||
try { | try { | ||
第18行: | 第12行: | ||
} catch (e) { | } catch (e) { | ||
alert('调试工具初始化失败,请重试或联系管理员'); | alert('调试工具初始化失败,请重试或联系管理员'); | ||
} | } | ||
}; | }; | ||
vConsoleScript.onerror = function() { | vConsoleScript.onerror = function() { | ||
alert('调试工具加载失败,请检查网络连接'); | alert('调试工具加载失败,请检查网络连接'); | ||
}; | }; | ||
document.body.appendChild(vConsoleScript); | document.body.appendChild(vConsoleScript); | ||
} | } | ||
第33行: | 第23行: | ||
* 模块 1:CSS 变量 RGB 转换 | * 模块 1:CSS 变量 RGB 转换 | ||
**********************/ | **********************/ | ||
(function () { | |||
var cachedRgb = ''; | |||
var mo = new MutationObserver(function() { | |||
var root = document.documentElement; | |||
var hex = getComputedStyle(root).getPropertyValue('--background-color-base').trim(); | |||
hex = hex.replace(/^#/, ''); | hex = hex.replace(/^#/, ''); | ||
if (hex.length === 3) { | if (hex.length === 3) { | ||
hex = hex.split('').map(function(c) { return c + c; }).join(''); | hex = hex.split('').map(function(c) { return c + c; }).join(''); | ||
} | } | ||
if (hex.length !== 6) | if (hex.length !== 6) { | ||
root.style.setProperty('--background-color-rgb', '0, 0, 0'); | |||
return; | |||
} | |||
var r = parseInt(hex.substring(0, 2), 16); | var r = parseInt(hex.substring(0, 2), 16); | ||
var g = parseInt(hex.substring(2, 4), 16); | var g = parseInt(hex.substring(2, 4), 16); | ||
var b = parseInt(hex.substring(4, 6), 16); | var b = parseInt(hex.substring(4, 6), 16); | ||
var rgb = r + ', ' + g + ', ' + b; | |||
if (rgb !== cachedRgb) { | if (rgb !== cachedRgb) { | ||
root.style.setProperty('--background-color-rgb', rgb); | root.style.setProperty('--background-color-rgb', rgb); | ||
cachedRgb = rgb; | cachedRgb = rgb; | ||
} | } | ||
} | }); | ||
mo.observe(document.documentElement, { attributes: true, attributeFilter: ['style'] }); | mo.observe(document.documentElement, { attributes: true, attributeFilter: ['style'] }); | ||
})(); | })(); | ||
第71行: | 第51行: | ||
* 模块 2:上传页引导弹窗 | * 模块 2:上传页引导弹窗 | ||
**********************/ | **********************/ | ||
if (window.mw && mw.config && mw.config.get('wgCanonicalSpecialPageName') === 'Upload') { | if (window.mw && mw.config && mw.config.get('wgCanonicalSpecialPageName') === 'Upload') { | ||
var pref = mw.storage.get('uploadPreference'); | |||
var pref = mw.storage.get( | |||
if (pref === 'wizard') { | if (pref === 'wizard') { | ||
window.location.href = mw.util.getUrl('Special:UploadWizard'); | window.location.href = mw.util.getUrl('Special:UploadWizard'); | ||
} else if (pref !== 'classic') { | |||
} | document.addEventListener('click', function initDialog() { | ||
document.removeEventListener('click', initDialog); | |||
mw.loader.using(['oojs-ui-core', 'oojs-ui-widgets']).then(function() { | |||
var UploadDialog = function() {}; | |||
UploadDialog.static = { | |||
name: 'UploadDialog', | |||
title: '请选择上传方式', | |||
actions: [{ action: 'classic', label: '❌ 传统方式', flags: ['safe'] }] | |||
}; | |||
UploadDialog.prototype.initialize = function() { | |||
OO.ui.ProcessDialog.prototype.initialize.apply(this, arguments); | |||
this._remember = new OO.ui.CheckboxInputWidget(); | |||
var wizardBtn = new OO.ui.ButtonWidget({ | |||
label: '✅ 上传向导', | |||
flags: ['primary'], | |||
href: mw.util.getUrl('Special:UploadWizard'), | |||
target: '_self' | |||
}); | |||
wizardBtn.on('click', function() { | |||
if (this._remember.isSelected()) { | |||
mw.storage.set('uploadPreference', 'wizard'); | |||
} | |||
}.bind(this)); | |||
this.$body.append( | |||
$('<p>').text('请选择上传方式:'), | |||
wizardBtn.$element, | |||
new OO.ui.FieldLayout(this._remember, { | |||
label: '记住选择', | |||
align: 'inline' | |||
}).$element | |||
); | |||
}; | |||
UploadDialog.prototype.getActionProcess = function(action) { | |||
if (action === 'classic') { | |||
if (this._remember.isSelected()) { | |||
mw.storage.set('uploadPreference', 'classic'); | |||
} | |||
return new OO.ui.Process(function() { | |||
this.close(); | |||
}.bind(this)); | |||
} | } | ||
return OO.ui.ProcessDialog.prototype.getActionProcess.apply(this, arguments); | |||
}; | |||
var wm = new OO.ui.WindowManager(); | |||
document.body.appendChild(wm.$element); | |||
wm.addWindows([new UploadDialog()]); | |||
wm.openWindow('UploadDialog'); | |||
}); | |||
}); | }); | ||
} | } | ||
} | } | ||
第143行: | 第115行: | ||
* 模块 3:加载指示器 | * 模块 3:加载指示器 | ||
**********************/ | **********************/ | ||
(function () { | |||
var indicator = null; | var indicator = null; | ||
var timerId = null; | var timerId = null; | ||
function createIndicator() { | function createIndicator() { | ||
var div = document.createElement('div'); | var div = document.createElement('div'); | ||
div.style.position = 'fixed'; | div.style.position = 'fixed'; | ||
div.style.width = | div.style.width = '256px'; | ||
div.style.height = | div.style.height = '256px'; | ||
div.style.bottom = | div.style.bottom = '20px'; | ||
div.style.right = | div.style.right = '20px'; | ||
div.style.zIndex = | div.style.zIndex = '99999'; | ||
div.style.background = 'url( | div.style.background = 'url(https://wiki.ottohub.cn/images/0/02/Loading.png) center/contain no-repeat'; | ||
div.style.opacity = '0'; | div.style.opacity = '0'; | ||
div.style.transition = 'opacity | div.style.transition = 'opacity 300ms'; | ||
div.style.pointerEvents = 'none'; | div.style.pointerEvents = 'none'; | ||
return div; | return div; | ||
第182行: | 第144行: | ||
}, 10); | }, 10); | ||
timerId = setTimeout(hide, | timerId = setTimeout(hide, 15000); | ||
} | } | ||
第194行: | 第156行: | ||
} | } | ||
indicator = null; | indicator = null; | ||
}, | }, 300); | ||
clearTimeout(timerId); | clearTimeout(timerId); | ||
} | } | ||
document.addEventListener('DOMContentLoaded', show); | document.addEventListener('DOMContentLoaded', show); | ||
window.addEventListener('load', hide); | window.addEventListener('load', hide); | ||
})(); | })(); | ||
2025年6月21日 (六) 08:51的版本
/**********************
* 模块 0:vConsole 加载(移动端专用)
**********************/
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && !window.localStorage.getItem('disableVConsole')) {
var vConsoleScript = document.createElement('script');
vConsoleScript.src = 'https://cdn.bootcdn.net/ajax/libs/vConsole/3.15.1/vconsole.min.js';
vConsoleScript.onload = function() {
try {
if (window.VConsole) {
new window.VConsole();
}
} catch (e) {
alert('调试工具初始化失败,请重试或联系管理员');
}
};
vConsoleScript.onerror = function() {
alert('调试工具加载失败,请检查网络连接');
};
document.body.appendChild(vConsoleScript);
}
/**********************
* 模块 1:CSS 变量 RGB 转换
**********************/
(function () {
var cachedRgb = '';
var mo = new MutationObserver(function() {
var root = document.documentElement;
var hex = getComputedStyle(root).getPropertyValue('--background-color-base').trim();
hex = hex.replace(/^#/, '');
if (hex.length === 3) {
hex = hex.split('').map(function(c) { return c + c; }).join('');
}
if (hex.length !== 6) {
root.style.setProperty('--background-color-rgb', '0, 0, 0');
return;
}
var r = parseInt(hex.substring(0, 2), 16);
var g = parseInt(hex.substring(2, 4), 16);
var b = parseInt(hex.substring(4, 6), 16);
var rgb = r + ', ' + g + ', ' + b;
if (rgb !== cachedRgb) {
root.style.setProperty('--background-color-rgb', rgb);
cachedRgb = rgb;
}
});
mo.observe(document.documentElement, { attributes: true, attributeFilter: ['style'] });
})();
/**********************
* 模块 2:上传页引导弹窗
**********************/
if (window.mw && mw.config && mw.config.get('wgCanonicalSpecialPageName') === 'Upload') {
var pref = mw.storage.get('uploadPreference');
if (pref === 'wizard') {
window.location.href = mw.util.getUrl('Special:UploadWizard');
} else if (pref !== 'classic') {
document.addEventListener('click', function initDialog() {
document.removeEventListener('click', initDialog);
mw.loader.using(['oojs-ui-core', 'oojs-ui-widgets']).then(function() {
var UploadDialog = function() {};
UploadDialog.static = {
name: 'UploadDialog',
title: '请选择上传方式',
actions: [{ action: 'classic', label: '❌ 传统方式', flags: ['safe'] }]
};
UploadDialog.prototype.initialize = function() {
OO.ui.ProcessDialog.prototype.initialize.apply(this, arguments);
this._remember = new OO.ui.CheckboxInputWidget();
var wizardBtn = new OO.ui.ButtonWidget({
label: '✅ 上传向导',
flags: ['primary'],
href: mw.util.getUrl('Special:UploadWizard'),
target: '_self'
});
wizardBtn.on('click', function() {
if (this._remember.isSelected()) {
mw.storage.set('uploadPreference', 'wizard');
}
}.bind(this));
this.$body.append(
$('<p>').text('请选择上传方式:'),
wizardBtn.$element,
new OO.ui.FieldLayout(this._remember, {
label: '记住选择',
align: 'inline'
}).$element
);
};
UploadDialog.prototype.getActionProcess = function(action) {
if (action === 'classic') {
if (this._remember.isSelected()) {
mw.storage.set('uploadPreference', 'classic');
}
return new OO.ui.Process(function() {
this.close();
}.bind(this));
}
return OO.ui.ProcessDialog.prototype.getActionProcess.apply(this, arguments);
};
var wm = new OO.ui.WindowManager();
document.body.appendChild(wm.$element);
wm.addWindows([new UploadDialog()]);
wm.openWindow('UploadDialog');
});
});
}
}
/**********************
* 模块 3:加载指示器
**********************/
(function () {
var indicator = null;
var timerId = null;
function createIndicator() {
var div = document.createElement('div');
div.style.position = 'fixed';
div.style.width = '256px';
div.style.height = '256px';
div.style.bottom = '20px';
div.style.right = '20px';
div.style.zIndex = '99999';
div.style.background = 'url(https://wiki.ottohub.cn/images/0/02/Loading.png) center/contain no-repeat';
div.style.opacity = '0';
div.style.transition = 'opacity 300ms';
div.style.pointerEvents = 'none';
return div;
}
function show() {
if (indicator) return;
indicator = createIndicator();
document.body.appendChild(indicator);
setTimeout(function() {
indicator.style.opacity = '1';
}, 10);
timerId = setTimeout(hide, 15000);
}
function hide() {
if (!indicator) return;
indicator.style.opacity = '0';
setTimeout(function() {
if (indicator && indicator.parentNode) {
indicator.parentNode.removeChild(indicator);
}
indicator = null;
}, 300);
clearTimeout(timerId);
}
document.addEventListener('DOMContentLoaded', show);
window.addEventListener('load', hide);
})();