Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
(3 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');
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
console.log('Survey display already exists, skipping...');
}
// 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));
}
console.log('Generating survey display for userpage...');
Line 155 ⟶ 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 160 ⟶ 200:
// Create a display box on the userpage
const $surveyBox = $('<div>')
.attr('id', 'quicksurveys-display-box')
.css({
'border': '1px solid #a2a9b1',
Line 183 ⟶ 224:
});
// Insert
const $content = $('#mw-content-text');
▲ if ($firstPara.length) {
▲ } else {
▲ }
})
.catch(error => {
Line 206 ⟶ 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();
▲ });
▲ }
}
});
|