MediaWiki:Common.js
Agros urbe non clamaten
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)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using(['mediawiki.api', 'mediawiki.util'], function () {
const api = new mw.Api();
// Only run this script on a specific page
if (mw.config.get('wgPageName') !== 'Wiki_Visualized') {
return;
}
async function fetchAndSimulateEdits() {
let apcontinue = null; // Pagination token
let simulatedEdits = []; // Store simulated edits locally
do {
// Fetch a batch of pages
const response = await api.get({
action: 'query',
list: 'allpages',
aplimit: 'max', // Maximum number of pages per batch
apcontinue: apcontinue,
});
const pages = response.query.allpages;
var newContent = "{{#network:Main Page"
// Iterate through each page
for (const page of pages) {
const title = page.title;
//console.log(`Simulating edit for page: ${title}`);
try {
// Fetch the current content of the page
const contentResponse = await api.get({
action: 'query',
prop: 'revisions',
titles: title,
rvslots: 'main',
rvprop: 'content',
});
newContent += ("|"+title);
// Simulate the edit (example: appending text)
//const newContent = `${oldContent}\n\nThis content would have been added by a script!`;
// Log the simulated change
//simulatedEdits.push({ title, oldContent, newContent });
console.log(`Simulated edit for ${title}:\n${newContent}`);
} catch (error) {
console.error(`Error simulating edit for ${title}:`, error);
}
newContent+="}}"
const contentArea = document.getElementById('mw-content-text');
if (contentArea) {
// Save the original content (optional)
const originalContent = contentArea.innerHTML;
// Modify the content locally
contentArea.innerHTML += `
{<div style="border: 2px solid red; padding: 10px; margin-top: 20px;">
<p>`+newContent+`</p>
</div>}
`;
}
// Get the next batch of pages if available
apcontinue = response.continue?.apcontinue || null;
} while (apcontinue);
console.log('Finished simulating edits. Here are the results:', simulatedEdits);
}
// Call the function
fetchAndSimulateEdits();
});