// ==UserScript== // @name Add Instagram Video Progressbar // @namespace https://greasyfork.org/en/users/85671-jcunews // @version 1.0.4 // @license GNU AGPLv3 // @author jcunews // @description Add a video playback progressbar at bottom of an Instagram video. This script also disables video looping. Both are configurable. // @match *://www.instagram.com/* // @exclude *://www.instagram.com/stories/* // @grant none // @run-at document-start // @downloadURL https://update.greasyfork.org/scripts/367667/Add%20Instagram%20Video%20Progressbar.user.js // @updateURL https://update.greasyfork.org/scripts/367667/Add%20Instagram%20Video%20Progressbar.meta.js // ==/UserScript== (function(vael, ie, ee, be, wm) { //===== CONFIGURATION BEGIN ===== var ProgressbarHeight = 3; //in pixels. set to zero to hide var ProgressbarColor = "#fff"; //e.g. "#fff" or "#e0e0e0" or "cyan" var ProgressbarElapsedColor = "#f00"; var disableVideoLoop = true; //===== CONFIGURATION END ===== function addBar(a, b) { if (disableVideoLoop) ie = this.parentNode.parentNode.parentNode.parentNode.lastElementChild; a = "aivp" + (new Date()).getTime(); b = a + "bar"; ee = document.createElement("DIV"); ee.id = a; ee.innerHTML = `
`; wm.set(this, be = ee.lastElementChild); this.parentNode.insertBefore(ee, this); this.removeEventListener("canplay", addBar); } wm = new WeakMap; vael = HTMLVideoElement.prototype.addEventListener; HTMLVideoElement.prototype.addEventListener = function() { var res; ((ve, tm, be) => { function updBar() { be.style.width = Math.ceil((ve.currentTime / ve.duration) * ee.offsetWidth) + "px"; } function startTimer(ev) { if (!be) be = wm.get(this); if (disableVideoLoop) ve.loop = false; if (!tm) tm = setInterval(updBar, 100); } function stopTimer(ev) { if (ev.type === "ended") { be.style.width = "100%"; if (disableVideoLoop) ie.click(); } clearInterval(tm); tm = 0; } res = vael.apply(ve, arguments); if (!ve.attributes["aivp_done"]) { ve.setAttribute("aivp_done", "1"); vael.call(ve, "canplay", addBar); vael.call(ve, "play", startTimer); vael.call(ve, "playing", startTimer); vael.call(ve, "waiting", stopTimer); vael.call(ve, "pause", stopTimer); vael.call(ve, "ended", stopTimer); } })(this); return res; }; })();