84 lines
3.0 KiB
JavaScript
84 lines
3.0 KiB
JavaScript
// ==UserScript==
|
|
// @name academyFIVE::AddSelectBox
|
|
// @namespace dakp/academyfive
|
|
// @version 2026.04.003
|
|
// @description Füge Selectbox für Kohorten/Planungsgruppen hinzu
|
|
// @author Dims Akpan
|
|
// @match https://a5.fhdw-hannover.de/*
|
|
// @match https://a5.fhdw.de/*
|
|
// @match https://fhdw.academyfive-preview.net/*
|
|
// @match https://fhdw-hannover.academyfive-preview.net/*
|
|
// @grant none
|
|
// @icon https://www.academyfive.com/typo3conf/ext/sitepackage/Resources/Public/build/assets/images/favicon-academyfive.ico
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
function getDropdownSelector() {
|
|
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() {
|
|
const selector = getDropdownSelector();
|
|
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;
|
|
|
|
const dropdownContainer = select.closest('.btn-group.bootstrap-select');
|
|
if (!dropdownContainer) return false;
|
|
|
|
const searchBox = dropdownContainer.querySelector('.bs-searchbox');
|
|
if (!searchBox) return false;
|
|
|
|
if (searchBox.nextElementSibling?.classList.contains('bs-actionsbox')) {
|
|
return true; // bereits vorhanden
|
|
}
|
|
|
|
const actionsBox = document.createElement('div');
|
|
actionsBox.className = 'bs-actionsbox';
|
|
actionsBox.innerHTML = `
|
|
<div class="btn-group btn-group-sm btn-block">
|
|
<button type="button" class="actions-btn bs-select-all btn btn-default">Alles auswählen</button>
|
|
<button type="button" class="actions-btn bs-deselect-all btn btn-default">Nichts auswählen</button>
|
|
</div>
|
|
`;
|
|
|
|
searchBox.insertAdjacentElement('afterend', actionsBox);
|
|
console.log('Select/Deselect Buttons erfolgreich eingefügt');
|
|
return true;
|
|
}
|
|
|
|
function waitForElement() {
|
|
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);
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', waitForElement);
|
|
} else {
|
|
waitForElement();
|
|
}
|
|
})(); |