User:Loki Laufeyjarson/common.js: Difference between revisions

From Heroes 3 wiki
Jump to navigation Jump to search
No edit summary
Blanked the page
Tag: Blanking
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.using('mediawiki.util').then(function () {
  var cache = Object.create(null);


  function playFromHref(href) {
    if (!href) return;
    var url = new URL(href, location.href).toString();
    var a = cache[url] || (cache[url] = new Audio(url));
    try {
      a.currentTime = 0;
      a.play && a.play();
    } catch (_) {}
  }
  $(document).on('click', '.click-audio a.image', function (e) {
    var href = $(this).attr('href') || '';
    if (/\/(Media:|Special:FilePath\/)/i.test(href) || /\.(mp3|wav|ogg|m4a|webm)(\?|#|$)/i.test(href)) {
      e.preventDefault();
      playFromHref(href);
    }
  });
  mw.hook('wikipage.content').add(function ($c) {
    $c.find('.click-audio')
      .css('cursor', 'pointer')
      .attr({ role: 'button', tabindex: 0 });
  });
});

Latest revision as of 02:38, 10 September 2025