Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
Line 8:
const QUICKSURVEYS_URL = 'https://en.wikipedia.org/w/load.php?modules=ext.quicksurveys.lib&debug=true';
const MEDIAWICK_BASE_URL = 'https://en.wikipedia.org/wiki/MediaWiki:';
// Track processed pages to prevent duplicates
let processedPages = new Set();
// Function to extract survey data from the loaded module
Line 148 ⟶ 151:
// Generate survey display when viewing userpage
function generateSurveyDisplay() {
const currentPage = mw.config.get('wgPageName');
// Prevent duplicate execution▼
const username = mw.config.get('wgUserName');
const pageKey = `${currentPage}-${Date.now()}`;
// Check if we've already processed this page recently (within 1 second)
const now = Date.now();
const recentProcessing = Array.from(processedPages).find(entry => {
const [page, timestamp] = entry.split('-');
return page === currentPage && (now - parseInt(timestamp)) < 1000;
});
if (recentProcessing) {
console.log('Survey display recently processed, skipping...');
return;
}
▲ // Prevent duplicate execution by checking for existing elements
if ($('#quicksurveys-display-box').length > 0) {
console.log('Survey display already exists, skipping...');
return;
}
// Add to processed pages
processedPages.add(`${currentPage}-${now}`);
// Clean up old entries (keep only last 10)
if (processedPages.size > 10) {
const sortedEntries = Array.from(processedPages).sort();
processedPages = new Set(sortedEntries.slice(-10));
}
Line 161 ⟶ 189:
const surveys = extractSurveyData(moduleText);
if (surveys.length === 0) {
return;
}
// Double-check that the element doesn't exist (race condition protection)
console.log('Survey display was created while fetching, skipping...');
return;
}
Line 213 ⟶ 247:
if (username && currentPage === `User:${username}`) {
//
// Auto-generate survey display on userpage
▲ if ($('#update-quicksurveys').length === 0) {
// Add a small link to manually update▼
▲ );
if ($('#update-quicksurveys').length === 0) {
▲ // Add a small link to manually update
$('#update-quicksurveys').on('click', function(e) {▼
$('#firstHeading').append($link);
▲ $('#update-quicksurveys').on('click', function(e) {
e.preventDefault();
fetchAndProcessSurveys();
});
}
}, 100); // Small delay to ensure DOM is ready
}
});
|