MediaWiki:Common.js: Difference between revisions
From semantic-hub.io
No edit summary Tag: Manual revert |
YvonneDHBW (talk | contribs) No edit summary Tag: Reverted |
||
| Line 1: | Line 1: | ||
mw.loader.load('/w/index.php?title=MediaWiki:CustomExtensions&action=raw&ctype=text/javascript'); | 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; | |||
}); | |||
}); | |||
Revision as of 19:53, 23 April 2026
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;
});
});
