MediaWiki:Gadget-LabelScan.js
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
/* global mw */
console.log('[LabelScan] gadget file loaded');
// --- robuste Ready/Bind-Mechanik ---
function bind(origin) {
try {
console.log('[LabelScan] bind from:', origin, 'state=', document.readyState);
var run = document.getElementById('ados-scan-run');
var photo = document.getElementById('ados-scan-photo');
var pick = document.getElementById('ados-scan-pick');
var file = document.getElementById('ados-scan-file');
console.log('[LabelScan] elements:', {
run: !!run, photo: !!photo, pick: !!pick, file: !!file
});
if (!run) {
console.warn('[LabelScan] kein #ados-scan-run gefunden – steht das HTML wirklich auf dieser Seite?');
return;
}
if (!run.dataset._bound) {
run.dataset._bound = '1';
run.addEventListener('click', function () {
alert('Click OK – Gadget greift!');
}, { once: true });
console.log('[LabelScan] click bound on run');
} else {
console.log('[LabelScan] already bound, skip');
}
// OPTIONAL: Buttons für Foto/Galerie testweise anklemmen
function clickInput(withCapture) {
try {
if (file) {
if (withCapture) { file.setAttribute('capture', 'environment'); }
else { file.removeAttribute('capture'); }
file.click();
}
} catch (e) {}
}
if (photo && !photo.dataset._bound) {
photo.dataset._bound = '1';
photo.addEventListener('click', function () { clickInput(true); });
console.log('[LabelScan] photo bound');
}
if (pick && !pick.dataset._bound) {
pick.dataset._bound = '1';
pick.addEventListener('click', function () { clickInput(false); });
console.log('[LabelScan] pick bound');
}
} catch (e) {
console.error('[LabelScan] bind error:', e);
}
}
// 1) Sofort versuchen (falls DOM schon bereit ist)
if (document.readyState !== 'loading') {
bind('immediate');
} else {
// 2) Klassisches DOMContentLoaded
document.addEventListener('DOMContentLoaded', function onDom() {
bind('DOMContentLoaded');
}, { once: true });
}
// 3) MediaWiki-Hook für dynamisch ersetzte Seiteninhalte
if (mw && mw.hook) {
mw.hook('wikipage.content').add(function () {
bind('mw.hook(wikipage.content)');
});
}
// 4) Fallbacks (manche Skins/Module laden später)
setTimeout(function(){ bind('timeout-250ms'); }, 250);
setTimeout(function(){ bind('timeout-1000ms'); }, 1000);
// 5) Optional: MutationObserver, falls der Inhalt später ins DOM kommt
var mo = new MutationObserver(function () {
// Versuche nur zu binden, wenn noch nicht gebunden
var run = document.getElementById('ados-scan-run');
if (run && !run.dataset._bound) {
bind('mutation');
}
});
mo.observe(document.documentElement || document.body, { childList: true, subtree: true });