更新 ColumnEdit.user.js

This commit is contained in:
2026-11-22 10:38:59 +08:00
parent 98427fc4d1
commit 62f8945765
+13 -4
View File
@@ -1,7 +1,7 @@
// ==UserScript==
// @name sxz.school Article HTML editor
// @namespace local.sxz.article-editor
// @version 1.0.0
// @version 1.1.0
// @description Add an HTML editor to article pages and submit updates through the site's API.
// @match http://sxz.school.zykj.org/index.html*
// @match https://sxz.school.zykj.org/index.html*
@@ -17,6 +17,7 @@
const BUTTON_ID = 'tm-sxz-article-edit-button';
const MODAL_ID = 'tm-sxz-article-edit-modal';
const STYLE_ID = 'tm-sxz-article-edit-style';
const FLOATING_CLASS = 'tm-sxz-floating-button';
function currentArticleId() {
const [route, query = ''] = location.hash.slice(1).split('?', 2);
@@ -108,6 +109,7 @@
style.id = STYLE_ID;
style.textContent = `
#${BUTTON_ID} { margin-left: 12px; }
#${BUTTON_ID}.${FLOATING_CLASS} { position: fixed !important; right: calc(14px + env(safe-area-inset-right, 0px)) !important; bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important; z-index: 99999 !important; margin: 0 !important; min-width: 64px; height: 40px; padding: 0 15px; border-radius: 20px; box-shadow: 0 3px 10px rgba(0,0,0,.24); }
#${MODAL_ID} { position: fixed; inset: 0; z-index: 100000; }
#${MODAL_ID} .tm-sxz-mask { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
#${MODAL_ID} .tm-sxz-wrap { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; padding: 16px; box-sizing: border-box; }
@@ -278,23 +280,30 @@
}
const footer = document.querySelector('.fix-bottom-div');
if (!footer) return;
if (existing && existing.parentElement === footer) return;
const mobile = /Android|iPhone|iPod|Mobile/i.test(navigator.userAgent)
|| window.matchMedia('(max-width: 768px)').matches;
const target = mobile || !footer ? document.body : footer;
const shouldFloat = mobile || !footer;
if (existing
&& existing.parentElement === target
&& existing.classList.contains(FLOATING_CLASS) === shouldFloat) return;
existing?.remove();
const button = document.createElement('button');
button.id = BUTTON_ID;
button.type = 'button';
button.className = 'ant-btn ant-btn-primary';
if (shouldFloat) button.classList.add(FLOATING_CLASS);
button.textContent = '编辑';
button.setAttribute('aria-label', '编辑文章 HTML');
button.addEventListener('click', openModal);
footer.appendChild(button);
target.appendChild(button);
addStyles();
}
ensureButton();
window.addEventListener('hashchange', ensureButton);
window.addEventListener('resize', ensureButton);
new MutationObserver(ensureButton).observe(document.documentElement, {
childList: true,
subtree: true