MediaWiki:Common.js: Unterschied zwischen den Versionen
Admin (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Admin (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| (137 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
/* Das folgende JavaScript wird für alle Benutzer geladen. */ | /* Das folgende JavaScript wird für alle Benutzer geladen. */ | ||
/* ADOS Whisky-Ratings – RatePage Frontend (ES5, Widgets + Stats + Summary, Doppel-Init-Schutz; ANON VOTING ERLAUBT) */ | /* ADOS Whisky-Ratings – RatePage Frontend (ES5, Widgets + Stats + Summary, Doppel-Init-Schutz; ANON VOTING ERLAUBT) */ | ||
mw.loader.using(['mediawiki.api', 'mediawiki.user']).then(function () { | mw.loader.using(['mediawiki.api', 'mediawiki.user']).then(function () { | ||
| Zeile 397: | Zeile 398: | ||
/* | /* --- Whisky Top-5 (multi-root, recursive, robust, namespaces, ES5) ------- */ | ||
mw.loader.using(['mediawiki. | mw.loader.using(['mediawiki.api']).then(function () { | ||
var | /* ========== Utils ========== */ | ||
function get(obj, path) { | |||
var cur = obj, i; | |||
for (i = 0; i < path.length; i++) { if (!cur || typeof cur !== 'object') return; cur = cur[path[i]]; } | |||
return cur; | |||
} | |||
function parseWeights(raw, contests) { | |||
var map = {}, parts = (raw || '').split(','), i; | |||
for (i = 0; i < parts.length; i++) { | |||
var kv = parts[i].split(':'); if (kv.length !== 2) continue; | |||
var k = kv[0].replace(/^\s+|\s+$/g, ''), v = parseFloat(kv[1]); | |||
if (!isNaN(v)) map[k] = v; | |||
} | |||
for (i = 0; i < contests.length; i++) if (typeof map[contests[i]] !== 'number') map[contests[i]] = 1; | |||
return map; | |||
} | |||
/* ========== Statusbox im Widget ========== */ | |||
function makeStatus(container, keep){ | |||
var box = container.querySelector('.whisky-top5__status'); | |||
if (!box) { | |||
box = document.createElement('div'); | |||
box.className = 'whisky-top5__status'; | |||
container.insertBefore(box, container.firstChild || null); | |||
} | |||
function line(txt){ var row = document.createElement('div'); row.textContent = txt; box.appendChild(row); box.scrollTop = box.scrollHeight; } | |||
function status(msg, append){ if (!append && !keep) box.innerHTML = ''; line(msg); /* console.log('[Top5]', msg); */ } | |||
status.done = function(delayMs){ if (keep) return; setTimeout(function(){ if (box && box.parentNode) box.parentNode.removeChild(box); }, typeof delayMs==='number'?delayMs:3000); }; | |||
return status; | |||
} | |||
/* ========== Robuste Kategorie-Auflösung ========== */ | |||
function categoryCandidates(name){ | |||
var n = (name || '').replace(/^\s+|\s+$/g,''); | |||
var v = {}, add=function(s){ if (s && !v[s]) v[s]=1; }; | |||
add(n); | |||
add(n.replace(/\u2026/g,'...')); // … -> ... | |||
add(n.replace(/\.{3}/g,'…')); // ... -> … | |||
add(n.replace(/\u2013/g,'-')); // – -> - | |||
add(n.replace(/-/g,'–')); // - -> – | |||
add(n.replace(/\s+/g,' ')); // Mehrfach-Spaces | |||
return Object.keys(v); | |||
} | |||
function resolveCategoryTitle(api, rawName){ | |||
var cands = categoryCandidates(rawName).map(function(n){ return 'Kategorie:' + n; }); | |||
return api.get({ action:'query', titles: cands.join('|'), format:'json' }).then(function(d){ | |||
var pages = get(d,['query','pages']) || {}, pid, p; | |||
for (pid in pages) if (Object.prototype.hasOwnProperty.call(pages,pid)) { p = pages[pid]; if (p && p.pageid && p.ns === 14) return p.title; } | |||
return null; | |||
}); | |||
} | |||
/* ========== Kategorien rekursiv einsammeln (inkl. Subkats, Namespaces) ========== */ | |||
function fetchCategoryMembersRecursiveSingleResolved(api, catTitle, limit, outSet, pages, nsStr){ | |||
var visited = {}, queue = [catTitle]; | |||
var cmNS = (nsStr && nsStr.trim()) ? nsStr.trim() : '0|14'; // default: Artikel+Kategorie | |||
function fetchOne(title, cont){ | |||
var params = { | |||
action: 'query', | |||
list: 'categorymembers', | |||
cmtitle: title, | |||
cmtype: 'page|subcat', | |||
cmlimit: Math.min(200, limit), | |||
format: 'json' | |||
}; | }; | ||
if (cmNS !== '*' && cmNS !== '') { | |||
params.cmnamespace = cmNS; // z.B. "0|102|14" | |||
} | |||
if (cont) params.cmcontinue = cont; | |||
return api.get(params).then(function(d){ | |||
var cms = (d.query && d.query.categorymembers) || [], i, it; | |||
for (i = 0; i < cms.length; i++) { | |||
it = cms[i]; | |||
if (it.ns !== 14) { // alles außer Kategorien zählt als Seite | |||
var pid = String(it.pageid); | |||
if (!outSet[pid] && pages.length < limit) { | |||
outSet[pid] = 1; | |||
pages.push({ pageid: pid, title: it.title }); | |||
} | |||
} else { | |||
var sub = it.title; | |||
if (!visited[sub]) { visited[sub] = 1; queue.push(sub); } | |||
} | |||
} | |||
var next = d.continue && d.continue.cmcontinue; | |||
if (next && pages.length < limit) return fetchOne(title, next); | |||
}); | |||
} | |||
function loop(){ | |||
if (pages.length >= limit || !queue.length) return Promise.resolve(); | |||
var next = queue.shift(); | |||
if (visited[next]) return loop(); | |||
visited[next] = 1; | |||
return fetchOne(next).then(loop); | |||
} | |||
return loop(); | |||
} | |||
function fetchCategoryMembersRecursiveMulti(rootCats, limit, status, nsStr){ | |||
var api = new mw.Api(); | |||
var pages = [], outSet = {}; | |||
var idx = 0; | |||
function next(){ | |||
if (idx >= rootCats.length || pages.length >= limit) return Promise.resolve(pages); | |||
var raw = rootCats[idx++]; if (!raw) return next(); | |||
return resolveCategoryTitle(api, raw).then(function(resolved){ | |||
if (!resolved) { status('Kategorie nicht gefunden: "' + raw + '"', true); return next(); } | |||
status('Kategorie erkannt: ' + resolved + ' – sammle …', true); | |||
var before = pages.length; | |||
return fetchCategoryMembersRecursiveSingleResolved(api, resolved, limit, outSet, pages, nsStr).then(function(){ | |||
var added = pages.length - before; | |||
status('→ gefunden in "' + resolved + '": ' + added + ' Seiten (kumuliert: ' + pages.length + ')', true); | |||
return next(); | |||
}); | |||
}); | |||
} | |||
return next(); | |||
} | |||
/* ========== Ratings laden / auswerten ========== */ | |||
function fetchRatingsForContest(pageIds, contest, includeHidden) { | |||
var api = new mw.Api(), res = {}, i, chunk = 50, chunks = []; | |||
for (i = 0; i < pageIds.length; i += chunk) chunks.push(pageIds.slice(i, i + chunk)); | |||
function step(idx) { | |||
if (idx >= chunks.length) return Promise.resolve(res); | |||
var ids = chunks[idx]; | |||
return api.get({ | |||
action:'query', prop:'pagerating', pageids: ids.join('|'), | |||
prcontest: contest, format:'json' | |||
}).then(function(d){ | |||
var pages = get(d,['query','pages']) || {}, pid, pr, hist, k, total, sum, s, c; | |||
for (pid in pages) if (Object.prototype.hasOwnProperty.call(pages,pid)) { | |||
if (!res[pid]) res[pid] = { avg:null, total:0 }; | |||
pr = pages[pid].pagerating; | |||
if (pr && (includeHidden || !('canSee' in pr) || pr.canSee !== 0)) { | |||
hist = pr.pageRating || {}; total=0; sum=0; | |||
for (k in hist) if (Object.prototype.hasOwnProperty.call(hist,k)) { | |||
s = parseInt(k,10); c = parseInt(hist[k],10); | |||
if (!isNaN(s) && !isNaN(c)) { total += c; sum += s*c; } | |||
} | |||
if (total > 0) res[pid] = { avg: Math.round((sum/total)*10)/10, total: total }; | |||
} | |||
} | |||
return step(idx + 1); | |||
}, function(){ return step(idx + 1); }); | |||
} | |||
return step(0); | |||
} | |||
function computeOverall(entry, contests, weights) { | |||
var wSum=0, wAvgSum=0, present=0, totalVotes=0, i, sc, w; | |||
for (i=0;i<contests.length;i++){ | |||
sc = entry.scores[contests[i]]; | |||
if (sc && sc.avg !== null) { w = (typeof weights[contests[i]]==='number') ? weights[contests[i]] : 1; wSum+=w; wAvgSum+=sc.avg*w; present++; } | |||
if (sc && sc.total) totalVotes += sc.total; | |||
} | |||
entry.totalVotes = totalVotes; | |||
entry.overall = (present>0 && wSum>0) ? Math.round((wAvgSum/wSum)*10)/10 : null; | |||
} | |||
/* ========== Render ========== */ | |||
function renderTopN(container, rows, N, minVotes) { | |||
var keep = (container.getAttribute && container.getAttribute('data-keep-status') === 'true'); | |||
var statusBox = keep ? container.querySelector('.whisky-top5__status') : null; | |||
rows = rows.filter(function(r){ return (r.overall !== null) && (r.totalVotes >= minVotes); }); | |||
rows.sort(function(a,b){ | |||
if ( | if (a.overall===null && b.overall!==null) return 1; | ||
if (a.overall!==null && b.overall===null) return -1; | |||
if (b.overall!==a.overall) return b.overall - a.overall; | |||
if (b.totalVotes!==a.totalVotes) return b.totalVotes - a.totalVotes; | |||
return a.title.localeCompare(b.title); | |||
}); | |||
rows = rows.slice(0, N); | |||
while (container.firstChild) container.removeChild(container.firstChild); | |||
if (statusBox) container.appendChild(statusBox); | |||
if (!rows.length) { container.appendChild(document.createTextNode('Noch keine Bewertungen vorhanden.')); return; } | |||
var frag = document.createDocumentFragment(), i, r, item, rank, name, a, right, mini, track, fill, val, votes; | |||
for (i=0;i<rows.length;i++){ | |||
r = rows[i]; | |||
item = document.createElement('div'); item.className = 'whisky-top5__item'; | |||
rank = document.createElement('div'); rank.className = 'whisky-top5__rank'; rank.textContent = (i+1); | |||
name = document.createElement('div'); name.className = 'whisky-top5__name'; | |||
a = document.createElement('a'); a.href = mw.util.getUrl(r.title); a.textContent = r.title; name.appendChild(a); | |||
if ( | right = document.createElement('div'); right.style.minWidth = '160px'; | ||
' | mini = document.createElement('div'); mini.className = 'whisky-mini'; | ||
track = document.createElement('div'); track.className = 'whisky-mini__track'; | |||
fill = document.createElement('div'); fill.className = 'whisky-mini__fill'; | |||
fill.style.width = Math.max(0, Math.min(100, (r.overall/10)*100)) + '%'; | |||
val = document.createElement('span'); val.className = 'whisky-mini__val'; | |||
} | val.textContent = (r.overall.toFixed ? r.overall.toFixed(1) : (Math.round(r.overall*10)/10)); | ||
track.appendChild(fill); mini.appendChild(track); mini.appendChild(val); | |||
votes = document.createElement('div'); votes.className = 'whisky-top5__votes'; | |||
votes.textContent = r.totalVotes + ' Stimmen'; | |||
right.appendChild(mini); right.appendChild(votes); | |||
item.appendChild(rank); item.appendChild(name); item.appendChild(right); | |||
frag.appendChild(item); | |||
} | |||
container.appendChild(frag); | |||
} | |||
/* ========== Boot ========== */ | |||
function bootTop5(root) { | |||
var nodes = (root || document).querySelectorAll('.whisky-top5'); | |||
if (!nodes.length) return; | |||
for (var n=0;n<nodes.length;n++) (function(container){ | |||
if (container.getAttribute('data-top5-init')==='1') return; | |||
container.setAttribute('data-top5-init','1'); | |||
var rawCats = container.getAttribute('data-categories') || container.getAttribute('data-category') || ''; | |||
var parts = rawCats.split(/\n|;/), rootCats = [], i; | |||
for (i=0;i<parts.length;i++){ var nm = parts[i].replace(/^\s+|\s+$/g,''); if (nm) rootCats.push(nm); } | |||
if (!rootCats.length) { container.textContent = 'Keine Kategorien angegeben.'; return; } | |||
var lim = parseInt(container.getAttribute('data-limit') || '2000', 10); | |||
var cnt = parseInt(container.getAttribute('data-count') || '5', 10); | |||
var minVotes = parseInt(container.getAttribute('data-min-votes') || '1', 10); | |||
var includeHidden = (container.getAttribute('data-include-hidden') === 'true'); | |||
var nsStr = container.getAttribute('data-namespaces') || '0|14'; | |||
var rawC = container.getAttribute('data-contests') || 'NASE,GESCHMACK,ABGANG,GESAMTEINDRUCK'; | |||
var cParts = rawC.split(','), contests = [], seen = {}; | |||
for (i=0;i<cParts.length;i++){ var c = cParts[i].replace(/^\s+|\s+$/g,''); if (c && !seen[c]){ contests.push(c); seen[c]=1; } } | |||
var weights = parseWeights(container.getAttribute('data-weights') || '', contests); | |||
var keep = (container.getAttribute('data-keep-status') === 'true'); | |||
function status(){ /* Debug-Ausgabe deaktiviert */ } | |||
status('Sammle Seiten …'); | |||
fetchCategoryMembersRecursiveMulti(rootCats, lim, status, nsStr).then(function(members){ | |||
status('Gefundene Seiten gesamt: ' + (members ? members.length : 0) + ' – lade Bewertungen …', true); | |||
if (!members || !members.length) { status('Keine passenden Seiten gefunden.', true); return; } | |||
var pageIds = [], byId = {}, i; | |||
for (i=0;i<members.length;i++){ pageIds.push(members[i].pageid); byId[members[i].pageid] = { pageid: members[i].pageid, title: members[i].title, scores: {} }; } | |||
function loopContest(idx){ | |||
if (idx >= contests.length) return Promise.resolve(); | |||
var contest = contests[idx]; | |||
return fetchRatingsForContest(pageIds, contest, includeHidden).then(function(map){ | |||
var pid; for (pid in map) if (Object.prototype.hasOwnProperty.call(map,pid)) byId[pid].scores[contest] = map[pid]; | |||
return loopContest(idx + 1); | |||
}); | |||
} | |||
function buildAndRender(){ | |||
var rows = [], pid, e, withVotes = 0; | |||
for (pid in byId) if (Object.prototype.hasOwnProperty.call(byId,pid)) { | |||
e = byId[pid]; computeOverall(e, contests, weights); rows.push(e); | |||
if (e.totalVotes > 0 && e.overall !== null) withVotes++; | |||
} | |||
if (withVotes === 0 && !includeHidden) { | |||
status('Keine sichtbaren Stimmen – zweiter Versuch (versteckte Ergebnisse mitzählen) …', true); | |||
includeHidden = true; | |||
return loopContest(0).then(buildAndRender); | |||
} | |||
renderTopN(container, rows, cnt, minVotes); | |||
status.done(keep ? 0 : 3000); | |||
} | |||
loopContest(0).then(buildAndRender).catch(function(){ status('Topliste konnte nicht geladen werden.', true); }); | |||
}).catch(function(){ status('Topliste konnte nicht geladen werden.'); }); | |||
})(nodes[n]); | |||
} | |||
if (document.readyState === 'loading') { | |||
document.addEventListener('DOMContentLoaded', function(){ bootTop5(document); }); | |||
} else { bootTop5(document); } | |||
mw.hook('wikipage.content').add(function($c){ if($c && $c[0]) bootTop5($c[0]); }); | |||
}); | |||
/* Render star ratings from data-rating on .rating elements (0..5, step .5) */ | |||
mw.hook('wikipage.content').add(function($content){ | |||
$content.find('.rating').each(function(){ | |||
var el = this, val = parseFloat(el.getAttribute('data-rating') || '0'); | |||
if (isNaN(val)) val = 0; | |||
val = Math.max(0, Math.min(5, val)); | |||
el.style.setProperty('--stars', (val).toString()); | |||
el.setAttribute('aria-label', val + ' von 5 Sternen'); | |||
el.setAttribute('title', val + ' von 5 Sternen'); | |||
}); | |||
}); | |||
// Force light color-scheme at document level (helps Mobile Safari) | |||
mw.loader.using('mediawiki.util').then(function () { | |||
var m = document.querySelector('meta[name="color-scheme"]'); | |||
if (!m) { | |||
m = document.createElement('meta'); | |||
m.name = 'color-scheme'; | |||
m.content = 'light'; | |||
document.head.appendChild(m); | |||
} else { | |||
m.content = 'light'; | |||
} | |||
}); | |||
function isFlagTrue(v){ | |||
if (v == null) return false; | |||
v = String(v).trim().toLowerCase(); | |||
return v === 'true' || v === '1' || v === 'yes'; | |||
} | |||
// Gesamtzahl unter der Legende einfügen (im Diagramm-Block, nicht im Canvas!) | |||
function addTotalBelowLegend(chart, block) { | |||
try { | |||
if (!chart || !block) return; | |||
const total = chart.data.datasets.reduce((sum, ds) => | |||
sum + (ds.data || []).reduce((a, b) => a + (parseFloat(b) || 0), 0) | |||
, 0); | |||
const oldInfo = block.querySelector(':scope > .chart-total-info'); | |||
if (oldInfo) oldInfo.remove(); | |||
const info = document.createElement('div'); | |||
info.className = 'chart-total-info'; | |||
info.textContent = 'Gesamte Anzahl aller eigenen Abfüllungen: ' + total; | |||
info.style.textAlign = 'center'; | |||
info.style.fontWeight = 'bold'; | |||
info.style.fontSize = '1.05em'; | |||
info.style.marginTop = '0.5rem'; | |||
info.style.marginBottom = '0.5rem'; | |||
info.style.color = '#444'; | |||
block.appendChild(info); | |||
} catch(e) { console.warn('[addTotalBelowLegend]', e); } | |||
} | |||
/* === ADOS Multi-Serien-Chart (Chart.js) ============================= * | |||
* Lädt Chart.js sicher (asynchron) und baut Diagramme aus Cargo-Tabellen. | |||
* Benötigt im Artikel: <div class="ados-chart-multi"> + Cargo-Query als |format=table | |||
* ==================================================================== */ | |||
(function () { | |||
var _chartReady = null; | |||
function ensureChartJS() { | |||
if (_chartReady) return _chartReady; | |||
_chartReady = new Promise(function (resolve, reject) { | |||
if (window.Chart) return resolve(); | |||
var s = document.createElement('script'); | |||
s.src = 'https://cdn.jsdelivr.net/npm/chart.js'; | |||
s.async = true; | |||
s.onload = function(){ resolve(); }; | |||
s.onerror = function(){ console.error('Chart.js konnte nicht geladen werden'); reject(); }; | |||
document.head.appendChild(s); | |||
}); | |||
return _chartReady; | |||
} | |||
var ADOS_COLORS = { | |||
'A Dream of Scotland': '#C2410C', | |||
'A Dream of Ireland': '#15803D', | |||
'A Dream of... – Der Rest der Welt': '#1D4ED8', | |||
'Friendly Mr. Z': '#9333EA', | |||
'Die Whisky Elfen': '#0891B2', | |||
'The Fine Art of Whisky': '#CA8A04' | |||
}; | |||
var COLOR_CYCLE = ['#2563eb','#16a34a','#f97316','#dc2626','#a855f7','#0ea5e9','#f59e0b','#10b981']; | |||
function toYear(x){ | |||
var n = parseInt(String(x).replace(/[^\d]/g,''),10); | |||
return isFinite(n) ? n : null; | |||
} | |||
function getColor(name, used){ | |||
if (ADOS_COLORS[name]) return ADOS_COLORS[name]; | |||
var i = used.size % COLOR_CYCLE.length; | |||
used.add(name); | |||
return COLOR_CYCLE[i]; | |||
} | |||
function buildDatasetsFromTable(tbl){ | |||
var rows = Array.from(tbl.querySelectorAll('tr')); | |||
if (rows.length < 2) return { labels:[], datasets:[] }; | |||
var yearsSet = new Set(); | |||
var bySeries = new Map(); | |||
rows.slice(1).forEach(function(tr){ | |||
var tds = tr.querySelectorAll('td,th'); | |||
if (tds.length < 3) return; | |||
var y = toYear(tds[0].textContent.trim()); | |||
var s = tds[1].textContent.trim(); | |||
var v = parseFloat(tds[2].textContent.replace(',','.')) || 0; | |||
if (y == null) return; | |||
yearsSet.add(y); | |||
if (!bySeries.has(s)) bySeries.set(s, new Map()); | |||
bySeries.get(s).set(y, v); | |||
}); | |||
var years = Array.from(yearsSet).sort(function(a,b){return a-b;}); | |||
var used = new Set(); | |||
var labels = years.map(String); | |||
var datasets = Array.from(bySeries.entries()).map(function(entry){ | |||
var name = entry[0], yearMap = entry[1]; | |||
var data = years.map(function(y){ return yearMap.get(y) || 0; }); | |||
var color = getColor(name, used); | |||
return { | |||
label: name, | |||
data: data, | |||
borderColor: color, | |||
backgroundColor: color + '80', | |||
tension: 0.25, | |||
pointRadius: 3 | |||
}; | |||
}); | |||
return { labels: labels, datasets: datasets }; | |||
} | |||
function renderOne(block){ | |||
if (block.dataset.rendered === '1') return; | |||
var el = block.nextElementSibling, tbl = null, wrapToHide = null; | |||
while (el) { | |||
if (/^H[1-6]$/.test(el.tagName) || (el.classList && el.classList.contains('ados-chart-multi'))) break; | |||
if (el.tagName === 'TABLE') { | |||
tbl = el; | |||
} else if (el.querySelector) { | |||
var t = el.querySelector('table'); | |||
if (t) tbl = t; | |||
} | } | ||
if (tbl) { | |||
wrapToHide = tbl.parentElement; | |||
if ( | break; | ||
} | } | ||
el = el.nextElementSibling; | |||
} | |||
if (!tbl) return; | |||
var out = buildDatasetsFromTable(tbl); | |||
if (!out.labels.length || !out.datasets.length) return; | |||
var hide = (block.dataset.hideTable || '').toLowerCase() === 'true'; | |||
if (hide) { | |||
var onlyTable = wrapToHide && wrapToHide.children.length === 1 && wrapToHide.firstElementChild === tbl; | |||
if (onlyTable) { | |||
wrapToHide.setAttribute('aria-hidden','true'); | |||
wrapToHide.style.display = 'none'; | |||
} else { | |||
tbl.setAttribute('aria-hidden','true'); | |||
tbl.style.display = 'none'; | |||
} | } | ||
} | |||
var wrap = document.createElement('div'); | |||
wrap.style.position = 'relative'; | |||
wrap.style.width = '100%'; | |||
wrap.style.height = block.dataset.height || (window.matchMedia('(min-width:768px)').matches ? '450px' : '300px'); | |||
var canvas = document.createElement('canvas'); | |||
wrap.appendChild(canvas); | |||
block.innerHTML = ''; | |||
block.appendChild(wrap); | |||
var type = (block.dataset.type || 'line').toLowerCase(); | |||
var title = block.dataset.title || ''; | |||
var cumulative = (block.dataset.cumulative || '').toLowerCase() === 'true'; | |||
if (cumulative) { | |||
out.datasets = out.datasets.map(function(ds){ | |||
var acc = 0; | |||
return Object.assign({}, ds, { | |||
data: ds.data.map(function(v){ acc += v; return acc; }) | |||
}); | |||
}); | |||
} | |||
ensureChartJS().then(function(){ | |||
const chart = new Chart(canvas.getContext('2d'), { | |||
type: type, | |||
data: { labels: out.labels, datasets: out.datasets }, | |||
options: { | |||
responsive: true, | |||
maintainAspectRatio: false, | |||
interaction: { mode: 'nearest', intersect: false }, | |||
plugins: { | |||
legend: { position: 'bottom', labels: { font: { size: 13 }, boxWidth: 20 } }, | |||
title: { display: !!title, text: title, font: { size: 16 } }, | |||
tooltip:{ backgroundColor: 'rgba(0,0,0,0.8)', titleFont: {size:14}, bodyFont: {size:13} } | |||
}, | |||
scales: { | |||
x: { ticks: { font: { size: 12 } } }, | |||
y: { beginAtZero: true, ticks: { precision: 0, font: { size: 12 } } } | |||
} | } | ||
} | } | ||
}); | |||
const hideTotal = (block.dataset.hideTotal || '').toLowerCase() === 'true'; | |||
const oldInfo = block.querySelector(':scope > .chart-total-info'); | |||
if (oldInfo) oldInfo.remove(); | |||
if (!hideTotal) { | |||
addTotalBelowLegend(chart, block); | |||
if (window.ResizeObserver) { | |||
const obs = new ResizeObserver(() => addTotalBelowLegend(chart, block)); | |||
obs.observe(chart.canvas); | |||
chart.$adosTotalObserver = obs; | |||
} | } | ||
} | } | ||
function | |||
block.dataset.rendered = '1'; | |||
}); | |||
} | |||
function boot($scope){ | |||
var blocks = ($scope && $scope[0] ? $scope[0] : document).querySelectorAll('.ados-chart-multi'); | |||
if (!blocks.length) return; | |||
} | ensureChartJS().then(function(){ blocks.forEach(renderOne); }); | ||
function | } | ||
if (window.mw && mw.hook) { | |||
mw.hook('wikipage.content').add(boot); | |||
} else { | |||
(document.readyState === 'loading') | |||
? document.addEventListener('DOMContentLoaded', function(){ boot(); }) | |||
: boot(); | |||
} | |||
})(); | |||
// ==========================Scan================================== | |||
mw.loader.using('mediawiki.util').then(function () { | |||
if (mw.config.get('wgPageName') !== 'LabelScan') return; | |||
mw.loader.load('/index.php?title=MediaWiki:Gadget-LabelScan.js&action=raw&ctype=text/javascript'); | |||
mw.loader.load('/index.php?title=MediaWiki:Gadget-LabelScan.css&action=raw&ctype=text/css', 'text/css'); | |||
}); | |||
// ==========================ScanApp================================== | |||
/* ==== PWA: Manifest + Service Worker + Install-Button (ES5) ==== */ | |||
/* Manifest einbinden */ | |||
(function () { | |||
var link = document.createElement("link"); | |||
link.rel = "manifest"; | |||
link.href = "/app/labelscan/manifest.webmanifest"; | |||
document.head.appendChild(link); | |||
})(); | |||
/* Service Worker registrieren (nur wenn vorhanden) */ | |||
(function () { | |||
if ("serviceWorker" in navigator) { | |||
navigator.serviceWorker.register("/app/labelscan/sw.js")["catch"](function () {}); | |||
} | |||
})(); | |||
/* Install-Button steuern (Button-ID: ados-install) */ | |||
(function () { | |||
var installPrompt = null; | |||
window.addEventListener("beforeinstallprompt", function (e) { | |||
try { e.preventDefault(); } catch (ex) {} | |||
installPrompt = e; | |||
var btn = document.getElementById("ados-install"); | |||
if (btn) btn.style.display = "inline-block"; | |||
}); | |||
function onReady(fn){ if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", fn); else fn(); } | |||
onReady(function () { | |||
var btn = document.getElementById("ados-install"); | |||
if (!btn) return; | |||
btn.addEventListener("click", function () { | |||
if (!installPrompt) return; | |||
try { installPrompt.prompt(); } catch (ex) {} | |||
installPrompt = null; | |||
btn.style.display = "none"; | |||
}); | |||
}); | |||
})(); | |||
if ('serviceWorker' in navigator) { | |||
navigator.serviceWorker.register('/app/labelscan/sw.js').catch(function(){}); | |||
} | |||
// ============================================================ | |||
mw.loader.using('mediawiki.util').then(function () { | |||
function checkNeuBadges() { | |||
var badges = document.querySelectorAll('.ados-neu-badge'); | |||
var now = new Date(); | |||
badges.forEach(function (badge) { | |||
var expiry = badge.getAttribute('data-expiry'); | |||
if (!expiry) return; | |||
var expiryDate = new Date(expiry + "T23:59:59"); | |||
if (now > expiryDate) { | |||
badge.style.display = "none"; | |||
} | } | ||
}); | |||
} | |||
if (document.readyState === "loading") { | |||
document.addEventListener("DOMContentLoaded", checkNeuBadges); | |||
} else { | |||
checkNeuBadges(); | |||
} | } | ||
}); | }); | ||
// ============================================================ | |||
mw.loader.load('/wiki/MediaWiki:WhiskybaseBatch.js?action=raw&ctype=text/javascript'); | |||