Template:YoutubeTest: Difference between revisions

Template page
No edit summary
(Added a video shuffle function)
Line 1: Line 1:
<ul class="videolist">
 
<li><h3>Example player call</h3></li>
 
<li>{{#widget:YouTube|id=tfcf5pv3VfA}}</li>
<li><h3>ID list</h3></li>
<li>tfcf5pv3VfA</li>
<li>EQ7ZgdSlQRs</li>
<li>aQYTuk-_hKg</li>
<li>0UMeJpjvV5k</li>
<li>1p9I-No9HEo</li>
<li>48mKhSfcJ60</li>
<li>5_oQb7GWKTU</li>
<li>5f4Xt_QYxTc</li>
<li>5lmm3sSr7nY</li>
<li>BSJpTMTyxUM</li>
<li>DE0I-rey15k</li>
<li>GXoOjRoF0nc</li>
<li>G_KgZqd8b2k</li>
<li>HLa1T9f0hy4</li>
<li>JXbdSsjOYn8</li>
<li>KAce42mgj84</li>
<li>KRXUYAFdKX4</li>
<li>N90Utrsfwz8</li>
<li>O69bZUNgEas</li>
<li>PPap3u_cWVw</li>
<li>R8RTLW9SOlc</li>
<li>RTNljh1RLdM</li>
<li>RvgYj1dVg14</li>
<li>T-sDOO4L42U</li>
<li>UHppQLgcC_8</li>
<li>Ura1IgHRlgg</li>
<li>W_Yh2-MHATo</li>
<li>W_Yh2-MHATo</li>
<li>Z__E97Wo2yw</li>
<li>Zc9HsPx0rN8</li>
<li>Zc9HsPx0rN8</li>
<li>Zw7PEVEBuwY</li>
<li>_LWj3TSbDRo</li>
<li>_r47zds9ajg</li>
<li>apNnmCBiKv4</li>
<li>fTgo466hG1c</li>
<li>jFW7BdHTRdY</li>
<li>mtZA_k174VM</li>
<li>sxXaPow0qig</li>
<li>wYwf1HdBlkQ</li>
<li>xV88777nyOA</li>
<li>ydxQlqpkX8E</li>
<li>yeF-QesNdto</li>
</ul>
<html>
<html>
<iframe id="ytPlayer" type="text/html" width="640" height="360"
  src="https://www.youtube.com/embed/M7lc1UVf-VE"
  frameborder="0">
  </iframe>
<button id="ytButton">Play next</button>
<!-- Put Your javascript here-->
<!-- Put Your javascript here-->
<script>
var videoIdList = [
"tfcf5pv3VfA",
"EQ7ZgdSlQRs",
"aQYTuk-_hKg",
"0UMeJpjvV5k",
"1p9I-No9HEo",
"48mKhSfcJ60",
"5_oQb7GWKTU",
"5f4Xt_QYxTc",
"5lmm3sSr7nY",
"BSJpTMTyxUM",
"DE0I-rey15k",
"GXoOjRoF0nc",
"G_KgZqd8b2k",
"HLa1T9f0hy4",
"JXbdSsjOYn8",
"KAce42mgj84",
"KRXUYAFdKX4",
"N90Utrsfwz8",
"O69bZUNgEas",
"PPap3u_cWVw",
"R8RTLW9SOlc",
"RTNljh1RLdM",
"RvgYj1dVg14",
"T-sDOO4L42U",
"UHppQLgcC_8",
"Ura1IgHRlgg",
"W_Yh2-MHATo",
"W_Yh2-MHATo",
"Z__E97Wo2yw",
"Zc9HsPx0rN8",
"Zc9HsPx0rN8",
"Zw7PEVEBuwY",
"_LWj3TSbDRo",
"_r47zds9ajg",
"apNnmCBiKv4",
"fTgo466hG1c",
"jFW7BdHTRdY",
"mtZA_k174VM",
"sxXaPow0qig",
"wYwf1HdBlkQ",
"xV88777nyOA",
"ydxQlqpkX8E",
"yeF-QesNdto"
];
var youtubeLink = "https://www.youtube.com/embed/";
var shuffledList = videoIdList.sort(() => Math.random() - 0.5);
var button = document.querySelector("#ytButton");
var player = document.querySelector("#ytPlayer");
button.addEventListener("click", playNext);
function playNext() {
  var justPlayedVideo = shuffledList.shift();
  shuffledList.push(justPlayedVideo);
  player.src = youtubeLink + shuffledList[0];
}
player.src = youtubeLink + shuffledList[0];
</script>
</html>
</html>

Revision as of 08:58, 23 April 2022