Warten bis Frame fertig Funktion; Refacoring
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name academyFIVE::AddSelectBox
|
// @name academyFIVE::AddSelectBox
|
||||||
// @namespace dakp/academyfive
|
// @namespace dakp/academyfive
|
||||||
// @version 2026.04.003
|
// @version 2026.04.005
|
||||||
// @description Füge Selectbox für Kohorten/Planungsgruppen hinzu
|
// @description Füge Selectbox für Kohorten/Planungsgruppen hinzu
|
||||||
// @author Dims Akpan
|
// @author Dims Akpan
|
||||||
// @match https://a5.fhdw-hannover.de/*
|
// @match https://a5.fhdw-hannover.de/*
|
||||||
@@ -15,25 +15,10 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function getDropdownSelector() {
|
// ─── Gemeinsame Hilfsfunktionen ───────────────────────────────────────────
|
||||||
const url = window.location.href;
|
|
||||||
if (url.includes('/course/planning-group/list')) {
|
|
||||||
return 'select[name="cohort-ids[]"]';
|
|
||||||
}
|
|
||||||
if (url.includes('/course/list')) {
|
|
||||||
return 'select[name="planningGroupIds[]"]';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function tryInsertButtons() {
|
function insertSelectButtons(selectSelector) {
|
||||||
const selector = getDropdownSelector();
|
const select = document.querySelector(selectSelector);
|
||||||
if (!selector) return false;
|
|
||||||
|
|
||||||
// Bootstrap Select wraps the <select> in .btn-group.bootstrap-select —
|
|
||||||
// suche die searchbox direkt über den select-Namen um sicherzustellen,
|
|
||||||
// dass Bootstrap Select bereits initialisiert hat
|
|
||||||
const select = document.querySelector(selector);
|
|
||||||
if (!select) return false;
|
if (!select) return false;
|
||||||
|
|
||||||
const dropdownContainer = select.closest('.btn-group.bootstrap-select');
|
const dropdownContainer = select.closest('.btn-group.bootstrap-select');
|
||||||
@@ -56,29 +41,66 @@
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
searchBox.insertAdjacentElement('afterend', actionsBox);
|
searchBox.insertAdjacentElement('afterend', actionsBox);
|
||||||
console.log('Select/Deselect Buttons erfolgreich eingefügt');
|
console.log('Select/Deselect Buttons eingefügt für:', selectSelector);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function waitForElement() {
|
function waitAndInsert(tryFn) {
|
||||||
if (tryInsertButtons()) return;
|
if (tryFn()) return;
|
||||||
|
|
||||||
// Bootstrap Select läuft nach DOMContentLoaded — beobachte DOM-Mutationen
|
|
||||||
const observer = new MutationObserver(() => {
|
const observer = new MutationObserver(() => {
|
||||||
if (tryInsertButtons()) {
|
if (tryFn()) observer.disconnect();
|
||||||
observer.disconnect();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
observer.observe(document.body, { childList: true, subtree: true });
|
observer.observe(document.body, { childList: true, subtree: true });
|
||||||
|
|
||||||
// Sicherheitsnetz: nach 10 s aufgeben
|
// Polling für initialen Seitenaufruf (Bootstrap Select initialisiert sich
|
||||||
setTimeout(() => observer.disconnect(), 10000);
|
// asynchron nach DOMContentLoaded)
|
||||||
|
let attempts = 0;
|
||||||
|
const poll = setInterval(() => {
|
||||||
|
attempts++;
|
||||||
|
if (tryFn() || attempts >= 50) {
|
||||||
|
clearInterval(poll);
|
||||||
|
if (attempts >= 50) observer.disconnect();
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── /course/list ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
function courseList_tryInsert() {
|
||||||
|
return insertSelectButtons('select[name="planningGroupIds[]"]');
|
||||||
|
}
|
||||||
|
|
||||||
|
function courseList_init() {
|
||||||
|
waitAndInsert(courseList_tryInsert);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── /course/planning-group/list ──────────────────────────────────────────
|
||||||
|
|
||||||
|
function planningGroupList_tryInsert() {
|
||||||
|
return insertSelectButtons('select[name="cohort-ids[]"]');
|
||||||
|
}
|
||||||
|
|
||||||
|
function planningGroupList_init() {
|
||||||
|
waitAndInsert(planningGroupList_tryInsert);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Routing ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
const url = window.location.href;
|
||||||
|
|
||||||
|
if (url.includes('/course/planning-group/list')) {
|
||||||
|
planningGroupList_init();
|
||||||
|
} else if (url.includes('/course/list')) {
|
||||||
|
courseList_init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') {
|
||||||
document.addEventListener('DOMContentLoaded', waitForElement);
|
document.addEventListener('DOMContentLoaded', init);
|
||||||
} else {
|
} else {
|
||||||
waitForElement();
|
init();
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
Reference in New Issue
Block a user