Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
Line 1:
// Wikipedia QuickSurveys Tracker for common.js
// Fetches
(function() {
Line 63:
url: MEDIAWICK_BASE_URL + formatLinkKey(survey.link)
});
}
Line 146 ⟶ 94:
}
// Display survey information in console/notification instead of updating userpage
function
if (surveys.length === 0) {
mw.notify('No surveys found in QuickSurveys module', { type: 'info' });
return;
}
let notificationText = `Found ${surveys.length} survey(s): `;
surveys.forEach((survey, index) => {
console.log(` Type: ${survey.type}`);
console.log(` Coverage: ${(survey.coverage * 100).toFixed(1)}%`);
if (survey.links.length > 0) {
survey.links.forEach(link => {
});
}
notificationText += survey.name;
if (index < surveys.length - 1) notificationText += ', ';
});
mw.notify(notificationText, { type: 'success', autoHide: false });
console.log('\n=== End of QuickSurveys ===');
}
// Main function to fetch and process surveys (for manual checking)
function fetchAndProcessSurveys() {
console.log('Fetching QuickSurveys data...');
Line 246 ⟶ 143:
console.error('Error fetching survey data:', error);
mw.notify('Error fetching QuickSurveys data: ' + error.message, { type: 'error' });
});
}
// Generate survey display when viewing userpage
function generateSurveyDisplay() {
console.log('Generating survey display for userpage...');
fetch(QUICKSURVEYS_URL)
.then(response => response.text())
.then(moduleText => {
const surveys = extractSurveyData(moduleText);
if (surveys.length === 0) {
return;
}
// Create a display box on the userpage
const $surveyBox = $('<div>')
.css({
'border': '1px solid #a2a9b1',
'background-color': '#f8f9fa',
'padding': '10px',
'margin': '10px 0',
'border-radius': '3px'
})
.html('<strong>Wikipedia QuickSurveys</strong><br>');
surveys.forEach(survey => {
$surveyBox.append(`<div style="margin: 5px 0;">
<strong>${survey.name}</strong> (${survey.type}, ${(survey.coverage * 100).toFixed(1)}% coverage)
</div>`);
if (survey.links.length > 0) {
survey.links.forEach(link => {
$surveyBox.append(`<div style="margin-left: 15px; font-size: 0.9em;">
→ <a href="${link.url}" target="_blank">${link.key}</a>
</div>`);
});
}
});
// Insert after the first paragraph or at the top
const $content = $('#mw-content-text');
const $firstPara = $content.find('p').first();
if ($firstPara.length) {
$firstPara.after($surveyBox);
} else {
$content.prepend($surveyBox);
}
})
.catch(error => {
console.error('Error fetching survey data for display:', error);
});
}
Line 278 ⟶ 226:
});
console.log('QuickSurveys tracker loaded. Use window.updateQuickSurveys() to manually
})();
|