mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 10:56:15 -08:00
- Removed the assignment of Artplayer to the global window object in index.js of the artplayer package. - Eliminated the window export for the template plugin in index.js, streamlining the code and reducing global scope pollution.
8 lines
2.0 KiB
JavaScript
8 lines
2.0 KiB
JavaScript
/*!
|
|
* artplayer-plugin-vtt-thumbnail.js v1.0.4
|
|
* Github: https://github.com/zhw2590582/ArtPlayer
|
|
* (c) 2017-2026 Harvey Zhao
|
|
* Released under the MIT License.
|
|
*/
|
|
function t(t){const n=t.split("."),e=n[0].split(":")||[],l=(i=n[1]||"0",o=3,s="0",i.length>o?String(i):((o-=i.length)>s.length&&(s+=s.repeat(o/s.length)),String(i)+s.slice(0,o)));var i,o,s;const r=Number(l)/1e3;return 3600*Number(e[e.length-3]||0)+60*Number(e[e.length-2]||0)+Number(e[e.length-1]||0)+r}function n(n){return async e=>{const{constructor:{utils:{setStyle:l,isMobile:i,addClass:o}},template:{$progress:s}}=e;let r=null;const a=await async function(n=""){const e=(await(await fetch(n)).text()).split(/[\n\r]/g).filter(t=>t.trim()),l=[];for(let i=1;i<e.length;i+=2){const o=e[i],s=e[i+1];if(!s.trim())continue;const r=/((?:\d{2}:)?(?:\d{2}:)?\d{2}(?:.\d{3})?) ?--> ?((?:\d{2}:)?(?:\d{2}:)?\d{2}(?:.\d{3})?)/,a=o.match(r),c=/(.*)#(\w{4})=(.*)/,u=s.match(c),d=Math.floor(t(a[1])),p=Math.floor(t(a[2]));let h=u[1];if(!/^\/|(?:https?|ftp|file):\/\//i.test(h)){const t=n.split("/");t.pop(),t.push(h),h=t.join("/")}const f={start:d,end:p,url:h},g=u[2].split(""),m=u[3].split(",");for(let t=0;t<g.length;t++)f[g[t]]=m[t];l.push(f)}return l}(n.vtt);return e.controls.add({name:"vtt-thumbnail",position:"top",index:20,style:n.style||{},mounted(t){o(t,"art-control-thumbnails"),e.on("setBar",async(n,o,c)=>{const u="played"===n&&c&&i;if("hover"===n||u){const n=s.clientWidth*o,c=o*e.duration;l(t,"display","flex");const d=a.find(t=>c>=t.start&&c<=t.end);if(!d)return l(t,"display","none");n>0&&n<s.clientWidth?function(t,n,e){l(t,"backgroundImage",`url(${n.url})`),l(t,"height",`${n.h}px`),l(t,"width",`${n.w}px`),l(t,"backgroundPosition",`-${n.x}px -${n.y}px`),e<=n.w/2?l(t,"left",0):e>s.clientWidth-n.w/2?l(t,"left",s.clientWidth-n.w+"px"):l(t,"left",e-n.w/2+"px")}(t,d,n):i||l(t,"display","none"),u&&(clearTimeout(r),r=setTimeout(()=>{l(t,"display","none")},500))}})}}),{name:"artplayerPluginVttThumbnail"}}}export{n as default};
|