MediaWiki:Common.js: Difference between revisions
Appearance
FrankMuraca (talk | contribs) mNo edit summary |
FrankMuraca (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
document.addEventListener('DOMContentLoaded', function () { | |||
(function () { | // Find the "Buy Raleighpedia a coffee" sidebar link | ||
var links = document.querySelectorAll('#mw-panel a'); | |||
var target = null; | |||
links.forEach(function (a) { | |||
if ((a.textContent || '').trim() === 'Buy Raleighpedia a coffee') target = a; | |||
}); | |||
if (!target) { | |||
console.log('BMC: sidebar link not found'); | |||
return; | |||
} | |||
// Replace link with a container div | |||
var container = document.createElement('div'); | |||
container.id = 'buymeacoffee'; | |||
target.parentNode.replaceChild(container, target); | |||
console.log('BMC: container inserted'); | |||
// Load Buy Me a Coffee button script | |||
var script = document.createElement('script'); | |||
script.src = 'https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js'; | |||
script.async = true; | |||
script.setAttribute('data-name', 'bmc-button'); | |||
script.setAttribute('data-slug', 'Raleighpedia'); | |||
script.setAttribute('data-color', '#FFDD00'); | |||
script.setAttribute('data-font', 'Lato'); | |||
script.setAttribute('data-text', 'Buy Raleighpedia a coffee'); | |||
script.setAttribute('data-outline-color', '#000000'); | |||
script.setAttribute('data-font-color', '#000000'); | |||
script.setAttribute('data-coffee-color', '#ffffff'); | |||
script.onload = function () { console.log('BMC: script loaded'); }; | |||
script.onerror = function (e) { console.log('BMC: script failed', e); }; | |||
container.appendChild(script); | |||
} | }); | ||
Revision as of 15:10, 29 January 2026
/* Any JavaScript here will be loaded for all users on every page load. */
document.addEventListener('DOMContentLoaded', function () {
// Find the "Buy Raleighpedia a coffee" sidebar link
var links = document.querySelectorAll('#mw-panel a');
var target = null;
links.forEach(function (a) {
if ((a.textContent || '').trim() === 'Buy Raleighpedia a coffee') target = a;
});
if (!target) {
console.log('BMC: sidebar link not found');
return;
}
// Replace link with a container div
var container = document.createElement('div');
container.id = 'buymeacoffee';
target.parentNode.replaceChild(container, target);
console.log('BMC: container inserted');
// Load Buy Me a Coffee button script
var script = document.createElement('script');
script.src = 'https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js';
script.async = true;
script.setAttribute('data-name', 'bmc-button');
script.setAttribute('data-slug', 'Raleighpedia');
script.setAttribute('data-color', '#FFDD00');
script.setAttribute('data-font', 'Lato');
script.setAttribute('data-text', 'Buy Raleighpedia a coffee');
script.setAttribute('data-outline-color', '#000000');
script.setAttribute('data-font-color', '#000000');
script.setAttribute('data-coffee-color', '#ffffff');
script.onload = function () { console.log('BMC: script loaded'); };
script.onerror = function (e) { console.log('BMC: script failed', e); };
container.appendChild(script);
});