MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
const reportLinkText = '🐾 Report Abuse'; | const reportLinkText = '🐾 Report Abuse'; | ||
const reportPageURL = mw.util.getUrl('Report_Animal_Abuse'); // | const reportPageURL = mw.util.getUrl('Report_Animal_Abuse'); // Update if needed | ||
let attempts = 0; | let attempts = 0; | ||
Line 11: | Line 11: | ||
const tryInsert = function () { | const tryInsert = function () { | ||
const personalMenu = document.querySelector('#p-personal ul.vector-menu-content-list'); | const personalMenu = document.querySelector('#p-personal ul.vector-menu-content-list'); | ||
if (personalMenu | if (personalMenu) { | ||
if (!document.getElementById('pt-reportabuse')) { | |||
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); | |||
console.log('[ReportAbuseLink] Link inserted at the end of personal menu.'); | |||
} | |||
return true; | return true; | ||
} | } | ||
if (attempts >= maxAttempts) { | |||
console.warn('[ReportAbuseLink] Failed to find personal menu after max attempts.'); | |||
return true; | return true; | ||
} | } | ||
Line 46: | Line 40: | ||
const interval = setInterval(function () { | const interval = setInterval(function () { | ||
attempts++; | attempts++; | ||
if (tryInsert() | if (tryInsert()) { | ||
clearInterval(interval); | clearInterval(interval); | ||
console.log('[ReportAbuseLink] Done.'); | console.log('[ReportAbuseLink] Done.'); |
Revision as of 04:56, 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'); // Update if needed let attempts = 0; const maxAttempts = 50; const tryInsert = function () { const personalMenu = document.querySelector('#p-personal ul.vector-menu-content-list'); if (personalMenu) { if (!document.getElementById('pt-reportabuse')) { 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); console.log('[ReportAbuseLink] Link inserted at the end of personal menu.'); } return true; } if (attempts >= maxAttempts) { console.warn('[ReportAbuseLink] Failed to find personal menu after max attempts.'); return true; } return false; }; const interval = setInterval(function () { attempts++; if (tryInsert()) { clearInterval(interval); console.log('[ReportAbuseLink] Done.'); } }, 100); }); });