User:K599/Niconico.js

//Author: K599 / Kelvs599

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

//Loading this JavaScript allows Niconico videos to be embedded by inserting the following code: // //data-id: The ID of the video, which is found after the "watch/" in the video's URL. //data-from: Set when the video starts in seconds from the start. //Default width and height is 640x360.

mw.hook('wikipage.content').add(function($content) {   $content.find('.niconico:not(.loaded)').each(function { var $this = $(this), data = $this.data, uri = new mw.Uri('https://embed.nicovideo.jp/watch/');

uri.path += String(data.id || '').trim; uri.query = { from: String(data.from || '').trim };

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