Container Suche Implementiert
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.002
|
// @version 2026.04.003
|
||||||
// @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/*
|
||||||
@@ -26,29 +26,24 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addSelectButtons() {
|
function tryInsertButtons() {
|
||||||
const selector = getDropdownSelector();
|
const selector = getDropdownSelector();
|
||||||
if (!selector) return;
|
if (!selector) return false;
|
||||||
|
|
||||||
const dropdown = document.querySelector(selector);
|
// 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 (!dropdown) {
|
const dropdownContainer = select.closest('.btn-group.bootstrap-select');
|
||||||
console.log('Dropdown nicht gefunden:', selector);
|
if (!dropdownContainer) return false;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dropdownContainer = dropdown.closest('.btn-group.bootstrap-select');
|
const searchBox = dropdownContainer.querySelector('.bs-searchbox');
|
||||||
const searchBox = dropdownContainer?.querySelector('.bs-searchbox');
|
if (!searchBox) return false;
|
||||||
|
|
||||||
if (!searchBox) {
|
|
||||||
console.log('Searchbox nicht gefunden');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prüfe ob schon vorhanden
|
|
||||||
if (searchBox.nextElementSibling?.classList.contains('bs-actionsbox')) {
|
if (searchBox.nextElementSibling?.classList.contains('bs-actionsbox')) {
|
||||||
console.log('Select/Deselect Buttons bereits vorhanden');
|
return true; // bereits vorhanden
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const actionsBox = document.createElement('div');
|
const actionsBox = document.createElement('div');
|
||||||
@@ -61,15 +56,29 @@
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
searchBox.insertAdjacentElement('afterend', actionsBox);
|
searchBox.insertAdjacentElement('afterend', actionsBox);
|
||||||
|
|
||||||
console.log('Select/Deselect Buttons erfolgreich eingefügt');
|
console.log('Select/Deselect Buttons erfolgreich eingefügt');
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Versuche es direkt
|
function waitForElement() {
|
||||||
addSelectButtons();
|
if (tryInsertButtons()) return;
|
||||||
|
|
||||||
|
// Bootstrap Select läuft nach DOMContentLoaded — beobachte DOM-Mutationen
|
||||||
|
const observer = new MutationObserver(() => {
|
||||||
|
if (tryInsertButtons()) {
|
||||||
|
observer.disconnect();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe(document.body, { childList: true, subtree: true });
|
||||||
|
|
||||||
|
// Sicherheitsnetz: nach 10 s aufgeben
|
||||||
|
setTimeout(() => observer.disconnect(), 10000);
|
||||||
|
}
|
||||||
|
|
||||||
// Falls das Element noch nicht da ist, warte auf DOMContentLoaded
|
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') {
|
||||||
document.addEventListener('DOMContentLoaded', addSelectButtons);
|
document.addEventListener('DOMContentLoaded', waitForElement);
|
||||||
|
} else {
|
||||||
|
waitForElement();
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
Reference in New Issue
Block a user