Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
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 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...');
▲ // 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) {
// Double-check that the element doesn't exist (race condition protection)
console.log('Survey display was created while fetching, skipping...');
return;
}
Line 190 ⟶ 224:
});
// Insert
const $content = $('#mw-content-text');
▲ } else {
▲ }
})
.catch(error => {
Line 213 ⟶ 242:
if (username && currentPage === `User:${username}`) {
//
// Auto-generate survey display on userpage
}, 100); // Small delay to ensure DOM is ready
▲ if ($('#update-quicksurveys').length === 0) {
▲ );
▲ e.preventDefault();
▲ });
▲ }
}
});
|