mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 11:44:40 +00:00
Merge pull request #400 from StroepWafel/main
automatic WISP content support
This commit is contained in:
+69
-7
@@ -612,7 +612,6 @@ export function init() {
|
||||
if (settingsState.onoff) {
|
||||
console.info("[BetterSEQTA+] Enabled");
|
||||
if (settingsState.DarkMode) document.documentElement.classList.add("dark");
|
||||
if (settingsState.iconOnlySidebar) document.body.classList.add("icon-only-sidebar");
|
||||
|
||||
document.querySelector(".legacy-root")?.classList.add("hidden");
|
||||
ObserveMenuItemPosition();
|
||||
@@ -620,16 +619,79 @@ export function init() {
|
||||
new StorageChangeHandler();
|
||||
new MessageHandler();
|
||||
|
||||
void updateAllColors();
|
||||
|
||||
window.addEventListener("hashchange", () => {
|
||||
if (settingsState.adaptiveThemeColour) void updateAllColors();
|
||||
});
|
||||
updateAllColors();
|
||||
loading();
|
||||
InjectCustomIcons();
|
||||
HideMenuItems();
|
||||
tryLoad();
|
||||
|
||||
// Auto-focus WISP direct online submission editor when pane opens
|
||||
eventManager.register(
|
||||
"wispassessmentAdded",
|
||||
{
|
||||
customCheck: (el) =>
|
||||
el.classList.contains("wispassessment") ||
|
||||
el.querySelector(".wispassessment") !== null,
|
||||
},
|
||||
(element) => {
|
||||
const wispassessment = element.classList.contains("wispassessment")
|
||||
? (element as Element)
|
||||
: element.querySelector(".wispassessment");
|
||||
if (!wispassessment) return;
|
||||
|
||||
const focusEditableBody = (iframe: HTMLIFrameElement) => {
|
||||
try {
|
||||
const doc = iframe.contentDocument;
|
||||
const win = iframe.contentWindow;
|
||||
if (doc?.body && win) {
|
||||
const editable =
|
||||
doc.body.querySelector(".cke_editable") || doc.body;
|
||||
const el = editable as HTMLElement;
|
||||
el.focus();
|
||||
const range = doc.createRange();
|
||||
range.selectNodeContents(el);
|
||||
range.collapse(true);
|
||||
const sel = win.getSelection();
|
||||
if (sel) {
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} catch (_) {}
|
||||
return false;
|
||||
};
|
||||
|
||||
const focusEditor = () => {
|
||||
const iframe = wispassessment.querySelector(".cke_wysiwyg_frame");
|
||||
if (iframe instanceof HTMLIFrameElement) {
|
||||
if (focusEditableBody(iframe)) return;
|
||||
iframe.focus();
|
||||
return;
|
||||
}
|
||||
const ckeditor = (window as any).CKEDITOR;
|
||||
if (ckeditor?.instances?.editor1) {
|
||||
try {
|
||||
ckeditor.instances.editor1.focus();
|
||||
} catch (_) {}
|
||||
}
|
||||
};
|
||||
|
||||
const iframe = wispassessment.querySelector(".cke_wysiwyg_frame");
|
||||
if (iframe instanceof HTMLIFrameElement) {
|
||||
iframe.addEventListener(
|
||||
"load",
|
||||
() => focusEditableBody(iframe),
|
||||
{ once: true },
|
||||
);
|
||||
}
|
||||
|
||||
[1000, 1200, 1500].forEach((delay) =>
|
||||
setTimeout(focusEditor, delay),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
setTimeout(() => {
|
||||
const legacyElement = document.querySelector(
|
||||
".outside-container .bottom-container",
|
||||
@@ -692,4 +754,4 @@ export function AppendElementsToDisabledPage() {
|
||||
}
|
||||
`;
|
||||
document.head.append(settingsStyle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user