MediaWiki:Common.js: Difference between revisions

From Fatesend Wiki
Jump to navigation Jump to search
Created page with "Any JavaScript here will be loaded for all users on every page load.: (function () { // If there are no DP links on the page, don't load anything. if (!document.querySelector('a[href*="divine-pride.net/database/item/"]')) return; var s = document.createElement('script'); s.src = 'https://www.divine-pride.net/scripts/tooltip.js'; s.async = true; document.head.appendChild(s); })();"
 
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 8: Line 8:
   s.async = true;
   s.async = true;
   document.head.appendChild(s);
   document.head.appendChild(s);
})();
(function () {
  function loadScriptOnce(src, id) {
    return new Promise(function (resolve, reject) {
      if (document.getElementById(id)) return resolve();
      var s = document.createElement('script');
      s.id = id;
      s.src = src;
      s.async = true;
      s.onload = resolve;
      s.onerror = reject;
      document.head.appendChild(s);
    });
  }
  var RO_API_JS = '/robrowser/api.js';
  function ensureROBrowser() {
    return loadScriptOnce(RO_API_JS, 'robrowser-api').then(function () {
      if (!window.ROBrowser) throw new Error('ROBrowser not available after loading api.js');
    });
  }
  function openPopupFromLink(a) {
    var sprite = a.getAttribute('data-sprite') || a.getAttribute('data-accessory') || '';
    var jobId = parseInt(a.getAttribute('data-jobid') || '0', 10) || 0;
    var job = a.getAttribute('data-job') || '';
    var robe = a.getAttribute('data-robe') || '';
    if (!sprite) return;
    var ro = new window.ROBrowser({
      application: window.ROBrowser.APP.MODELVIEWER,
      type: window.ROBrowser.TYPE.POPUP,
      width: 820,
      height: 520,
      development: true,
      remoteClient: 'https://grf.robrowser.com/',
      skipIntro: true,
      skipServerList: true,
      accessory: sprite,
      jobId: jobId,
      job: job,
      robe: robe
    });
    ro.start();
  }
  document.addEventListener('click', function (e) {
    var a = e.target.closest && e.target.closest('a.dp-modelviewer');
    if (!a) return;
    e.preventDefault();
    e.stopPropagation();
    ensureROBrowser()
      .then(function () { openPopupFromLink(a); })
      .catch(function (err) { console.error('ModelViewer popup error:', err); });
  });
})();
})();

Latest revision as of 15:32, 27 January 2026

/* Any JavaScript here will be loaded for all users on every page load. */
(function () {
  // If there are no DP links on the page, don't load anything.
  if (!document.querySelector('a[href*="divine-pride.net/database/item/"]')) return;

  var s = document.createElement('script');
  s.src = 'https://www.divine-pride.net/scripts/tooltip.js';
  s.async = true;
  document.head.appendChild(s);
})();


(function () {
  function loadScriptOnce(src, id) {
    return new Promise(function (resolve, reject) {
      if (document.getElementById(id)) return resolve();
      var s = document.createElement('script');
      s.id = id;
      s.src = src;
      s.async = true;
      s.onload = resolve;
      s.onerror = reject;
      document.head.appendChild(s);
    });
  }

  var RO_API_JS = '/robrowser/api.js';

  function ensureROBrowser() {
    return loadScriptOnce(RO_API_JS, 'robrowser-api').then(function () {
      if (!window.ROBrowser) throw new Error('ROBrowser not available after loading api.js');
    });
  }

  function openPopupFromLink(a) {
    var sprite = a.getAttribute('data-sprite') || a.getAttribute('data-accessory') || '';
    var jobId = parseInt(a.getAttribute('data-jobid') || '0', 10) || 0;
    var job = a.getAttribute('data-job') || '';
    var robe = a.getAttribute('data-robe') || '';
    if (!sprite) return;

    var ro = new window.ROBrowser({
      application: window.ROBrowser.APP.MODELVIEWER,
      type: window.ROBrowser.TYPE.POPUP,
      width: 820,
      height: 520,
      development: true,
      remoteClient: 'https://grf.robrowser.com/',
      skipIntro: true,
      skipServerList: true,
      accessory: sprite,
      jobId: jobId,
      job: job,
      robe: robe
    });

    ro.start();
  }

  document.addEventListener('click', function (e) {
    var a = e.target.closest && e.target.closest('a.dp-modelviewer');
    if (!a) return;

    e.preventDefault();
    e.stopPropagation();

    ensureROBrowser()
      .then(function () { openPopupFromLink(a); })
      .catch(function (err) { console.error('ModelViewer popup error:', err); });
  });
})();