MediaWiki:Common.js
From semantic-hub.io
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
mw.loader.load('/w/index.php?title=MediaWiki:CustomExtensions&action=raw&ctype=text/javascript');
// Test Q5
mw.loader.using(['mediawiki.util']).then(function () {
if (mw.config.get('wgPageName') !== 'Item:Q5' || mw.config.get('wgAction') !== 'view') {
return;
}
const target = document.querySelector('#mw-content-text') || document.body;
if (!target) {
return;
}
const box = document.createElement('div');
box.id = 'qudt-auto-box';
box.style.border = '1px solid #c8ccd1';
box.style.background = '#f8f9fa';
box.style.padding = '12px';
box.style.margin = '12px 0';
box.style.fontFamily = 'sans-serif';
box.innerHTML = `
<h2 style="margin-top:0;">QUDT-Test</h2>
<div id="qudt-auto-status">Lade Daten für <strong>Volt</strong>...</div>
<pre id="qudt-auto-result" style="white-space:pre-wrap; margin-top:10px;"></pre>
`;
target.prepend(box);
const statusEl = document.getElementById('qudt-auto-status');
const resultEl = document.getElementById('qudt-auto-result');
const url = 'http://127.0.0.1:5000/api/v3/search?search=Volt&lang=en&types=unit';
fetch(url)
.then(function (response) {
if (!response.ok) {
throw new Error('HTTP ' + response.status);
}
return response.json();
})
.then(function (data) {
statusEl.textContent = 'Daten erfolgreich geladen.';
resultEl.textContent = JSON.stringify(data, null, 2);
})
.catch(function (error) {
statusEl.textContent = 'Fehler beim Laden.';
resultEl.textContent = error.message;
});
});
