Youtube Video Reload

Get Youtube Video views from a video url.

by Amal Das

HTML

<script src="https://www.youtube.com/iframe_api"></script>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>

<div class="slideshow-container">

<div class="mySlides fade">
  <div class="numbertext">1 / 6</div>
  <video autoplay id="video1" class="video1"><source src="video.mp4" type="video/mp4"></video>
  <div class="text">Caption Text</div>
</div>

<div class="mySlides fade">
  <div class="numbertext">2 / 6</div>
  <video id="video2" class="video2"><source src="video.mp4" type="video/mp4"></video>
  <div class="text">Caption Two</div>
</div>

<div class="mySlides fade">
  <div class="numbertext">3 / 6</div>
  <video id="video3" class="video3"><source src="video.mp4" type="video/mp4"></video>
  <div class="text">Caption Three</div>
</div>

<div class="mySlides fade">
  <div class="numbertext">4 / 6</div>
  <video id="video4" class="video4"><source src="video.mp4" type="video/mp4"></video>
  <div class="text">Caption Four</div>
</div>

<div class="mySlides fade">
  <div class="numbertext">5 / 6</div>
  <video id="video5" class="video5"><source src="video.mp4" type="video/mp4"></video>
  <div class="text">Caption Five</div>
</div>

<div class="mySlides fade">
  <div class="numbertext">6 / 6</div>
  <video id="video6" class="video6"><source src="video.mp4" type="video/mp4"></video>
  <div class="text">Caption Six</div>
</div>

<a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a>

</div>
<br>

<div style="text-align:center">
  <span class="dot" onclick="currentSlide(1)"></span> 
  <span class="dot" onclick="currentSlide(2)"></span> 
  <span class="dot" onclick="currentSlide(3)"></span>
  <span class="dot" onclick="currentSlide(4)"></span>
  <span class="dot" onclick="currentSlide(5)"></span>
  <span class="dot" onclick="currentSlide(6)"></span>
</div>

</body>
</html>

CSS

* {box-sizing: border-box}
body {font-family: Verdana, sans-serif; margin:0}
.mySlides {display: none}
img {vertical-align: middle;}

/* Slideshow container */
.slideshow-container {
  max-width: 1000px;
  position: relative;
  margin: auto;
}

/* Next & previous buttons */
.prev, .next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  padding: 16px;
  margin-top: -22px;
  color: white;
  font-weight: bold;
  font-size: 18px;
  transition: 0.6s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

/* Position the "next button" to the right */
.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
  background-color: rgba(0,0,0,0.8);
}

/* Caption text */
.text {
  color: #f2f2f2;
  font-size: 15px;
  padding: 8px 12px;
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
}

/* Number text (1/3 etc) */
.numbertext {
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  position: absolute;
  top: 0;
}

/* The dots/bullets/indicators */
.dot {
  cursor: pointer;
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active, .dot:hover {
  background-color: #717171;
}

/* Fading animation */
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}

@-webkit-keyframes fade {
  from {opacity: .4} 
  to {opacity: 1}
}

@keyframes fade {
  from {opacity: .4} 
  to {opacity: 1}
}

/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
  .prev, .next,.text {font-size: 11px}
}

JavaScript

var sPositions = localStorage.positions || "{}",
  positions = JSON.parse(sPositions);
// console.log(localStorage.positions);

$.each(positions, function (id, pos) {
  // console.log(pos);
  setTimeout(function () {
    $("#" + pos.id).click();
    $("#containment-wrapper").children("div").last().attr("id", id);
    $("#containment-wrapper")
      .children("div")
      .last()
      .attr("style", pos.stylecss);
    $("#containment-wrapper").children("div").last().css(pos.pos);
    if (pos.name != null) {
      $("#containment-wrapper")
        .children("div")
        .last()
        .find(".editable")
        .text(pos.name);
    }
    // $('#containment-wrapper').children('div').last().width(pos.width_css).height(pos.height_css);
  }, 500);
});

var item_list = [
    {
    id: "firewall",
    item: "Firewall",
    category: "Netword Devices",
    imagefile: "firewall1.svg",
    imagewidth: "100",
    minwidth: "100",
    maxwidth: "500",
    minheight: "100",
    maxheight: "500"
  }
];

var toolitems = '{ "items" :' + JSON.stringify(item_list) + "}";

$(function () {
   $("#menu").menu({
    items: "> :not(.ui-widget-header)"
  });
  // console.log(toolitems);
  //Parse JSON array into javascript array  - REQUIRED FOR dynamic add
  const tooltime = JSON.parse(toolitems);
  //  console.log(tooltime);

  function makeid(length) {
    var result = [];
    var characters =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    var charactersLength = characters.length;
    for (var i = 0; i < length; i++) {
      result.push(
        characters.charAt(Math.floor(Math.random() * charactersLength))
      );
    }
    return result.join("");
  }

  //DYNAMICALLY generate new copies of items
  $("#menu .menu-item").click(function () {
    var elmt_id = $(this).attr("id");
    var make_elmt_id = makeid(10);
    // find associated item in toolitems.items array
    const tool = tooltime.items.find((o) => o.id === this.id);
    const $div =...