Files
ArtPlayer/docs/compiled/artplayer-plugin-ads.js
T
2025-04-20 10:12:14 +08:00

8 lines
7.1 KiB
JavaScript

/*!
* artplayer-plugin-ads.js v2.0.0
* Github: https://github.com/zhw2590582/ArtPlayer
* (c) 2017-2025 Harvey Zack
* Released under the MIT License.
*/
!function(e,n,l,t,i,r,a,o){var d="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},p="function"==typeof d[t]&&d[t],s=p.i||{},u=p.cache||{},c="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function y(n,l){if(!u[n]){if(!e[n]){if(i[n])return i[n];var r="function"==typeof d[t]&&d[t];if(!l&&r)return r(n,!0);if(p)return p(n,!0);if(c&&"string"==typeof n)return c(n);var a=Error("Cannot find module '"+n+"'");throw a.code="MODULE_NOT_FOUND",a}s.resolve=function(l){var t=e[n][1][l];return null!=t?t:l},s.cache={};var o=u[n]=new y.Module(n);e[n][0].call(o.exports,s,o,o.exports,d)}return u[n].exports;function s(e){var n=s.resolve(e);return!1===n?{}:y(n)}}y.isParcelRequire=!0,y.Module=function(e){this.id=e,this.bundle=y,this.require=c,this.exports={}},y.modules=e,y.cache=u,y.parent=p,y.distDir=void 0,y.publicUrl=void 0,y.devServer=void 0,y.i=s,y.register=function(n,l){e[n]=[function(e,n){n.exports=l},{}]},Object.defineProperty(y,"root",{get:function(){return d[t]}}),d[t]=y;for(var f=0;f<n.length;f++)y(n[f]);if(l){var g=y(l);"object"==typeof exports&&"undefined"!=typeof module?module.exports=g:"function"==typeof define&&define.amd&&define(function(){return g})}}({hUYA0:[function(e,n,l,t){var i=e("@parcel/transformer-js/src/esmodule-helpers.js");i.defineInteropFlag(l),i.export(l,"default",()=>o);var r=e("bundle-text:./style.less"),a=i.interopDefault(r);function o(e){return n=>{let{version:l,utils:{errorHandle:t}}=n.constructor,i=l.split(".").map(Number);t(i[0]+i[1]/100>=5,`Artplayer.js@${l} is not compatible the artplayerPluginAds@${o.version}. Please update it to version Artplayer.js@5.x.x`);let{template:{$player:r},icons:{volume:a,volumeClose:d,fullscreenOn:p,fullscreenOff:s,loading:u},constructor:{validator:c,utils:{query:y,append:f,setStyle:g}}}=n;e=c({html:"",video:"",url:"",playDuration:5,totalDuration:10,muted:!1,i18n:{close:"关闭广告",countdown:"%s秒",detail:"查看详情",canBeClosed:"%s秒后可关闭广告"},...e},{html:"?string",video:"?string",url:"?string",playDuration:"number",totalDuration:"number",muted:"?boolean",i18n:{close:"string",countdown:"string",detail:"string",canBeClosed:"string"}});let m=null,v=null,x=null,h=null,b=null,w=null,j=0,D=null,P=!1,$=!1,k=!1;function A(e,n){return n.replace("%s",e)}function O(){P=!0,n.play(),e.video&&m.pause(),g(n.template.$ads,"display","none"),n.emit("artplayerPluginAds:skip",e)}function C(){P||(D=setTimeout(()=>{j+=1;let n=e.playDuration-j;n>=1?x.innerHTML=A(n,e.i18n.canBeClosed):(x.innerHTML=e.i18n.close,k||(k=!0)),h.innerHTML=A(e.totalDuration-j,e.i18n.countdown),j>=e.totalDuration?O():C()},1e3))}function M(){P||clearTimeout(D)}function T(){$||($=!0,function(){n.template.$ads=f(r,'<div class="artplayer-plugin-ads"></div>'),m=f(n.template.$ads,e.video?`<video class="artplayer-plugin-ads-video" src="${e.video}" loop playsInline></video>`:`<div class="artplayer-plugin-ads-html">${e.html}</div>`),w=f(n.template.$ads,'<div class="artplayer-plugin-ads-loading"></div>'),f(w,u),x=y(".artplayer-plugin-ads-close",v=f(n.template.$ads,`<div class="artplayer-plugin-ads-timer"><div class="artplayer-plugin-ads-close">${e.playDuration<=0?e.i18n.close:A(e.playDuration,e.i18n.canBeClosed)}</div><div class="artplayer-plugin-ads-countdown">${A(e.totalDuration,e.i18n.countdown)}</div></div>`)),h=y(".artplayer-plugin-ads-countdown",v),e.playDuration>=e.totalDuration&&g(x,"display","none"),n.proxy(x,"click",()=>{k&&O()});let l=y(".artplayer-plugin-ads-detail",b=f(n.template.$ads,`<div class="artplayer-plugin-ads-control"><div class="artplayer-plugin-ads-detail">${e.i18n.detail}</div><div class="artplayer-plugin-ads-muted"></div><div class="artplayer-plugin-ads-fullscreen"></div></div>`)),t=y(".artplayer-plugin-ads-muted",b),i=y(".artplayer-plugin-ads-fullscreen",b);if(e.url?n.proxy(l,"click",()=>{window.open(e.url),n.emit("artplayerPluginAds:click",e)}):g(l,"display","none"),e.video){let l=f(t,a),i=f(t,d);g(i,"display","none"),e.muted&&(m.muted=!0,g(l,"display","none"),g(i,"display","inline-flex")),n.proxy(t,"click",()=>{m.muted=!m.muted,m.muted?(g(l,"display","none"),g(i,"display","inline-flex")):(g(l,"display","inline-flex"),g(i,"display","none"))})}else g(t,"display","none");let o=f(i,p),c=f(i,s);g(c,"display","none"),n.proxy(i,"click",()=>{n.fullscreen=!n.fullscreen,n.fullscreen?(g(o,"display","inline-flex"),g(c,"display","none")):(g(o,"display","none"),g(c,"display","inline-flex"))}),n.proxy(m,"click",()=>{e.url&&window.open(e.url),n.emit("artplayerPluginAds:click",e)})}(),n.pause(),e.video?(n.proxy(m,"error",O),n.proxy(m,"loadedmetadata",()=>{C(),m.play(),g(v,"display","flex"),g(b,"display","flex"),g(w,"display","none")})):(C(),g(v,"display","flex"),g(b,"display","flex"),g(w,"display","none")),n.proxy(document,"visibilitychange",()=>{document.hidden?M():C()}))}return n.on("ready",()=>{n.once("play",T),n.once("video:playing",T)}),{name:"artplayerPluginAds",skip:O,pause:M,play:C}}}if("undefined"!=typeof document&&!document.getElementById("artplayer-plugin-ads")){let e=document.createElement("style");e.id="artplayer-plugin-ads",e.textContent=a.default,document.head.appendChild(e)}"undefined"!=typeof window&&(window.artplayerPluginAds=o)},{"bundle-text:./style.less":"jDrWj","@parcel/transformer-js/src/esmodule-helpers.js":"9pCYc"}],jDrWj:[function(e,n,l,t){n.exports=".artplayer-plugin-ads{z-index:150;color:#fff;background-color:#000;width:100%;height:100%;font-size:13px;line-height:1;position:absolute;inset:0;overflow:hidden}.artplayer-plugin-ads .artplayer-plugin-ads-html{justify-content:center;align-items:center;width:100%;height:100%;display:flex}.artplayer-plugin-ads .artplayer-plugin-ads-video{width:100%;height:100%}.artplayer-plugin-ads .artplayer-plugin-ads-timer{display:none;position:absolute;top:10px;right:10px}.artplayer-plugin-ads .artplayer-plugin-ads-timer>div{cursor:pointer;background-color:#00000080;border-radius:15px;align-items:center;margin-left:5px;padding:5px 10px;display:flex}.artplayer-plugin-ads .artplayer-plugin-ads-control{display:none;position:absolute;bottom:10px;right:10px}.artplayer-plugin-ads .artplayer-plugin-ads-control>div{cursor:pointer;background-color:#00000080;border-radius:15px;align-items:center;margin-left:5px;padding:5px 10px;display:flex}.artplayer-plugin-ads .artplayer-plugin-ads-control .art-icon svg{width:20px;height:20px}.artplayer-plugin-ads .artplayer-plugin-ads-loading{justify-content:center;align-items:center;width:100%;height:100%;display:flex;position:absolute;inset:0}"},{}],"9pCYc":[function(e,n,l,t){l.interopDefault=function(e){return e&&e.__esModule?e:{default:e}},l.defineInteropFlag=function(e){Object.defineProperty(e,"__esModule",{value:!0})},l.exportAll=function(e,n){return Object.keys(e).forEach(function(l){"default"===l||"__esModule"===l||Object.prototype.hasOwnProperty.call(n,l)||Object.defineProperty(n,l,{enumerable:!0,get:function(){return e[l]}})}),n},l.export=function(e,n,l){Object.defineProperty(e,n,{enumerable:!0,get:l})}},{}]},["hUYA0"],"hUYA0","parcelRequire4dc0",{});