View Single Post
  #3  
Old 02-03-2024, 10:09 PM
rahmani rahmani is offline
Kobold

rahmani's Avatar

Join Date: Jul 2011
Posts: 126
Default

After fiddling around a bit more, this will only trigger API calls to the mediawiki whenever someone hovers their mouse over an item, which should dramatically reduce the server load on the wiki

Code:
$(document).ready(function() {
    $('.item-data-placeholder').mouseenter(function() {
        var $this = $(this);
        // Check if the data has already been fetched
        if (!$this.data('fetched')) {
            var itemId = this.id.replace('item-data-', '');  // Trims "item-data-" prefix
            $.get(mw.util.wikiScript('api'), {
                action: 'parse',
                contentmodel: 'wikitext',
                text: '{{:' + itemId + '}}',
                prop: 'text',
                format: 'json'
            }, function(data) {
                var itemData = data.parse.text['*'];
                var itemLink = mw.util.getUrl(itemId);
                $this.html('<a href="' + itemLink + '">' + itemData + '</a>');
                // Mark the data as fetched
                $this.data('fetched', true);
            });
        }
    });
});
Reply With Quote