MediaWiki:Common.js: Difference between revisions
FrankMuraca (talk | contribs) No edit summary |
FrankMuraca (talk | contribs) No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
/* | /* Buy Me a Coffee button in sidebar */ | ||
document. | |||
function injectBmc() { | |||
if (! | // Find the placeholder link (works for /Bmc-placeholder and /wiki/Bmc-placeholder) | ||
var link = | |||
document.querySelector('#mw-panel a[href$="Bmc-placeholder"]') || | |||
document.querySelector('#mw-panel a[href*="Bmc-placeholder"]') || | |||
document.querySelector('#mw-panel a[href*="bmc-placeholder"]'); | |||
if (!link) return false; | |||
// Replace the whole <li> contents so we don't keep a bullet link | |||
var li = link.closest('li'); | |||
if (!li) return false; | |||
// Avoid duplicates | |||
if (li.dataset.loaded === '1') return true; | |||
li.dataset.loaded = '1'; | |||
li.innerHTML = '<div id="bmc-button-container" style="padding:0.25rem 0;"></div>'; | |||
var container = document. | var container = document.getElementById('bmc-button-container'); | ||
container | if (!container) return false; | ||
var script = document.createElement('script'); | var script = document.createElement('script'); | ||
script.src = 'https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js'; | 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-name', 'bmc-button'); | ||
script.setAttribute('data-slug', 'Raleighpedia'); | script.setAttribute('data-slug', 'Raleighpedia'); | ||
| Line 19: | Line 37: | ||
container.appendChild(script); | container.appendChild(script); | ||
return true; | |||
} | |||
document.addEventListener('DOMContentLoaded', function () { | |||
// Try a few times because Vector 2022 can re-render the sidebar | |||
injectBmc(); | |||
setTimeout(injectBmc, 300); | |||
setTimeout(injectBmc, 1200); | |||
}); | }); | ||