Jump to content

MediaWiki:Common.js: Difference between revisions

From Raleighpedia
Created page with "Any JavaScript here will be loaded for all users on every page load.: mw.hook('wikipage.content').add(function () { var container = document.getElementById('buymeacoffee'); if (!container) return; // Prevent duplicate insertion if (container.dataset.loaded === '1') return; container.dataset.loaded = '1'; var script = document.createElement('script'); script.src = 'https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js'; script.setAttribute('data-..."
 
mNo 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. */
/* Buy Me a Coffee button in sidebar */
(function () {
  function injectBmc() {
    // Try to find either a div we inserted, or the sidebar link we can replace
    var container = document.getElementById('buymeacoffee');


mw.hook('wikipage.content').add(function () {
    if (!container) {
  var container = document.getElementById('buymeacoffee');
      // Fallback: replace a sidebar link whose href ends with "buymeacoffee"
  if (!container) return;
      var link = document.querySelector('#mw-panel a[href$="buymeacoffee"]');
      if (!link) return;


  // Prevent duplicate insertion
      // Replace the link with a container div
  if (container.dataset.loaded === '1') return;
      container = document.createElement('div');
  container.dataset.loaded = '1';
      container.id = 'buymeacoffee';
      link.parentNode.replaceChild(container, link);
    }


  var script = document.createElement('script');
    if (container.dataset.loaded === '1') return;
  script.src = 'https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js';
    container.dataset.loaded = '1';
  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');


  container.appendChild(script);
    var script = document.createElement('script');
});
    script.src = 'https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js';
    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');
 
    container.appendChild(script);
  }
 
  // Run on initial load and after MediaWiki navigation events
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', injectBmc);
  } else {
    injectBmc();
  }
 
  mw.hook('wikipage.content').add(injectBmc);
})();

Revision as of 14:08, 29 January 2026

/* Any JavaScript here will be loaded for all users on every page load. */
/* Buy Me a Coffee button in sidebar */
(function () {
  function injectBmc() {
    // Try to find either a div we inserted, or the sidebar link we can replace
    var container = document.getElementById('buymeacoffee');

    if (!container) {
      // Fallback: replace a sidebar link whose href ends with "buymeacoffee"
      var link = document.querySelector('#mw-panel a[href$="buymeacoffee"]');
      if (!link) return;

      // Replace the link with a container div
      container = document.createElement('div');
      container.id = 'buymeacoffee';
      link.parentNode.replaceChild(container, link);
    }

    if (container.dataset.loaded === '1') return;
    container.dataset.loaded = '1';

    var script = document.createElement('script');
    script.src = 'https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js';
    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');

    container.appendChild(script);
  }

  // Run on initial load and after MediaWiki navigation events
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', injectBmc);
  } else {
    injectBmc();
  }

  mw.hook('wikipage.content').add(injectBmc);
})();