Files
NiceQuote/assets/manage.js

78 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* NiceQuote 后台「引用管理」
*
* 只做两件事:危险操作二次确认、深色模式跟随。
* 其余(筛选、分页、修改、删除)都是普通链接 / 表单 + 302,不依赖脚本。
*/
(function () {
'use strict';
/* ---------- 深色跟随 ----------
* NewAdmin 的 .dark 加在 #newadmin 上,而面板页的内容不在它的子树里,
* 光靠 CSS 祖先选择器吃不到,这里读一次类名把 .nq-dark 补到 .nq-adm 上。 */
(function () {
var root = document.querySelector('.nq-adm');
if (!root) {
return;
}
function isDark() {
var admin = document.getElementById('newadmin');
if (admin && /(^|\s)dark(\s|$)/.test(admin.className)) {
return true;
}
if (document.documentElement.classList.contains('dark')
|| document.body.classList.contains('dark')) {
return true;
}
if (admin) {
return false;
}
try {
return window.matchMedia('(prefers-color-scheme: dark)').matches;
} catch (e) {
return false;
}
}
function sync() {
root.classList.toggle('nq-dark', isDark());
}
sync();
var admin = document.getElementById('newadmin');
if (admin && window.MutationObserver) {
new MutationObserver(sync).observe(admin, { attributes: true, attributeFilter: ['class'] });
}
try {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', sync);
} catch (e) {
// 老浏览器没有 addEventListener,忽略
}
})();
/* ---------- 危险操作二次确认 ---------- */
document.addEventListener('submit', function (event) {
var form = event.target;
if (!form || form.tagName !== 'FORM') {
return;
}
var message = form.getAttribute('data-confirm');
if (message && !window.confirm(message)) {
event.preventDefault();
}
});
})();