MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
$(function () { | $(function () { | ||
console.log('[ReportAbuseLink] Running | mw.loader.using('mediawiki.util').then(function () { | ||
console.log('[ReportAbuseLink] Running...'); | |||
const reportPage = 'Report_Animal_Abuse'; // page title | |||
const linkText = '🚨 Report Abuse'; | |||
const insertLink = function () { | |||
const personalList = document.querySelector('#p-personal ul.vector-menu-content-list'); | |||
const langButton = document.querySelector('#p-lang-btn, #vector-lang-button'); // language button | |||
const loginItem = document.querySelector('#pt-login-2, #pt-login'); | |||
if (!personalList) { | |||
console.log('[ReportAbuseLink] personal tools list not found.'); | |||
return false; | |||
} | |||
// Create the list item | |||
const li = document.createElement('li'); | |||
li.id = 'pt-reportabuse'; | |||
const link = document.createElement('a'); | |||
link.href = mw.util.getUrl(reportPage); | |||
link.textContent = linkText; | |||
link.style.color = '#b10000'; | |||
link.style.fontWeight = 'bold'; | |||
li.appendChild(link); | |||
if (langButton && langButton.closest('li')?.parentNode === personalList) { | |||
personalList.insertBefore(li, langButton.closest('li')); | |||
console.log('[ReportAbuseLink] Inserted before language button.'); | |||
} else if (loginItem && loginItem.closest('li')?.parentNode === personalList) { | |||
personalList.insertBefore(li, loginItem.closest('li')); | |||
console.log('[ReportAbuseLink] Inserted before login.'); | |||
} else { | |||
personalList.appendChild(li); | |||
console.log('[ReportAbuseLink] Appended to the end.'); | |||
} | |||
return true; | |||
}; | |||
// Try inserting with retry logic | |||
let attempts = 0; | |||
const maxAttempts = 30; | |||
const retryInterval = setInterval(() => { | |||
if (insertLink() || ++attempts >= maxAttempts) { | |||
clearInterval(retryInterval); | |||
console.log('[ReportAbuseLink] Done.'); | |||
} | |||
}, 200); | |||
}); | |||
}); | }); |
Revision as of 05:48, 21 April 2025
$(function () { mw.loader.using('mediawiki.util').then(function () { console.log('[ReportAbuseLink] Running...'); const reportPage = 'Report_Animal_Abuse'; // page title const linkText = '🚨 Report Abuse'; const insertLink = function () { const personalList = document.querySelector('#p-personal ul.vector-menu-content-list'); const langButton = document.querySelector('#p-lang-btn, #vector-lang-button'); // language button const loginItem = document.querySelector('#pt-login-2, #pt-login'); if (!personalList) { console.log('[ReportAbuseLink] personal tools list not found.'); return false; } // Create the list item const li = document.createElement('li'); li.id = 'pt-reportabuse'; const link = document.createElement('a'); link.href = mw.util.getUrl(reportPage); link.textContent = linkText; link.style.color = '#b10000'; link.style.fontWeight = 'bold'; li.appendChild(link); if (langButton && langButton.closest('li')?.parentNode === personalList) { personalList.insertBefore(li, langButton.closest('li')); console.log('[ReportAbuseLink] Inserted before language button.'); } else if (loginItem && loginItem.closest('li')?.parentNode === personalList) { personalList.insertBefore(li, loginItem.closest('li')); console.log('[ReportAbuseLink] Inserted before login.'); } else { personalList.appendChild(li); console.log('[ReportAbuseLink] Appended to the end.'); } return true; }; // Try inserting with retry logic let attempts = 0; const maxAttempts = 30; const retryInterval = setInterval(() => { if (insertLink() || ++attempts >= maxAttempts) { clearInterval(retryInterval); console.log('[ReportAbuseLink] Done.'); } }, 200); }); });