Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
Line 63:
url: MEDIAWICK_BASE_URL + formatLinkKey(survey.link)
});
}
// 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) {
}
// 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 89 ⟶ 141:
}
// Format link key for MediaWiki URL (capitalize only the first letter
function formatLinkKey(key) {
return key.
▲ ).join('-');
}
Line 191 ⟶ 241:
console.log('Extracted surveys:', surveys);
▲ updateUserpage(markup);
})
.catch(error => {
Line 211 ⟶ 258:
if (username && currentPage === `User:${username}`) {
// Auto-generate survey display on userpage
generateSurveyDisplay();
// Only add link if it doesn't already exist
if ($('#update-quicksurveys').length === 0) {
// Add a small link to manually update
const $link = $('<span style="font-size: 0.8em; margin-left: 1em;">').html(
'[<a href="#" id="update-quicksurveys">
);
|