MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
$(function() { | $(function () { | ||
mw.loader.using( 'mediawiki.util' ).then( function () { | mw.loader.using('mediawiki.util').then(function () { | ||
console.log( '[ReportAbuseLink] | console.log('[ReportAbuseLink] Starting...'); | ||
const | const reportLinkText = '🐾 Report Abuse'; | ||
const | const reportPageURL = mw.util.getUrl('Report_Animal_Abuse'); // Change if your page name differs | ||
let attempts = 0; | let attempts = 0; | ||
const maxAttempts = 50; | const maxAttempts = 50; | ||
const | const tryInsert = function () { | ||
const personalMenu = document.querySelector('#p-personal ul.vector-menu-content-list'); | |||
const loginItem = document.querySelector('#pt-login-2'); | |||
if (personalMenu && loginItem) { | |||
console.log('[ReportAbuseLink] Found login item. Inserting before it.'); | |||
const li = document.createElement('li'); | |||
li.id = 'pt-reportabuse'; | |||
const | const a = document.createElement('a'); | ||
a.href = reportPageURL; | |||
a.textContent = reportLinkText; | |||
a.title = 'Report animal abuse to authorities or NGOs'; | |||
const li = document.createElement( 'li' ); | li.appendChild(a); | ||
personalMenu.insertBefore(li, loginItem); | |||
return true; | |||
} else if (personalMenu && attempts >= maxAttempts) { | |||
console.log('[ReportAbuseLink] Login item not found after max attempts. Appending to end.'); | |||
const li = document.createElement('li'); | |||
li.id = 'pt-reportabuse'; | li.id = 'pt-reportabuse'; | ||
const a = document.createElement('a'); | |||
a.href = reportPageURL; | |||
a.textContent = reportLinkText; | |||
a.title = 'Report animal abuse to authorities or NGOs'; | |||
li.appendChild(a); | |||
personalMenu.appendChild(li); | |||
return true; | |||
return true; | |||
} | } | ||
return false; | return false; | ||
}; | }; | ||
const interval = setInterval(function () { | |||
attempts++; | |||
if ( | if (tryInsert() || attempts >= maxAttempts) { | ||
clearInterval( | clearInterval(interval); | ||
console.log( '[ReportAbuseLink] | console.log('[ReportAbuseLink] Done.'); | ||
} | } | ||
}, | }, 100); | ||
}); | }); | ||
}); | }); |
Revision as of 04:53, 21 April 2025
$(function () { mw.loader.using('mediawiki.util').then(function () { console.log('[ReportAbuseLink] Starting...'); const reportLinkText = '🐾 Report Abuse'; const reportPageURL = mw.util.getUrl('Report_Animal_Abuse'); // Change if your page name differs let attempts = 0; const maxAttempts = 50; const tryInsert = function () { const personalMenu = document.querySelector('#p-personal ul.vector-menu-content-list'); const loginItem = document.querySelector('#pt-login-2'); if (personalMenu && loginItem) { console.log('[ReportAbuseLink] Found login item. Inserting before it.'); const li = document.createElement('li'); li.id = 'pt-reportabuse'; const a = document.createElement('a'); a.href = reportPageURL; a.textContent = reportLinkText; a.title = 'Report animal abuse to authorities or NGOs'; li.appendChild(a); personalMenu.insertBefore(li, loginItem); return true; } else if (personalMenu && attempts >= maxAttempts) { console.log('[ReportAbuseLink] Login item not found after max attempts. Appending to end.'); const li = document.createElement('li'); li.id = 'pt-reportabuse'; const a = document.createElement('a'); a.href = reportPageURL; a.textContent = reportLinkText; a.title = 'Report animal abuse to authorities or NGOs'; li.appendChild(a); personalMenu.appendChild(li); return true; } return false; }; const interval = setInterval(function () { attempts++; if (tryInsert() || attempts >= maxAttempts) { clearInterval(interval); console.log('[ReportAbuseLink] Done.'); } }, 100); }); });