User:K599/TwitchClip.js

//Author: K599 / Kelvs599

//Code based on https://dev.fandom.com/wiki/MediaWiki:YoutubePlayer/code.js

//Loading this JavaScript allows Twitch clips to be embedded by inserting the following code: // //Explanations for each parameter can be found on https://dev.twitch.tv/docs/embed/video-and-clips (note that this script sets "parent" automatically) //Default width and height is 620x378.

mw.hook('wikipage.content').add(function($content) {   $content.find('.twitchclip:not(.loaded)').each(function { var $this = $(this), data = $this.data, uri = new mw.Uri('https://clips.twitch.tv/embed/');

uri.query = { clip: String(data.slug || '').trim, autoplay: String(data.autoplay ?? '').trim, muted: String(data.muted ?? '').trim, parent: mw.config.get('wgServerName') };

$this.html(           $(' ', { src: uri.toString, style: 'width: ' + (typeof data.width === 'number' ? data.width + 'px' : String(data.width || '620px').trim) + '; height: ' + (typeof data.height === 'number' ? data.height + 'px' : String(data.height || '378px').trim) + ';', frameborder: '0', scrolling: 'no', allowfullscreen: 'true' })       ).addClass('loaded'); }); });