MediaWiki:Common.js: Difference between revisions

From [STAGING] Destiny Wiki
Jump to navigation Jump to search
(Preload video fix. Fix for disappearing videos.)
Tag: Reverted
(Undo revision 971 by Spr1ggs (talk))
Tag: Undo
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. */
mw.loader.using('mediawiki.util').then(function () {
const observer = new MutationObserver((mutations) => {
     document.addEventListener('DOMContentLoaded', function () {
     mutations.forEach((mutation) => {
         // Select all video elements
         mutation.addedNodes.forEach((node) => {
        var videos = document.querySelectorAll('video');
             if (node.tagName === 'VIDEO') {
 
                node.setAttribute('preload', 'none');
        videos.forEach(function (video) {
             }
             // Set the preload attribute to 'metadata'
            // This loads only the metadata and ensures the placeholder is displayed
            video.setAttribute('preload', 'metadata');
 
            // Add event listener to ensure the video plays correctly on click
            video.addEventListener('click', function () {
                video.play();
             });
         });
         });
     });
     });
});
});
// Start observing the document for changes
observer.observe(document.body, { childList: true, subtree: true });

Revision as of 21:10, 10 December 2024

/* Any JavaScript here will be loaded for all users on every page load. */
const observer = new MutationObserver((mutations) => {
    mutations.forEach((mutation) => {
        mutation.addedNodes.forEach((node) => {
            if (node.tagName === 'VIDEO') {
                node.setAttribute('preload', 'none');
            }
        });
    });
});

// Start observing the document for changes
observer.observe(document.body, { childList: true, subtree: true });