From 8518b263e05dced34a4b965c9154c76963a4e292 Mon Sep 17 00:00:00 2001 From: Alexander Mandrikov Date: Thu, 26 Sep 2024 23:26:36 +0700 Subject: [PATCH] remove debug info --- dist/bookmarklet-video-speed.js | 4 ++-- main.ts | 10 +--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/dist/bookmarklet-video-speed.js b/dist/bookmarklet-video-speed.js index 4be8b13..9279676 100644 --- a/dist/bookmarklet-video-speed.js +++ b/dist/bookmarklet-video-speed.js @@ -1,8 +1,8 @@ -(()=>{var H=Object.defineProperty;var b=n=>{throw TypeError(n)};var $=(n,e,t)=>e in n?H(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>$(n,typeof e!="symbol"?e+"":e,t),A=(n,e,t)=>e.has(n)||b("Cannot "+t);var E=(n,e,t)=>e.has(n)?b("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t);var a=(n,e,t)=>(A(n,e,"access private method"),t);var d="nunsez-video-bookmarklet";var h="".concat(d,"-state"),g="".concat(d,"-memory"),i="".concat(d,"-controller"),T="".concat(d,"-tickmarks"),v="".concat(d,"-stylesheet"),B="#".concat(i," * {box-sizing: border-box;color: #111;line-height:initial}")+"#".concat(i,", #").concat(i," .range, #").concat(i," .controls {margin: 0;padding: 4px;}")+"#".concat(i,", #").concat(i," .btn {border: 1px solid #444;border-radius: 4px;background-color: #eee;}")+"#".concat(i," {position: fixed;left: 8px;top: 8px;width: 150px;font: 15px monospace;box-shadow: 1px 1px 4px #444;user-select: none;z-index: 999999999;}")+"#".concat(i," .controls {display: flex;justify-content: space-between;align-items: center;}")+"#".concat(i," .btn {width: 20px;height: 20px;margin: 0;padding: 0;}")+"#".concat(i," .value {pointer-events: none;}")+"#".concat(i,' .value::after {content: "%";margin-left: 2px;}')+"#".concat(i," .range {width: 100%;}")+"#".concat(i," .range ~ * {display: none;}");function k(n){if(n.head.querySelector("#".concat(v)))return;let e=n.createElement("style");e.setAttribute("id",v),e.textContent=B,n.head.append(e)}var m=class n{constructor(e){o(this,"document");o(this,"speed");o(this,"videos",[]);o(this,"controller");o(this,"searchTimeoutId");o(this,"observer");this.document=e,this.speed=n.getSpeed(),this.observer=new MutationObserver(t=>this.refresh(t)),this.controller=new p(this)}static getSpeed(){let e=Number.parseInt(localStorage.getItem(g)||"");return Number.isNaN(e)?100:e}static getVideos(e){let t=[];return e.querySelectorAll("video, iframe").forEach(r=>{var l;if(r instanceof HTMLVideoElement)t.push(r);else if(r instanceof HTMLIFrameElement){let c=(l=n.getIDoc(r))==null?void 0:l.querySelector("video");c&&t.push(c)}}),t}static getIDoc(e){var t;try{return((t=e.contentWindow)==null?void 0:t.document)||e.contentDocument}catch(r){return console.log("iframe document is not reachable: "+e.src),null}}initialize(){this.observer.observe(document.body,{childList:!0}),this.controller.appendTo(document.body)}refresh(e){console.log("_mutationRecords",e),console.log("refresh",this.searchTimeoutId,this.controller),clearTimeout(this.searchTimeoutId),this.searchTimeoutId=setTimeout(()=>{this.videos=n.getVideos(this.document.body),this.setSpeed(this.speed)},500)}terminate(){console.log("terminate observer",this.observer),console.log("terminate oldController",this.controller),console.log("terminate searchTimeoutId",this.searchTimeoutId),clearTimeout(this.searchTimeoutId),this.observer.disconnect(),this.controller.el.remove(),this.videos.forEach(e=>e.playbackRate=100/100)}setSpeed(e){if(!this.controller||Number.isNaN(e))return;e===5?this.speed>5?this.speed=0:this.speed=10:e>300?this.speed=300:e<0?this.speed=0:this.speed=e;let t=this.speed.toString();this.controller.value.textContent=t,this.controller.range.value=t,this.videos.forEach(r=>r.playbackRate=this.speed/100),console.log("set speed",this.videos,this.controller),localStorage.setItem(g,t)}},s,L,S,M,f,x,I,y,D,u=class u{constructor(e){E(this,s);o(this,"el");o(this,"subBtn",document.createElement("button"));o(this,"value",document.createElement("div"));o(this,"addBtn",document.createElement("button"));o(this,"range",document.createElement("input"));this.el=document.createElement("div"),this.el[h]=e}appendTo(e){var t;return(t=e.querySelector(i))==null||t.remove(),a(this,s,S).call(this),a(this,s,L).call(this),e.append(this.el),this}get state(){return this.el[h]}};s=new WeakSet,L=function(){this.range.addEventListener("input",()=>{let e=Number.parseFloat(this.range.value);this.state.setSpeed(e)}),this.subBtn.addEventListener("click",()=>this.state.setSpeed(this.state.speed-5)),this.addBtn.addEventListener("click",()=>this.state.setSpeed(this.state.speed+5))},S=function(){this.el.setAttribute("id",i),this.el.append(a(this,s,M).call(this),a(this,s,y).call(this),a(this,s,D).call(this,u.tickMarks))},M=function(){let e=document.createElement("div");return e.classList.add("controls"),e.append(a(this,s,f).call(this),a(this,s,x).call(this),a(this,s,I).call(this)),e},f=function(){return this.subBtn=document.createElement("button"),this.subBtn.textContent="-",this.subBtn.classList.add("btn","sub"),this.subBtn},x=function(){return this.value=document.createElement("div"),this.value.textContent=this.state.speed.toString(),this.value},I=function(){return this.addBtn=document.createElement("button"),this.addBtn.textContent="+",this.addBtn.classList.add("btn","add"),this.addBtn},y=function(){return this.range=document.createElement("input"),this.range.classList.add("range"),this.range.setAttribute("type","range"),this.range.setAttribute("min","10"),this.range.setAttribute("max","300"),this.range.setAttribute("step","10"),this.range.setAttribute("list",T),this.range.value=this.state.speed.toString(),this.range},D=function(e){let t=document.createElement("datalist");t.setAttribute("id",T);let r=e.map(l=>{let c=document.createElement("option");return c.value=l.toString(),c});return t.append(...r),t},o(u,"tickMarks",[10,50,100,150,200,250,300]);var p=u;function R(n){let e=n.document,t=e.querySelector("#".concat(i));if(t){let l=t[h];l==null||l.terminate(),t.remove();return}k(e),new m(e).initialize()}R(window);})(); +(()=>{var H=Object.defineProperty;var E=n=>{throw TypeError(n)};var $=(n,t,e)=>t in n?H(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var o=(n,t,e)=>$(n,typeof t!="symbol"?t+"":t,e),A=(n,t,e)=>t.has(n)||E("Cannot "+e);var b=(n,t,e)=>t.has(n)?E("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(n):t.set(n,e);var a=(n,t,e)=>(A(n,t,"access private method"),e);var l="nunsez-video-bookmarklet";var m="".concat(l,"-state"),g="".concat(l,"-memory"),i="".concat(l,"-controller"),T="".concat(l,"-tickmarks"),v="".concat(l,"-stylesheet"),B="#".concat(i," * {box-sizing: border-box;color: #111;line-height:initial}")+"#".concat(i,", #").concat(i," .range, #").concat(i," .controls {margin: 0;padding: 4px;}")+"#".concat(i,", #").concat(i," .btn {border: 1px solid #444;border-radius: 4px;background-color: #eee;}")+"#".concat(i," {position: fixed;left: 8px;top: 8px;width: 150px;font: 15px monospace;box-shadow: 1px 1px 4px #444;user-select: none;z-index: 999999999;}")+"#".concat(i," .controls {display: flex;justify-content: space-between;align-items: center;}")+"#".concat(i," .btn {width: 20px;height: 20px;margin: 0;padding: 0;}")+"#".concat(i," .value {pointer-events: none;}")+"#".concat(i,' .value::after {content: "%";margin-left: 2px;}')+"#".concat(i," .range {width: 100%;}")+"#".concat(i," .range ~ * {display: none;}");function k(n){if(n.head.querySelector("#".concat(v)))return;let t=n.createElement("style");t.setAttribute("id",v),t.textContent=B,n.head.append(t)}var h=class n{constructor(t){o(this,"document");o(this,"speed");o(this,"videos",[]);o(this,"controller");o(this,"searchTimeoutId");o(this,"observer");this.document=t,this.speed=n.getSpeed(),this.observer=new MutationObserver(e=>this.refresh(e)),this.controller=new p(this)}static getSpeed(){let t=Number.parseInt(localStorage.getItem(g)||"");return Number.isNaN(t)?100:t}static getVideos(t){let e=[];return t.querySelectorAll("video, iframe").forEach(r=>{var d;if(r instanceof HTMLVideoElement)e.push(r);else if(r instanceof HTMLIFrameElement){let c=(d=n.getIDoc(r))==null?void 0:d.querySelector("video");c&&e.push(c)}}),e}static getIDoc(t){var e;try{return((e=t.contentWindow)==null?void 0:e.document)||t.contentDocument}catch(r){return console.log("iframe document is not reachable: "+t.src),null}}initialize(){this.observer.observe(document.body,{childList:!0}),this.controller.appendTo(document.body)}refresh(t){clearTimeout(this.searchTimeoutId),this.searchTimeoutId=setTimeout(()=>{this.videos=n.getVideos(this.document.body),this.setSpeed(this.speed)},500)}terminate(){clearTimeout(this.searchTimeoutId),this.observer.disconnect(),this.controller.el.remove(),this.videos.forEach(t=>t.playbackRate=100/100)}setSpeed(t){if(Number.isNaN(t))return;t===5?this.speed>5?this.speed=0:this.speed=10:t>300?this.speed=300:t<0?this.speed=0:this.speed=t;let e=this.speed.toString();this.controller.value.textContent=e,this.controller.range.value=e,this.videos.forEach(r=>r.playbackRate=this.speed/100),localStorage.setItem(g,e)}},s,L,S,M,f,x,y,D,I,u=class u{constructor(t){b(this,s);o(this,"el");o(this,"subBtn",document.createElement("button"));o(this,"value",document.createElement("div"));o(this,"addBtn",document.createElement("button"));o(this,"range",document.createElement("input"));this.el=document.createElement("div"),this.el[m]=t}appendTo(t){var e;return(e=t.querySelector(i))==null||e.remove(),a(this,s,S).call(this),a(this,s,L).call(this),t.append(this.el),this}get state(){return this.el[m]}};s=new WeakSet,L=function(){this.range.addEventListener("input",()=>{let t=Number.parseFloat(this.range.value);this.state.setSpeed(t)}),this.subBtn.addEventListener("click",()=>this.state.setSpeed(this.state.speed-5)),this.addBtn.addEventListener("click",()=>this.state.setSpeed(this.state.speed+5))},S=function(){this.el.setAttribute("id",i),this.el.append(a(this,s,M).call(this),a(this,s,D).call(this),a(this,s,I).call(this,u.tickMarks))},M=function(){let t=document.createElement("div");return t.classList.add("controls"),t.append(a(this,s,f).call(this),a(this,s,x).call(this),a(this,s,y).call(this)),t},f=function(){return this.subBtn=document.createElement("button"),this.subBtn.textContent="-",this.subBtn.classList.add("btn","sub"),this.subBtn},x=function(){return this.value=document.createElement("div"),this.value.textContent=this.state.speed.toString(),this.value},y=function(){return this.addBtn=document.createElement("button"),this.addBtn.textContent="+",this.addBtn.classList.add("btn","add"),this.addBtn},D=function(){return this.range=document.createElement("input"),this.range.classList.add("range"),this.range.setAttribute("type","range"),this.range.setAttribute("min","10"),this.range.setAttribute("max","300"),this.range.setAttribute("step","10"),this.range.setAttribute("list",T),this.range.value=this.state.speed.toString(),this.range},I=function(t){let e=document.createElement("datalist");e.setAttribute("id",T);let r=t.map(d=>{let c=document.createElement("option");return c.value=d.toString(),c});return e.append(...r),e},o(u,"tickMarks",[10,50,100,150,200,250,300]);var p=u;function R(n){let t=n.document,e=t.querySelector("#".concat(i));if(e){let d=e[m];d==null||d.terminate(),e.remove();return}k(t),new h(t).initialize()}R(window);})(); /** * @file A script to control the speed of html5 video playback in the browser. * @author Alexander Mandrikov - * @version 2.1.1 + * @version 2.1.2 * @license AGPLv3 * @see {@link https://github.com/nunsez/bookmarklet-video-speed GitHub} for further information. */ diff --git a/main.ts b/main.ts index abb7e62..b1dd9d9 100644 --- a/main.ts +++ b/main.ts @@ -1,7 +1,7 @@ /** * @file A script to control the speed of html5 video playback in the browser. * @author Alexander Mandrikov - * @version 2.1.1 + * @version 2.1.2 * @license AGPLv3 * @see {@link https://github.com/nunsez/bookmarklet-video-speed GitHub} for further information. */ @@ -101,8 +101,6 @@ class State { } refresh(_mutationRecords: MutationRecord[]) { - console.log("_mutationRecords", _mutationRecords); - console.log("refresh", this.searchTimeoutId, this.controller); clearTimeout(this.searchTimeoutId); this.searchTimeoutId = setTimeout(() => { @@ -112,9 +110,6 @@ class State { } terminate() { - console.log("terminate observer", this.observer); - console.log("terminate oldController", this.controller); - console.log("terminate searchTimeoutId", this.searchTimeoutId); clearTimeout(this.searchTimeoutId); this.observer.disconnect(); this.controller.el.remove(); @@ -122,7 +117,6 @@ class State { } setSpeed(newSpeed: number) { - if (!this.controller) return; if (Number.isNaN(newSpeed)) return; // The 0.05x playback rate is not in the supported playback range @@ -142,8 +136,6 @@ class State { this.controller.range.value = speedString; this.videos.forEach((v) => v.playbackRate = this.speed / 100); - console.log("set speed", this.videos, this.controller); - localStorage.setItem(STORAGE_ID, speedString); } }