peertube-plugin-premium-members 3.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client/common.ts CHANGED
@@ -3168,12 +3168,23 @@ function saveNativePeerTubeResumeSnapshot(
3168
3168
  const previous = getStoredNativePeerTubeResumeForRoute(routeSignature, NATIVE_PEERTUBE_RESUME_TTL)
3169
3169
  const memory = nativePeerTubeLastGoodResumeByRoute.get(routeSignature) || null
3170
3170
  const snapPosition = Math.max(0, Math.floor(Number(snap.currentTime || 0)))
3171
+ const memoryPosition = Math.max(0, Math.floor(Number(memory?.positionSeconds || 0)))
3172
+ const previousPosition = Math.max(0, Math.floor(Number(previous?.positionSeconds || 0)))
3173
+ const fallbackPosition = memoryPosition || previousPosition
3171
3174
 
3172
- // ✅ v12.3: ห้ามเลือก max เสมอ เพราะถ้าผู้ใช้ลากย้อนกลับเอง เวลาปลายคลิปเก่าจะชนะ
3173
- // ลำดับที่ถูก: currentTime ที่อ่านได้ตอนนี้ > memory ล่าสุด > localStorage เก่า
3174
- const bestPosition = snapPosition >= 2
3175
- ? snapPosition
3176
- : Math.max(0, Math.floor(Number(memory?.positionSeconds ?? previous?.positionSeconds ?? 0)))
3175
+ // ✅ v12.4: แก้ regression จาก v12.3
3176
+ // ตอนมือถือ hidden/destroy บางรอบ VideoJS/HLS reset ค่า currentTime กลับมาเป็น 2-3 วิ
3177
+ // ถ้าใช้ currentTime ตอนนั้นชนะทันที จะเขียนทับ cache ดี ๆ แล้ว reload กลับไปต้นคลิป
3178
+ // หลักใหม่:
3179
+ // - ถ้า currentTime ตอนนี้น้อยมาก (< 10s) แต่ memory/localStorage มีตำแหน่งเก่ามากกว่า ให้ถือว่า currentTime นี้ไม่น่าเชื่อถือ
3180
+ // - ถ้า user ลากย้อนจริงไปมากกว่า 10s ให้ยอมรับ currentTime นั้น เพื่อไม่กลับไปปลายคลิปเก่า
3181
+ // - ถ้า currentTime อ่านไม่ได้/0 ให้ fallback memory > localStorage
3182
+ let bestPosition = fallbackPosition
3183
+
3184
+ if (snapPosition >= 2) {
3185
+ const suspiciousEarlyReset = snapPosition < 10 && fallbackPosition >= 10
3186
+ bestPosition = suspiciousEarlyReset ? fallbackPosition : snapPosition
3187
+ }
3177
3188
 
3178
3189
  const videoUuid = getNativePeerTubeVideoIdSync() || memory?.videoUuid || previous?.videoUuid
3179
3190
 
@@ -3254,7 +3265,9 @@ function isNativePeerTubeMediaCompleted(media: HTMLMediaElement): boolean {
3254
3265
  const position = getNativePeerTubePlayerCurrentTime(media)
3255
3266
 
3256
3267
  // ✅ จบจริงหรือเกือบสุดมาก ๆ เท่านั้น ไม่ใช้ threshold กว้างจนดูใกล้จบแล้วถูกล้างก่อน
3257
- return duration > 0 && position > 0 && duration - position <= 1.5
3268
+ // ต้องมีทั้งระยะเหลือไม่เกิน 1.5 วิ และดูไปแล้วอย่างน้อย 99.5%
3269
+ // กันบาง browser รายงาน duration/currentTime เพี้ยนตอน source ถูก reset แล้วล้าง cache เร็วเกินไป
3270
+ return duration > 0 && position > 0 && duration - position <= 1.5 && (position / duration) >= 0.995
3258
3271
  }
3259
3272
 
3260
3273
  function completeNativePeerTubeResume(media: HTMLMediaElement): void {
@@ -1 +1 @@
1
- var Sn=Object.defineProperty,En=Object.defineProperties;var Mn=Object.getOwnPropertyDescriptors;var Yt=Object.getOwnPropertySymbols;var Rn=Object.prototype.hasOwnProperty,Ln=Object.prototype.propertyIsEnumerable;var er=(u,l,m)=>l in u?Sn(u,l,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[l]=m,D=(u,l)=>{for(var m in l||(l={}))Rn.call(l,m)&&er(u,m,l[m]);if(Yt)for(var m of Yt(l))Ln.call(l,m)&&er(u,m,l[m]);return u},ae=(u,l)=>En(u,Mn(l));var Be=class{constructor(l){this.rootEl=l}renderRow(l,m){return this.div([this.div(l,m?"col-12 col-lg-4 col-xl-3":"col-12"),...m?[this.div(m,"col-12 col-lg-8 col-xl-9")]:[]],"row")}div(l,m){let f=document.createElement("div");return m&&(f.className=m),l.forEach(b=>f.appendChild(b)),f}a(l,m){let f=document.createElement("a");f.innerHTML=l;for(let b in m)f.setAttribute(b,m[b]);return f}h2(l){let m=document.createElement("h2");return m.innerText=l,m}h3(l){let m=document.createElement("h2");return m.innerText=l,m}p(l,m){let f=document.createElement("p");return f.innerHTML=l,m&&(f.className=m),f}img(l,m){let f=document.createElement("img");return f.src=l,f.className=m,f}ul(l,m){let f=document.createElement("ul");return m&&(f.className=m),l.forEach(b=>{let E=document.createElement("li");E.innerText=b,f.appendChild(E)}),f}};var tr="enable-plugin";var ht=(u,l)=>{"gtag"in window&&window.gtag("event",u,D({event_category:"premium-users"},l))},se=(u,l)=>new Intl.NumberFormat(navigator.language,{style:"currency",currency:l,minimumFractionDigits:0}).format(u),yt=u=>{var l;return!((l=u.coupon)!=null&&l.valid)||!u.unit_amount?null:u.coupon.amount_off?(u.unit_amount-u.coupon.amount_off)/100:u.coupon.percent_off?Math.round((u.unit_amount-u.unit_amount*(u.coupon.percent_off/100))/100):null};var _n=u=>{var l,m,f;return(l=u.coupon)!=null&&l.percent_off?"".concat(u.coupon.percent_off," %"):se((f=(m=u.coupon)==null?void 0:m.amount_off)!=null?f:0,u.currency)},In=async(u,l)=>{var m,f,b;return((m=u.recurring)==null?void 0:m.interval)==="month"?(await l("discount the first MONTHS_COUNT months.")).replace("MONTHS_COUNT",String((f=u.coupon)==null?void 0:f.duration_in_months)):((b=u.recurring)==null?void 0:b.interval)==="year"?l("discount for a whole year."):""},xn=u=>{var m,f,b,E,B,M,V,N,T,S;let l=0;return((m=u.recurring)==null?void 0:m.interval)==="month"?(u.unit_amount&&((f=u.coupon)!=null&&f.amount_off)&&((b=u.coupon)!=null&&b.duration_in_months)&&(l=u.coupon.amount_off*((E=u.coupon)==null?void 0:E.duration_in_months)/100),u.unit_amount&&((B=u.coupon)!=null&&B.percent_off)&&((M=u.coupon)!=null&&M.duration_in_months)&&(l=u.unit_amount*(u.coupon.percent_off/100)*((V=u.coupon)==null?void 0:V.duration_in_months)/100)):((N=u.recurring)==null?void 0:N.interval)==="year"&&(u.unit_amount&&((T=u.coupon)!=null&&T.amount_off)&&(l=u.coupon.amount_off*12/100),u.unit_amount&&((S=u.coupon)!=null&&S.percent_off)&&(l=u.unit_amount*(u.coupon.percent_off/100)/100)),l},An=async(u,l)=>{var b;let m=yt(u),f;return m!==null?f='\n <span class="original-price">\n '.concat(se(u.unit_amount/100,u.currency),"</span>\n ").concat(se(m,u.currency)):f=se(u.unit_amount/100,u.currency),(b=u.recurring)!=null&&b.interval?f+=" / "+await l(u.recurring.interval):f+=" / "+await l("1 \u0E40\u0E14\u0E37\u0E2D\u0E19"),f},rr=async({buttonOnClick:u,price:l,uiBuilder:m,translate:f})=>{var F,q;let b=yt(l),E=await In(l,f),B=xn(l),M=_n(l),V=await An(l,f),N=!!u,T="";(F=l.recurring)!=null&&F.interval?T=await f("Pay "+(l.recurring.interval==="day"?"daily":l.recurring.interval+"ly")):T=await f("\u0E0A\u0E33\u0E23\u0E30 1 \u0E40\u0E14\u0E37\u0E2D\u0E19 (QR \u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E40\u0E1E\u0E22\u0E4C)");let S=m.a(V,{class:"primary-button peertube-button-link mb-4","data-testid":"premium_users-button-pay_"+(((q=l.recurring)==null?void 0:q.interval)||"onetime")});return N&&S.addEventListener("click",u),m.div([m.p(T,"fw-bold"),...b===null?[]:[m.ul([M+" "+E,(await f("You'll save AMOUNT_TO_SAVE.")).replace("AMOUNT_TO_SAVE",String(se(Math.round(B),l.currency)))],"text-start")],...N?[S]:[m.p(V,"mt-auto")]],"d-flex flex-grow-1 flex-column")};var nr={name:"peertube-plugin-premium-members",description:"peertube-plugin-premium-members",version:"3.2.0",author:"Vee",bugs:"",clientScripts:[{script:"dist/client/my-account/index.js",scopes:["my-account"]},{script:"dist/client/common.js",scopes:["common"]},{script:"dist/client/video-edit.js",scopes:["video-edit"]},{script:"dist/client/admin-manage.js",scopes:["common"]}],css:["dist/assets/style.css"],engine:{peertube:">=6.0.0"},homepage:"",keywords:["peertube","plugin"],library:"./dist/server/server/main.js",scripts:{clean:"rm -rf dist/*",prepare:"npm run build","build:client":"node ./scripts/build.cjs","build:server":"tsc --build server/tsconfig.json","build:styles":"npx --yes sass --no-source-map assets:dist/assets",build:"npm-run-all -s clean check:client:tsc -p build:server build:client build:styles","check:client:tsc":"npx tsc --p client/tsconfig.json --noEmit","lint:script":"npx eslint .",test:"npm-run-all -p lint:script test:unit","test:unit":"TS_NODE_PROJECT=server/tsconfig.test.json mocha server/*.spec.ts","test:e2e":"cd demo && npm ci && npm test"},staticDirs:{images:"public/images"},translations:{"sv-SE":"./languages/sv.json","th-TH":"./languages/th.json",th:"./languages/th.json"},devDependencies:{"@tsconfig/node16":"^16.0.0","@types/mocha":"^10.0.8","@typescript-eslint/eslint-plugin":"^8.9.0","@typescript-eslint/parser":"^8.9.0",esbuild:"^0.24.0",eslint:"^9.12.0","eslint-config-love":"^87.0.0",globals:"^15.3.0",mocha:"^10.7.3","npm-run-all":"^4.1.5",tsx:"^4.19.1",typescript:"^5.4.3"},dependencies:{"@peertube/peertube-types":"^6.3.0","@types/gtag.js":"^0.0.20","@types/sequelize":"^4.28.20",express:"^4.19.2","short-uuid":"^5.2.0",stripe:"^18.1.0"}};var K=class{constructor(l){this.pluginBasePath="/plugins/".concat(nr.name.replace("peertube-plugin-",""),"/router");this.getAuthHeader=l||(()=>{})}async get(l){return fetch(l,{method:"GET",headers:this.getAuthHeader(),credentials:"include"}).then(async m=>m.json())}async patch(l,m){await fetch(l,{method:"PATCH",headers:ae(D({},this.getAuthHeader()),{"Content-Type":"application/json"}),credentials:"include",body:JSON.stringify(m)})}async post(l,m){return fetch(l,{method:"POST",headers:ae(D({},this.getAuthHeader()),{"Content-Type":"application/json"}),credentials:"include",body:JSON.stringify(m)}).then(async f=>f.json())}async delete(l){return fetch(l,{method:"DELETE",headers:this.getAuthHeader(),credentials:"include"}).then(async m=>m.json())}async getMe(){return this.get("/api/v1/users/me")}async getPrices(){return this.get(this.pluginBasePath+"/price")}async getSubscription(){return this.get(this.pluginBasePath+"/subscription")}async updateSubscription(l){return this.patch(this.pluginBasePath+"/subscription",l)}async createCheckout({allowPromotionCodes:l,couponId:m,priceId:f,paymentMode:b,paymentMethod:E}){return this.post(this.pluginBasePath+"/checkout",{allowPromotionCodes:l,couponId:m,priceId:f,paymentMode:b,paymentMethod:E})}async getRumblePlaybackInfo(l){return this.get(this.pluginBasePath+"/rumble/playback-info/".concat(encodeURIComponent(l)))}async saveRumbleProgress(l){return this.post(this.pluginBasePath+"/rumble/progress",l)}async saveRumbleDuration(l){return this.post(this.pluginBasePath+"/rumble/duration",l)}async getRumbleProgress(l){return this.get(this.pluginBasePath+"/rumble/progress/".concat(encodeURIComponent(l)))}async saveNativePeerTubeProgress(l){return this.post(this.pluginBasePath+"/native/progress",l)}async getNativePeerTubeProgress(l){return this.get(this.pluginBasePath+"/native/progress/".concat(encodeURIComponent(l)))}async getRumbleHistory(l=50,m=0){return this.get(this.pluginBasePath+"/rumble/history?limit=".concat(l,"&offset=").concat(m))}async deleteRumbleHistoryItem(l){return this.delete(this.pluginBasePath+"/rumble/history/".concat(encodeURIComponent(l)))}async clearRumbleHistory(){return this.delete(this.pluginBasePath+"/rumble/history")}};async function Jn({peertubeHelpers:u,registerClientRoute:l,registerHook:m}){let b=!!(await u.getSettings())[tr];m({target:"filter:left-menu.links.create.result",handler:async e=>{if(!b)return e;let t=!1;if(u.isLoggedIn())try{let i=u.getAuthHeader;t=(await new K(i).getMe()).isPremium===!0}catch(i){console.error("\u274C [Premium Plugin] Failed to fetch premium status for menu:",i)}let r=u.isLoggedIn()?"/my-account/p/premium":"/p/premium",n=await u.translate(t?"Premium account":"Become premium");return e.map(i=>i.key==="quick-access"?ae(D({},i),{links:[...i.links,{path:r,icon:t?"premium":void 0,label:n,shortLabel:n,isPrimaryButton:!t}]}):u.isLoggedIn()&&i.key==="my-library"?ae(D({},i),{links:[...i.links,{path:"/p/rumble-history",label:"\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21",shortLabel:"\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34",icon:"history"}]}):i)}}),m({target:"filter:internal.common.svg-icons.get-content.result",handler:(e,t)=>t.name==="premium"?'\n\n <svg\n\n fill="gray"\n\n version="1.1"\n\n xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"\n\n viewBox="0 0 45.402 45.402"\n\n xml:space="preserve">\n\n <g>\n\n <path d="M41.267,18.557H26.832V4.134C26.832,1.851,24.99,0,22.707,0c-2.283,0-4.124,1.851-4.124,4.135v14.432H4.141\n\n c-2.283,0-4.139,1.851-4.138,4.135c-0.001,1.141,0.46,2.187,1.207,2.934c0.748,0.749,1.78,1.222,2.92,1.222h14.453V41.27\n\n c0,1.142,0.453,2.176,1.201,2.922c0.748,0.748,1.777,1.211,2.919,1.211c2.282,0,4.129-1.851,4.129-4.133V26.857h14.435\n\n c2.283,0,4.134-1.867,4.133-4.15C45.399,20.425,43.548,18.557,41.267,18.557z"/>\n\n </g>\n\n </svg>':e});let E=e=>()=>{let t=new URLSearchParams(window.location.search).get("redirect");t&&m({target:"action:auth-user.logged-in",handler:()=>{ht("tutorial_complete",{event_label:e}),window.location.href=t}})};if(m({target:"action:login.init",handler:E("login")}),m({target:"action:signup.register.init",handler:E("signup")}),l({route:"/premium",title:await u.translate("Become premium"),onMount:async({rootEl:e})=>{if(u.isLoggedIn()){window.location.href="/my-account/p/premium";return}ht("tutorial_begin");let r=await new K().getPrices(),n=new Be(e),i=await Promise.all(r.map(s=>rr({price:s,uiBuilder:n,translate:u.translate}))),o=n.div([n.img("/client/assets/images/icons/icon-192x192.png","instance-logo"),n.h2(await u.translate("Become a premium user")),n.p(await u.translate("Get access to premium videos and helps us to continue our work.")),n.div(i.map(s=>n.div([s],"col-12 col-sm-6 d-flex")),"prices-alternatives row my-5 mx-auto"),n.div([n.a(await u.translate("Create an account"),{class:"primary-button peertube-button-link button-md mb-2",href:"/signup?redirect=/my-account/p/premium","data-testid":"premium_users-button-create_account"}),n.p(await u.translate("or"),"mb-0"),n.a(await u.translate("Login"),{class:"secondary-button peertube-button-link mt-2 button-md",href:"/login?redirect=/my-account/p/premium"})],"action-buttons d-flex justify-content-center flex-column mb-4 mx-sm-auto")],"plugin-premium-users become-premium margin-content pt-4 text-center mx-auto px-4 px-md-0");e.appendChild(o)}}),!b)return;function B(e){e=Math.max(0,Math.floor(Number(e)||0));let t=Math.floor(e/3600),r=Math.floor(e%3600/60),n=e%60;return t>0?"".concat(t,":").concat(String(r).padStart(2,"0"),":").concat(String(n).padStart(2,"0")):"".concat(r,":").concat(String(n).padStart(2,"0"))}function M(e){return String(e!=null?e:"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function V(e){var r,n;let t=(e==null?void 0:e.thumbnailPath)||(e==null?void 0:e.previewPath)||(e==null?void 0:e.thumbnailUrl)||(e==null?void 0:e.previewUrl)||((n=(r=e==null?void 0:e.files)==null?void 0:r[0])==null?void 0:n.thumbnailPath)||"";return t?/^https?:\/\//i.test(t)?t:"".concat(window.location.origin).concat(t.startsWith("/")?"":"/").concat(t):""}async function N(e){var n;if(e.innerHTML='<div class="margin-content"><h1>\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</h1><p>\u0E01\u0E33\u0E25\u0E31\u0E07\u0E42\u0E2B\u0E25\u0E14...</p></div>',!u.isLoggedIn()){e.innerHTML='<div class="margin-content"><h1>\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</h1><p>\u0E01\u0E23\u0E38\u0E13\u0E32\u0E40\u0E02\u0E49\u0E32\u0E2A\u0E39\u0E48\u0E23\u0E30\u0E1A\u0E1A\u0E01\u0E48\u0E2D\u0E19</p></div>';return}let t=new K(u.getAuthHeader),r=()=>N(e);try{let i=await t.getRumbleHistory(50,0),o=Array.isArray(i==null?void 0:i.data)?i.data:[];if(o.length===0){e.innerHTML='\n <div class="margin-content">\n <h1>\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</h1>\n <p>\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</p>\n </div>\n ';return}let s=await Promise.all(o.map(async a=>{var j,A,G,Se;let d=a.videoUuid,p="/w/".concat(encodeURIComponent(a.videoUuid)),g="",v="";try{let oe=await fetch("/api/v1/videos/".concat(encodeURIComponent(a.videoUuid)),{headers:((j=u.getAuthHeader)==null?void 0:j.call(u))||{},credentials:"include"});if(oe.ok){let _=await oe.json();d=_.name||d,_.shortUUID&&(p="/w/".concat(_.shortUUID)),g=V(_),v=((A=_.channel)==null?void 0:A.displayName)||((G=_.account)==null?void 0:G.displayName)||((Se=_.account)==null?void 0:Se.name)||""}}catch(oe){}let L=Math.max(0,Math.floor(Number(a.lastPositionSeconds||0))),y=Math.max(0,Math.floor(Number(a.durationSeconds||0))),h=Number(a.watchedPercent||0),P="".concat(p).concat(p.includes("?")?"&":"?","rumbleStart=").concat(L,"&rumbleAutoplay=1"),x=String(a.videoUuid||"");return'\n <div class="premium-rumble-history-row" data-video-uuid="'.concat(M(x),'" style="display:flex;gap:14px;align-items:flex-start;padding:14px 0;border-bottom:1px solid var(--greyForegroundColor, #ddd);">\n <a href="').concat(M(P),'" style="display:block;width:180px;max-width:35%;flex:0 0 180px;background:#111;border-radius:4px;overflow:hidden;">\n ').concat(g?'<img src="'.concat(M(g),'" alt="" loading="lazy" style="display:block;width:100%;aspect-ratio:16/9;object-fit:cover;">'):'<div style="width:100%;aspect-ratio:16/9;background:#111;"></div>','\n </a>\n <div style="min-width:0;flex:1;">\n <a href="').concat(M(P),'" style="font-weight:600;font-size:16px;line-height:1.35;display:block;word-break:break-word;">').concat(M(d),"</a>\n ").concat(v?'<div style="font-size:13px;opacity:.75;margin-top:4px;">'.concat(M(v),"</div>"):"",'\n <div style="font-size:13px;opacity:.85;margin-top:5px;">\u0E14\u0E39\u0E16\u0E36\u0E07 ').concat(B(L)," / ").concat(B(y)," (").concat(h,'%)</div>\n <div style="margin-top:10px;display:flex;gap:8px;align-items:center;flex-wrap:wrap;">\n <button class="peertube-button secondary-button button-sm premium-rumble-delete-history" data-video-uuid="').concat(M(x),'" type="button">\u0E25\u0E1A\u0E2D\u0E2D\u0E01\u0E08\u0E32\u0E01\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34</button>\n </div>\n </div>\n </div>\n ')}));e.innerHTML='\n <div class="margin-content">\n <div style="display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;margin-bottom:16px;">\n <div>\n <h1 style="margin-bottom:4px;">\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</h1>\n </div>\n <button class="peertube-button secondary-button premium-rumble-clear-history" type="button">\u0E25\u0E49\u0E32\u0E07\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E17\u0E31\u0E49\u0E07\u0E2B\u0E21\u0E14</button>\n </div>\n <div>'.concat(s.join(""),"</div>\n </div>\n "),e.querySelectorAll(".premium-rumble-delete-history").forEach(a=>{a.addEventListener("click",async()=>{let d=a.dataset.videoUuid;if(d)try{await t.deleteRumbleHistoryItem(d),await r()}catch(p){console.error("\u274C [Premium Rumble] delete history failed:",p)}})}),(n=e.querySelector(".premium-rumble-clear-history"))==null||n.addEventListener("click",async()=>{if(window.confirm("\u0E25\u0E49\u0E32\u0E07\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21\u0E17\u0E31\u0E49\u0E07\u0E2B\u0E21\u0E14?"))try{await t.clearRumbleHistory(),await r()}catch(a){console.error("\u274C [Premium Rumble] clear history failed:",a)}})}catch(i){console.error("\u274C [Premium Rumble] Failed to load history:",i),e.innerHTML='<div class="margin-content"><h1>\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</h1><p>\u0E42\u0E2B\u0E25\u0E14\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08</p></div>'}}l({route:"/rumble-history",title:"\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21",parentRoute:"/",onMount:async({rootEl:e})=>N(e)});let T=new Map,S=[],F=!1,q=window.location.origin,Ee=new AbortController;function ir(){Ee.abort(),Ee=new AbortController,S=[],T.clear(),F=!1}async function or(){if(!(F||S.length===0)){for(F=!0;S.length>0;){let e=S[0];if(!e)break;try{let t=await fetch(e.url,{signal:Ee.signal});if(t.status===429){await new Promise(r=>setTimeout(r,1e3));continue}S.shift(),e.resolve(t),T.delete(e.url)}catch(t){S.shift(),e.resolve(null),T.delete(e.url)}Ee.signal.aborted||await new Promise(t=>setTimeout(t,100))}F=!1}}function Me(e){if(T.has(e))return T.get(e);let t=new Promise(r=>{S.push({url:e,resolve:r}),or()});return T.set(e,t),t}function gt(e){return"premium_cache_checked_videos_".concat(e)}function bt(e){return"premium_cache_checked_shortUUID_".concat(e)}function Z(e){return"premium_cache_map_uuid_to_short_".concat(e)}function J(e){return"premium_cache_map_short_to_uuid_".concat(e)}function ar(e){e=Math.max(0,Math.floor(Number(e)||0));let t=Math.floor(e/3600),r=Math.floor(e%3600/60),n=e%60;return t>0?"".concat(t,":").concat(String(r).padStart(2,"0"),":").concat(String(n).padStart(2,"0")):"".concat(r,":").concat(String(n).padStart(2,"0"))}function sr(e){if(!e)return;let t=e.pluginData||{},r=t["use-rumble-player"]==="true"||t["use-rumble-player"]===!0||t["use-rumble-player"]==="1",n=Number(t["rumble-duration-seconds"]||0);if(!r||!n||n<=0)return;[e.uuid,e.shortUUID].filter(Boolean).forEach(o=>{sessionStorage.setItem(ye(o),"true"),sessionStorage.setItem(Tt(o),String(Math.floor(n)))})}function ur(e){try{let r=new URL(e,window.location.origin).pathname.match(/^\/w\/(?!p\/)([a-zA-Z0-9-]+)/);return(r==null?void 0:r[1])||null}catch(t){let r=e.match(/\/w\/(?!p\/)([a-zA-Z0-9-]+)/);return(r==null?void 0:r[1])||null}}let Ve=new Set;function lr(e,t){let r=Math.max(1,Math.floor(Number(t)||1)),n=Math.floor((r-1)/100)*100,i="".concat(e,"_").concat(n);Ve.has(i)||sessionStorage.getItem("premium_rumble_playlist_duration_page_".concat(i))!=="true"&&(Ve.add(i),setTimeout(async()=>{try{let o=await Me("".concat(q,"/api/v1/video-playlists/").concat(e,"/videos?start=").concat(n,"&count=100"));if(!o||!o.ok)return;let s=await o.json();O(s,"/api/v1/video-playlists/".concat(e,"/videos?start=").concat(n,"&count=100")),sessionStorage.setItem("premium_rumble_playlist_duration_page_".concat(i),"true"),setTimeout(ue,120)}catch(o){console.warn("\u26A0\uFE0F [Premium Rumble] playlist duration metadata fetch failed:",o)}finally{Ve.delete(i)}},250))}function cr(e){let t=e.closest('a[href*="/w/"]'),r=e.closest('a[href*="/w/"], .video-thumbnail, .video-miniature, .video-wrapper, .video, my-video-miniature, my-video-playlist-element-miniature'),n=t||(r==null?void 0:r.querySelector('a[href*="/w/"]'));if(!(n!=null&&n.href))return null;let i=ur(n.href);if(i)return i;let o=Mr(n.href);if(o){let s=sessionStorage.getItem(We(o.playlistUuid,o.position));if(s)return s;lr(o.playlistUuid,o.position)}return null}function ue(){document.querySelectorAll(".duration-overlay").forEach(e=>{let t=e,r=cr(t);if(!r)return;let n=Number(sessionStorage.getItem(Tt(r))||0);if(!n||n<=0)return;let i=ar(n);t.textContent!==i&&(t.textContent=i),t.setAttribute("aria-label","Video duration is ".concat(i))})}function mr(e,t){e!=null&&e.uuid&&(sessionStorage.setItem(gt(e.uuid),"true"),e.shortUUID&&(sessionStorage.setItem(bt(e.shortUUID),"true"),sessionStorage.setItem(Z(e.uuid),e.shortUUID),sessionStorage.setItem(J(e.shortUUID),e.uuid)),t?(sessionStorage.setItem("premium_cache_videos_".concat(e.uuid),"true"),e.shortUUID&&sessionStorage.setItem("premium_cache_shortUUID_".concat(e.shortUUID),"true")):(sessionStorage.removeItem("premium_cache_videos_".concat(e.uuid)),e.shortUUID&&sessionStorage.removeItem("premium_cache_shortUUID_".concat(e.shortUUID))))}function vt(e){let t=e.match(/\/api\/v1\/videos\/([^/?#]+)/);return t!=null&&t[1]?decodeURIComponent(t[1]):null}function dr(){let e=[];for(let t=0;t<sessionStorage.length;t++){let r=sessionStorage.key(t);r&&r.startsWith("premium_cache_playlist_")&&e.push(r)}e.forEach(t=>sessionStorage.removeItem(t))}function pr(e){let t=sessionStorage.getItem(Z(e)),r=sessionStorage.getItem(J(e)),n=new Set([e]);t&&n.add(t),r&&n.add(r),n.forEach(i=>{sessionStorage.removeItem("premium_cache_videos_".concat(i)),sessionStorage.removeItem("premium_cache_shortUUID_".concat(i)),sessionStorage.removeItem(gt(i)),sessionStorage.removeItem(bt(i)),sessionStorage.removeItem(Z(i)),sessionStorage.removeItem(J(i))}),dr()}function fr(e){let t=e.querySelector(".custom-member-badge");t&&t.remove(),e.classList.remove("has-premium-badge"),delete e.dataset.premiumFetchRequested}function wt(e){let t=sessionStorage.getItem(Z(e)),r=sessionStorage.getItem(J(e)),n=new Set([e]);t&&n.add(t),r&&n.add(r),pr(e);let i=["my-video-miniature",".video-miniature","ptb-video-miniature","my-video-playlist-element-miniature",".video-playlist-miniature","my-video-cell","my-video-list-element","my-user-video-history-element","tr.p-selectable-row","my-video-playlist-element","my-recommended-videos my-video-miniature"].join(", ");document.querySelectorAll(i).forEach(o=>{let s=o.tagName.toLowerCase()==="a"?o:o.querySelector('a.video-title, a.title, a.video-name, a.pt-router-link, a[href*="/w/"], a[href*="/video-playlists/"]');if(!s)return;let a=s.href||"",d=!1;for(let p of n)if(a.includes("/w/".concat(p))){d=!0;break}!d&&(a.includes("/w/p/")||a.includes("/video-playlists/"))&&(d=!0),d&&fr(o)}),setTimeout(X,50),setTimeout(X,250)}function Pt(){let e=[];for(let t=0;t<sessionStorage.length;t++){let r=sessionStorage.key(t);r&&r.startsWith("premium_cache_")&&e.push(r)}e.forEach(t=>sessionStorage.removeItem(t)),T.clear(),document.querySelectorAll(".has-premium-badge, [data-premium-fetch-requested]").forEach(t=>{let r=t.querySelector(".custom-member-badge");r&&r.remove(),t.classList.remove("has-premium-badge"),delete t.dataset.premiumFetchRequested}),setTimeout(X,200)}function O(e,t){let r=!1;e&&e.data&&Array.isArray(e.data)&&e.data.forEach(n=>{let i=n.video||n;if(i&&i.uuid){let o=t.match(/\/api\/v1\/video-playlists\/([a-zA-Z0-9-]+)/);if(o!=null&&o[1]&&n.position){let a=i.shortUUID||i.uuid;sessionStorage.setItem(We(o[1],n.position),a),i.shortUUID&&(sessionStorage.setItem(J(i.shortUUID),i.uuid),sessionStorage.setItem(Z(i.uuid),i.shortUUID))}sr(i);let s=!1;if(i.pluginData){let a=i.pluginData["is-premium-content"];s=a==="true"||a===!0||a==="1"}if(s||(s=sessionStorage.getItem("premium_cache_videos_".concat(i.uuid))==="true"),mr(i,s),s){if(n.position&&t.includes("/video-playlists/")){let a=t.match(/\/api\/v1\/video-playlists\/([a-zA-Z0-9-]+)/);a&&a[1]&&sessionStorage.setItem("premium_cache_playlist_".concat(a[1],"_pos_").concat(n.position),"true")}r=!0}else if(n.position&&t.includes("/video-playlists/")){let a=t.match(/\/api\/v1\/video-playlists\/([a-zA-Z0-9-]+)/);a&&a[1]&&sessionStorage.removeItem("premium_cache_playlist_".concat(a[1],"_pos_").concat(n.position))}}}),setTimeout(ue,150),r&&setTimeout(X,100)}window.processPeerTubePremiumData=O;let hr=XMLHttpRequest.prototype.open,yr=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(e,t){return this._customMethod=e.toUpperCase(),this._customUrl=t.toString(),hr.apply(this,arguments)},XMLHttpRequest.prototype.send=function(){return this.addEventListener("load",function(){let e=this._customUrl,t=this._customMethod;if(e){if(t==="PUT"&&e.includes("/api/v1/videos/")&&!e.includes("/views")&&!e.includes("/rate")&&!e.includes("/passwords")&&this.status>=200&&this.status<300){let n=vt(e);setTimeout(n?()=>wt(n):Pt,300)}if(e.includes("/api/v1/"))try{let n=typeof this.response=="string"?JSON.parse(this.response):this.response;n&&n.data&&Array.isArray(n.data)&&O(n,e)}catch(n){}}}),yr.apply(this,arguments)};let gr=window.fetch;window.fetch=async function(...e){let t=e[0]instanceof Request?e[0]:null,r=t?t.url:e[0],i=(t?t.method.toUpperCase():e[1]&&e[1].method?e[1].method.toUpperCase():"GET")==="PUT"&&r.includes("/api/v1/videos/")&&!r.includes("/views")&&!r.includes("/rate")&&!r.includes("/passwords"),o=await gr.apply(this,e);if(i&&o.ok){let a=vt(r);setTimeout(a?()=>wt(a):Pt,300)}let s=o.clone();try{r.includes("/api/v1/")&&s.json().then(a=>{a&&a.data&&Array.isArray(a.data)&&O(a,r)}).catch(()=>{})}catch(a){}return o};function br(e,t="append",r="block"){var a;if(!e)return!1;let n=t==="after"?e.parentNode:e;if(!n||n.querySelector(".custom-member-badge"))return!1;let i=document.createElement("div");i.className="custom-member-badge";let o="display: inline-flex; align-items: center; color: #127a1b; font-size: 12px; font-weight: 500; margin-top: 4px; margin-bottom: 2px; border: none; outline: none; box-shadow: none;";r==="block"?o+=" width: 100%;":r==="inline"&&(o+=" margin-left: 8px; vertical-align: middle;"),i.style.cssText=o,i.innerHTML='<svg style="width: 14px; height: 14px; margin-right: 4px; fill: currentColor;" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm4.24 16L12 15.45 7.77 18l1.12-4.81-3.73-3.23 4.92-.42L12 5l1.92 4.53 4.92.42-3.73 3.23L16.23 18z"/></svg>\u0E40\u0E09\u0E1E\u0E32\u0E30\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01';let s=r==="block"?(()=>{let d=document.createElement("div");return d.style.cssText="display: block; width: 100%; clear: both; border: none; margin: 0; padding: 0;",d.appendChild(i),d})():i;return t==="after"?(a=e.parentNode)==null||a.insertBefore(s,e.nextSibling):e.appendChild(s),!0}async function vr(e,t){let r="premium_cache_playlist_".concat(e,"_pos_").concat(t);if(sessionStorage.getItem(r)==="true")return!0;let n=100,i=0;try{for(;;){let o=await Me("".concat(q,"/api/v1/video-playlists/").concat(e,"/videos?start=").concat(i,"&count=").concat(n));if(!o||!o.ok)break;let s=await o.json();if(O(s,"/api/v1/video-playlists/".concat(e,"/videos?start=").concat(i,"&count=").concat(n)),sessionStorage.getItem(r)==="true")return!0;if((Array.isArray(s==null?void 0:s.data)?s.data:[]).length<n)break;i+=n}}catch(o){}return!1}function X(){let e=["my-video-miniature",".video-miniature","ptb-video-miniature","my-video-playlist-element-miniature",".video-playlist-miniature","my-video-cell","my-video-list-element","my-user-video-history-element","tr.p-selectable-row","my-video-playlist-element","my-recommended-videos my-video-miniature"].join(", "),t=document.querySelectorAll(e),r=window.location.pathname;t.forEach(n=>{if(n.querySelector(".custom-member-badge")){n.classList.add("has-premium-badge");return}let i=n.tagName.toLowerCase()==="a"?n:n.querySelector('a.video-title, a.title, a.video-name, a.pt-router-link, a[href*="/w/"], a[href*="/video-playlists/"]');if(i)try{let o=new URL(i.href,window.location.origin),s=o.searchParams.get("playlistPosition"),a=null,d=!1,p=n.tagName.toLowerCase().includes("playlist")||n.classList.contains("video-playlist-miniature")||n.classList.contains("my-video-playlist-element");if(o.pathname.includes("/w/p/")||o.pathname.includes("/video-playlists/")||p){let g=o.pathname.match(/(?:\/w\/p\/|\/video-playlists\/)([a-zA-Z0-9-]+)/);g&&(a=g[1]),d=!0}else{let g=o.pathname.match(/\/w\/([a-zA-Z0-9-]+)/);g&&(a=g[1])}if(!a){let g=n.querySelector('img[src*="/thumbnails/"]');if(g){let v=g.src.match(/\/thumbnails\/([a-zA-Z0-9-]+)\.jpg/);v&&v[1]&&(a=v[1])}}if(a){let g=!!(n.closest("my-recommended-videos")||n.closest(".other-videos")),v=sessionStorage.getItem("premium_cache_videos_".concat(a))==="true"||sessionStorage.getItem("premium_cache_shortUUID_".concat(a))==="true";!v&&s&&!g&&(v=sessionStorage.getItem("premium_cache_playlist_".concat(a,"_pos_").concat(s))==="true");let L=()=>{let y=null,h="append",P="block";r.includes("/admin/overview/videos")||r.includes("/my-library/videos")?(y=n.querySelector('a.channel.ellipsis[href*="/c/"]'),y&&(h="after",P="block")):r.includes("/my-library/history/videos")?(y=n.querySelector('a.inherit-parent-style[href*="/c/"]'),y&&(h="after",P="block")):g?(y=n.querySelector(".video-info-owner")||n.querySelector(".video-info"),y&&(h="append",P="block")):r.includes("/w/p/")?(y=n.querySelector(".video-info-owner"),y&&(h="after",P="block")):(y=n.querySelector(".video-info")||n.querySelector(".video-miniature-info")||n.querySelector(".metadata"),y&&(h="append",P="block")),y&&br(y,h,P)&&n.classList.add("has-premium-badge")};if(!v&&d&&s&&!g){if(n.dataset.premiumFetchRequested)return;n.dataset.premiumFetchRequested="true",vr(a,s).then(y=>{y?L():n.dataset.premiumFetchRequested="failed"}).catch(()=>{n.dataset.premiumFetchRequested="failed"})}else if(!v&&!d){if(a.includes("playlist-")||sessionStorage.getItem("premium_cache_checked_videos_".concat(a))==="true"||sessionStorage.getItem("premium_cache_checked_shortUUID_".concat(a))==="true"||n.dataset.premiumFetchRequested)return;n.dataset.premiumFetchRequested="true",Me("".concat(q,"/api/v1/videos/").concat(a)).then(h=>!h||!h.ok?(n.dataset.premiumFetchRequested="failed",null):h.json()).then(h=>{h&&(O({data:[h]},"/api/v1/videos/".concat(a)),sessionStorage.getItem("premium_cache_videos_".concat(a))==="true"&&L()),n.dataset.premiumFetchRequested="failed"}).catch(()=>{n.dataset.premiumFetchRequested="failed"})}else v&&L()}}catch(o){}})}let wr=u.getAuthHeader,z=new K(wr),c=null,Q="",le=null,ce="",Re=null,Fe="",me=0,de=null,pe=null,Le=null,qe=0,R=0;function fe(){return"".concat(window.location.pathname).concat(window.location.search)}function Pr(){return R++,qe++,le&&(clearTimeout(le),le=null),R}function he(e,t,r){return!(e!==R||t!==fe()||typeof r=="number"&&r!==qe)}let Tr="premium_rumble_duration_",Sr="premium_rumble_use_player_",Er="premium_rumble_local_progress_";function ye(e){return"".concat(Sr).concat(e)}function Tt(e){return"".concat(Tr).concat(e)}function Oe(e){return"".concat(Er).concat(e)}function St(e){if(!e)return null;try{let t=localStorage.getItem(Oe(e));if(!t)return null;let r=JSON.parse(t),n=Math.max(0,Math.floor(Number(r.positionSeconds)||0)),i=Math.max(0,Math.floor(Number(r.durationSeconds)||0)),o=Math.max(0,Math.floor(Number(r.updatedAt)||0));return!i||i<=0||i-n<=2?null:{positionSeconds:n,durationSeconds:i,updatedAt:o}}catch(t){return null}}function Et(e,t,r){let n=Math.max(0,Math.floor(Number(t)||0)),i=Math.max(0,Math.floor(Number(r)||0));if(!i||i<=0||u.isLoggedIn()||i-n<=2)return;let o=JSON.stringify({positionSeconds:n,durationSeconds:i,updatedAt:Date.now()}),s=new Set;s.add(e.videoUuid);let a=ge();a&&s.add(a),s.forEach(d=>{try{localStorage.setItem(Oe(d),o)}catch(p){}}),e.lastSavedPosition=n}function Mt(e){let t=new Set;e.forEach(n=>{let i=String(n||"").trim();i&&t.add(i)});let r=ge();r&&t.add(r),t.forEach(n=>{try{localStorage.removeItem(Oe(n))}catch(i){}})}function Rt(e){e&&Mt([e.videoUuid,e.rumbleVideoId])}function w(){return window.location.pathname.startsWith("/w/")}function ze(){return document.visibilityState==="visible"&&!document.hidden}function We(e,t){return"premium_rumble_playlist_".concat(e,"_pos_").concat(t,"_video")}function Mr(e){try{let t=new URL(e,window.location.origin),r=t.pathname.match(/^\/w\/p\/([a-zA-Z0-9-]+)/),n=t.searchParams.get("playlistPosition")||"1";return r!=null&&r[1]?{playlistUuid:r[1],position:n}:null}catch(t){let r=e.match(/\/w\/p\/([a-zA-Z0-9-]+).*?[?&]playlistPosition=(\d+)/);return r!=null&&r[1]?{playlistUuid:r[1],position:r[2]||"1"}:null}}function ge(){let e=window.location.pathname.match(/^\/w\/(?!p\/)([a-zA-Z0-9-]+)/);return(e==null?void 0:e[1])||null}async function Rr(e,t){let r=Number(t);if(!e||!Number.isFinite(r)||r<=0)return null;let n="premium_rumble_playlist_video_".concat(e,"_pos_").concat(t),i=sessionStorage.getItem(n);if(i)return i;let o=Math.max(0,Math.floor(r)-1),s=await Me("".concat(q,"/api/v1/video-playlists/").concat(e,"/videos?start=").concat(o,"&count=1"));if(!s||!s.ok)return null;let a=await s.json();O(a,"/api/v1/video-playlists/".concat(e,"/videos?start=").concat(o,"&count=1"));let d=Array.isArray(a==null?void 0:a.data)?a.data[0]:null,p=(d==null?void 0:d.video)||d,g=(p==null?void 0:p.shortUUID)||(p==null?void 0:p.uuid)||null;return g&&(sessionStorage.setItem(n,g),p!=null&&p.uuid&&sessionStorage.setItem(J(g),p.uuid),p!=null&&p.shortUUID&&sessionStorage.setItem(Z(p.uuid),p.shortUUID)),g}async function Lt(){if(window.location.pathname.startsWith("/w/p/")){let e=window.location.pathname.match(/^\/w\/p\/([a-zA-Z0-9-]+)/),t=e==null?void 0:e[1],r=new URLSearchParams(window.location.search).get("playlistPosition")||"1";if(!t)return null;let n=await Rr(t,r);if(n)return n;let i=document.querySelector('#videojs-wrapper .vjs-peertube-link[href*="/w/"], .vjs-peertube-link[href*="/w/"]');if(i!=null&&i.href){let o=i.href.match(/\/w\/(?!p\/)([a-zA-Z0-9-]+)/);if(o!=null&&o[1])return o[1]}return null}return ge()}function je(){let e=["my-video-watch #videojs-wrapper","#videojs-wrapper","my-video-watch .player-wrapper","my-video-watch my-video-watch-player","my-video-watch .video-player","my-video-watch .player-container",".player-wrapper"];for(let r of e){let n=document.querySelector(r);if(n)return n}let t=document.querySelector("my-video-watch .video-js, my-video-watch video");return t?t.closest("#videojs-wrapper, .player-wrapper, my-video-watch-player, .video-player, .player-container, .player")||t.parentElement:null}function _t(e,t=!1){if(!e.closest(".premium-rumble-wrapper")){try{e.pause()}catch(r){}if(t){try{e.autoplay=!1}catch(r){}try{e.setAttribute("preload","none")}catch(r){}}}}function U(e,t=!0){(e||document).querySelectorAll("video").forEach(n=>{let i=n;i.closest(".premium-rumble-wrapper")||_t(i,t)})}function Lr(e){(e||je()||document).querySelectorAll("video").forEach(r=>{let n=r;if(!n.closest(".premium-rumble-wrapper")){try{n.muted=!1}catch(i){}try{n.volume===0&&(n.volume=1)}catch(i){}}})}function Ge(){let e=new URLSearchParams(window.location.search);return e.has("rumbleStart")||e.get("rumbleAutoplay")==="1"||e.has("startSeconds")}function It(){(document.querySelector("my-video-watch, #videojs-wrapper")||document).querySelectorAll("video").forEach(t=>{_t(t,!1)})}function be(){de||(It(),de=window.setInterval(()=>{if(c!=null&&c.api){k();return}if(!window.location.pathname.startsWith("/w/")){k();return}It()},250))}function k(){de&&(window.clearInterval(de),de=null)}function ve(e=!0){pe&&(pe.remove(),pe=null),e&&Le&&Nt(Le),Le=null}function _r(e){if(c||pe||sessionStorage.getItem(ye(e))!=="true")return;let t=je();if(!t)return;U(t,!1);let r=Ht();r.innerHTML='<div class="premium-rumble-loading-placeholder">\u0E01\u0E33\u0E25\u0E31\u0E07\u0E42\u0E2B\u0E25\u0E14\u0E40\u0E04\u0E23\u0E37\u0E48\u0E2D\u0E07\u0E40\u0E25\u0E48\u0E19</div>',t.insertBefore(r,t.firstChild),pe=r,Le=At(t,r)}function xt(){if(document.getElementById("premium-rumble-style"))return;let e=document.createElement("style");e.id="premium-rumble-style",e.textContent='\n .premium-rumble-wrapper {\n display: block !important;\n width: 100% !important;\n max-width: 100% !important;\n aspect-ratio: 16 / 9 !important;\n background: #000 !important;\n position: relative !important;\n overflow: hidden !important;\n margin: 0 !important;\n padding: 0 !important;\n line-height: 0 !important;\n }\n .premium-rumble-loading-placeholder {\n width: 100% !important;\n height: 100% !important;\n display: flex !important;\n align-items: center !important;\n justify-content: center !important;\n background: #000 !important;\n color: #aaa !important;\n font-size: 14px !important;\n line-height: 1.4 !important;\n box-sizing: border-box !important;\n }\n .premium-rumble-pending > *:not(.premium-rumble-wrapper) {\n display: none !important;\n }\n .premium-rumble-wrapper > div,\n .premium-rumble-wrapper [id^="vid_"],\n .premium-rumble-wrapper iframe,\n .premium-rumble-wrapper video,\n .premium-rumble-wrapper object,\n .premium-rumble-wrapper embed {\n width: 100% !important;\n height: 100% !important;\n max-width: 100% !important;\n max-height: 100% !important;\n margin: 0 !important;\n border: 0 !important;\n box-sizing: border-box !important;\n }\n /* \u2705 v9.3: \u0E41\u0E01\u0E49\u0E40\u0E09\u0E1E\u0E32\u0E30\u0E1B\u0E38\u0E48\u0E21 play \u0E43\u0E2B\u0E0D\u0E48\u0E01\u0E25\u0E32\u0E07\u0E08\u0E2D\u0E02\u0E2D\u0E07 Rumble \u0E44\u0E21\u0E48\u0E22\u0E38\u0E48\u0E07 control bar */\n .premium-rumble-wrapper .premium-rumble-big-play-fixed {\n position: absolute !important;\n left: 50% !important;\n top: 50% !important;\n transform: translate(-50%, -50%) !important;\n width: 96px !important;\n height: 96px !important;\n max-width: 96px !important;\n max-height: 96px !important;\n min-width: 96px !important;\n min-height: 96px !important;\n z-index: 100 !important;\n align-items: center !important;\n justify-content: center !important;\n padding: 0 !important;\n margin: 0 !important;\n overflow: visible !important;\n box-sizing: border-box !important;\n pointer-events: auto !important;\n }\n .premium-rumble-wrapper .premium-rumble-big-play-inner-fixed {\n width: 96px !important;\n height: 96px !important;\n max-width: 96px !important;\n max-height: 96px !important;\n min-width: 96px !important;\n min-height: 96px !important;\n padding: 24px !important;\n margin: 0 !important;\n border-radius: 50% !important;\n box-sizing: border-box !important;\n display: flex !important;\n align-items: center !important;\n justify-content: center !important;\n }\n .premium-rumble-wrapper .premium-rumble-big-play-inner-fixed svg,\n .premium-rumble-wrapper svg.premium-rumble-big-play-svg-fixed {\n width: 48px !important;\n height: 48px !important;\n max-width: 48px !important;\n max-height: 48px !important;\n display: block !important;\n }\n .premium-rumble-wrapper .premium-rumble-title-hidden,\n .premium-rumble-wrapper .premium-rumble-logo-hidden,\n .premium-rumble-wrapper .premium-rumble-autoplay-hidden {\n display: none !important;\n visibility: hidden !important;\n pointer-events: none !important;\n }\n .premium-rumble-peertube-hidden {\n display: none !important;\n }\n ',document.head.appendChild(e)}function Ir(e){xt();let t=Array.from(e.children).find(n=>{var o;return(o=n.id)==null?void 0:o.startsWith("premium_rumble_")}),r=e.querySelector('[id^="vid_"]');[e,t,r].forEach(n=>{n&&(n.style.width="100%",n.style.height="100%",n.style.maxWidth="100%",n.style.maxHeight="100%",n.style.boxSizing="border-box")}),e.querySelectorAll("iframe, object, embed").forEach(n=>{let i=n;i.style.width="100%",i.style.height="100%",i.style.maxWidth="100%",i.style.maxHeight="100%",i.style.boxSizing="border-box"})}function xr(e){let t=e.querySelector('[id^="vid_"]')||e,r=t.querySelector(".bigPlayUI.ctp");if(r){r.classList.add("premium-rumble-big-play-fixed"),window.getComputedStyle(r).display!=="none"&&(r.style.display="flex");let o=r.querySelector(".bigPlayUIInner.ctp");o&&o.classList.add("premium-rumble-big-play-inner-fixed");let s=r.querySelector("svg.RumbleSVG-bplay, svg");s&&s.classList.add("premium-rumble-big-play-svg-fixed")}let n=t.querySelector(".touched_overlay_item");if(n){let i=n.querySelector(".play_pause_wrap");i&&(i.style.width="96px",i.style.height="96px",i.style.maxWidth="96px",i.style.maxHeight="96px",i.style.margin="0 18px",i.style.padding="0"),n.querySelectorAll(".play_svg, .pause_svg").forEach(o=>{let s=o;s.style.width="96px",s.style.height="96px",s.style.maxWidth="96px",s.style.maxHeight="96px",s.style.padding="24px",s.style.boxSizing="border-box"})}}function Ar(e){var r,n,i;let t=Array.from(e.querySelectorAll('a[href*="rumble.com/v"], a[href^="//rumble.com/v"]'));for(let o of t){let s=window.getComputedStyle(o);(o.textContent||"").trim().length>0&&s.position==="absolute"&&(s.top==="0px"||((r=o.getAttribute("style"))==null?void 0:r.includes("top: 0px")))&&(s.left==="0px"||((n=o.getAttribute("style"))==null?void 0:n.includes("left: 0px")))&&(s.right==="0px"||((i=o.getAttribute("style"))==null?void 0:i.includes("right: 0px")))&&o.classList.add("premium-rumble-title-hidden")}}function Nr(e){let t=Array.from(e.querySelectorAll('svg.RumbleElm[viewBox="0 0 140 35"], svg.RumbleElm[viewBox="0 0 35 35"]'));for(let r of t){let n=r.outerHTML||"";if(!(n.includes('fill="#85C742"')||n.includes("fill='#85C742'")))continue;(r.closest('div[style*="float: right"], div[title*="Rumble"], a, div')||r).classList.add("premium-rumble-logo-hidden")}}function Ur(e){return e.querySelector('div[title="Autoplay"], [title="Autoplay"]')}function kr(e){if(!e)return;let t=["setAutoplay","setAutoPlay","setAutoplayNext","setAutoPlayNext"];for(let r of t){let n=e[r];if(typeof n=="function")try{let i=n.call(e,!1);i!=null&&i.catch&&i.catch(()=>{})}catch(i){}}}function Hr(e){if(e.dataset.rumbleAutoplayUserGuardAttached==="true")return;e.dataset.rumbleAutoplayUserGuardAttached="true";let t=()=>{let r=Ur(e);if(!r||r.dataset.premiumAutoplayGuardAttached==="true")return;r.dataset.premiumAutoplayGuardAttached="true";let n=()=>{e.dataset.rumbleAutoplayUserTouched="true"};r.addEventListener("pointerdown",n,{passive:!0}),r.addEventListener("mousedown",n,{passive:!0}),r.addEventListener("touchstart",n,{passive:!0}),r.addEventListener("click",n,{passive:!0})};t(),window.setTimeout(t,500),window.setTimeout(t,1500),window.setTimeout(t,3e3)}function Cr(e,t){if(e.dataset.rumbleAutoplayArmed==="true")return;e.dataset.rumbleAutoplayArmed="true",Hr(e);let r=0,n=window.setInterval(()=>{if(r++,!c||c!==t||t.wrapper!==e){window.clearInterval(n);return}if(e.dataset.rumbleAutoplayUserTouched==="true"){window.clearInterval(n);return}kr(t.api),r>=6&&window.clearInterval(n)},700)}function Ke(e){Ir(e),xr(e),Ar(e),Nr(e)}function At(e,t){let r=[];return e.classList.add("premium-rumble-pending"),Array.from(e.children).forEach(n=>{let i=n;i!==t&&(i.classList.contains("premium-rumble-wrapper")||(i.classList.add("premium-rumble-peertube-hidden"),r.push(i)))}),r}function Nt(e){(e||[]).forEach(t=>{var r;t.classList.remove("premium-rumble-peertube-hidden"),(r=t.parentElement)==null||r.classList.remove("premium-rumble-pending")}),document.querySelectorAll(".premium-rumble-pending").forEach(t=>{t.classList.remove("premium-rumble-pending")})}function Ut(e){if(!e||e<=0)return;let t=Dr(e);document.querySelectorAll(".attribute-duration .attribute-value, .attribute.attribute-duration .attribute-value").forEach(r=>{let n=r,i=(c==null?void 0:c.videoUuid)||window.location.href;Fe!==i&&(Re=n.textContent||"",Fe=i),n.textContent=t,n.dataset.rumbleDuration="true"})}function $r(){document.querySelectorAll('.attribute-duration .attribute-value[data-rumble-duration="true"], .attribute.attribute-duration .attribute-value[data-rumble-duration="true"]').forEach(e=>{let t=e;Re!==null&&(t.textContent=Re),delete t.dataset.rumbleDuration}),Re=null,Fe=""}function Dr(e){e=Math.max(0,Math.floor(Number(e)||0));let t=Math.floor(e/3600),r=Math.floor(e%3600/60),n=e%60;return t>0?"".concat(t," \u0E0A\u0E21. ").concat(r," \u0E19\u0E32\u0E17\u0E35 ").concat(n,"sec"):r>0?"".concat(r," \u0E19\u0E32\u0E17\u0E35 ").concat(n,"sec"):"".concat(n,"sec")}function _e(){return/Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent)}function Br(){try{let e=new URL(window.location.href),t=Number(e.searchParams.get("playlistPosition"));return Number.isFinite(t)&&t>0?t:null}catch(e){return null}}function Vr(){return window.location.pathname.includes("/w/p/")}function kt(e){return e?(e.click(),!0):!1}function Fr(){let e=Br();if(!e)return null;let t=e+1,r=Array.from(document.querySelectorAll('a[href*="/w/p/"][href*="playlistPosition="]'));for(let n of r)try{let i=new URL(n.href,window.location.origin);if(Number(i.searchParams.get("playlistPosition"))===t)return n}catch(i){}return null}function qr(){let e=document.querySelector('my-input-switch input[name="autoplay-next-video"], input#autoplay-next-video, input[name="autoplay-next-video"]');if(e)return e.checked===!0;let t=document.querySelector('my-input-switch[inputname="autoplay-next-video"], [role="switch"][name="autoplay-next-video"], [aria-label*="\u0E40\u0E25\u0E48\u0E19\u0E27\u0E34\u0E14\u0E35\u0E42\u0E2D\u0E16\u0E31\u0E14\u0E44\u0E1B"], [aria-label*="autoplay"]');if(!t)return!1;let r=t.getAttribute("aria-checked");return r==="true"?!0:r==="false"?!1:t.classList.contains("active")||t.classList.contains("checked")||t.classList.contains("enabled")}function Or(){let e=["my-recommended-videos",".other-videos",".recommendations","aside"];for(let t of e){let r=document.querySelector(t);if(!r)continue;let n=Array.from(r.querySelectorAll('a[href*="/w/"]:not([href*="/w/p/"])'));for(let i of n)try{let o=new URL(i.href,window.location.origin);if(!o.pathname.includes("/w/")||o.pathname===window.location.pathname)continue;return i}catch(o){}}return null}async function zr(e){if(!(e.nextTriggered||!e.api))try{if(!!await Promise.resolve(e.api.getPaused()))return;let r=Number(await Promise.resolve(e.api.getCurrentTime()))||0,n=Number(await Promise.resolve(e.api.getDuration()))||0;if(!n||n<=0)return;let i=n-r;if(r<=10||i>2)return;e.nextTriggered=!0;try{e.api.pause&&await Promise.resolve(e.api.pause())}catch(s){}try{await Promise.resolve(e.api.setCurrentTime(0))}catch(s){}try{e.api.pause&&await Promise.resolve(e.api.pause())}catch(s){}if(U(e.oldPlayer,!0),await Gr(e,Math.floor(n)),e.canSaveProgress=!1,Vr()){let s=Fr();s&&kt(s);return}if(!qr())return;let o=Or();o&&kt(o)}catch(t){console.warn("\u26A0\uFE0F [Premium Rumble] auto-next failed:",t)}}function Wr(e){e.autoNextTimer&&window.clearInterval(e.autoNextTimer),e.autoNextTimer=window.setInterval(()=>{zr(e).catch(()=>{})},500)}function jr(e){e.peerTubeStopTimer&&window.clearInterval(e.peerTubeStopTimer);let t=0;e.peerTubeStopTimer=window.setInterval(()=>{if(t++,!c||c!==e||t>45){e.peerTubeStopTimer&&window.clearInterval(e.peerTubeStopTimer),e.peerTubeStopTimer=void 0;return}U(e.oldPlayer,!0)},700)}async function Gr(e,t){if(!e.canSaveProgress)return;let r=Math.max(0,Math.floor(Number(t)||0));if(!(!r||r<=0))try{await z.saveRumbleProgress({videoUuid:e.videoUuid,rumbleVideoId:e.rumbleVideoId,positionSeconds:0,durationSeconds:r,paused:!0,completed:!1}),e.lastSavedPosition=0}catch(n){console.warn("\u26A0\uFE0F [Premium Rumble] reset progress to start failed:",n)}}function Kr(e){window.Rumble||function(t,r,n,i,o,s){t._Rumble=i,t[i]||(t[i]=function(){var a;(t[i]._=t[i]._||[]).push(arguments),t[i]._.length===1&&(o=r.createElement(n),s=r.getElementsByTagName(n)[0],o.async=!0,o.src="https://rumble.com/embedJS/u"+e+(arguments[1].video?"."+arguments[1].video:"")+"/?url="+encodeURIComponent(location.href)+"&args="+encodeURIComponent(JSON.stringify([].slice.apply(arguments))),(a=s.parentNode)==null||a.insertBefore(o,s))})}(window,document,"script","Rumble")}function Ht(){xt();let e=document.createElement("div");return e.className="premium-rumble-wrapper",e}async function Ze(e){if(!e.api)return null;try{let t=Math.floor(Number(await Promise.resolve(e.api.getCurrentTime()))||0),r=Math.round(Number(await Promise.resolve(e.api.getDuration()))||0),n=!!await Promise.resolve(e.api.getPaused());return!r||r<=0||t<0?null:{positionSeconds:t,durationSeconds:r,paused:n}}catch(t){return console.warn("\u26A0\uFE0F [Premium Rumble] \u0E2D\u0E48\u0E32\u0E19\u0E40\u0E27\u0E25\u0E32 Rumble \u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08:",t),null}}async function I(e=!1){let t=c;if(!(t!=null&&t.api))return;let r=await Ze(t);if(!r||r.positionSeconds<=2&&t.lastSavedPosition>30||t.nextTriggered&&r.positionSeconds<=5)return;let n=Math.abs(r.positionSeconds-t.lastSavedPosition);if(!(!e&&n<10&&!r.paused)){if(t.canSaveProgress){try{let i=await z.saveRumbleProgress({videoUuid:t.videoUuid,rumbleVideoId:t.rumbleVideoId,positionSeconds:r.positionSeconds,durationSeconds:r.durationSeconds,paused:r.paused});i&&i.success!==!0&&(i.error||i.status===401||i.status===403)?(t.canSaveProgress=!1,console.warn("\u26A0\uFE0F [Premium Rumble] \u0E1B\u0E34\u0E14\u0E01\u0E32\u0E23\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01 progress \u0E0A\u0E31\u0E48\u0E27\u0E04\u0E23\u0E32\u0E27 \u0E40\u0E1E\u0E23\u0E32\u0E30 backend \u0E44\u0E21\u0E48\u0E2D\u0E19\u0E38\u0E0D\u0E32\u0E15:",i)):(t.lastSavedPosition=r.positionSeconds,Rt(t))}catch(i){t.canSaveProgress=!1,console.warn("\u26A0\uFE0F [Premium Rumble] \u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01 progress \u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08 \u0E1B\u0E34\u0E14\u0E01\u0E32\u0E23\u0E22\u0E34\u0E07\u0E0B\u0E49\u0E33\u0E0A\u0E31\u0E48\u0E27\u0E04\u0E23\u0E32\u0E27:",i)}return}u.isLoggedIn()||Et(t,r.positionSeconds,r.durationSeconds)}}async function Zr(e){if(!e.api)return;let t=await Ze(e);if(!(!t||t.durationSeconds-t.positionSeconds<=2)){if(e.canSaveProgress){try{let n=await z.saveRumbleProgress({videoUuid:e.videoUuid,rumbleVideoId:e.rumbleVideoId,positionSeconds:t.positionSeconds,durationSeconds:t.durationSeconds,paused:!0,completed:!1});n&&n.success!==!0&&(n.error||n.status===401||n.status===403)?e.canSaveProgress=!1:(e.lastSavedPosition=t.positionSeconds,Rt(e))}catch(n){e.canSaveProgress=!1,console.warn("\u26A0\uFE0F [Premium Rumble] \u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01 progress \u0E01\u0E48\u0E2D\u0E19\u0E1B\u0E34\u0E14\u0E1E\u0E37\u0E49\u0E19\u0E2B\u0E25\u0E31\u0E07\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08:",n)}return}u.isLoggedIn()||Et(e,t.positionSeconds,t.durationSeconds)}}async function Jr(e){let t=await Ze(e);if(!(!t||!t.durationSeconds)){Ut(t.durationSeconds);try{await z.saveRumbleDuration({videoUuid:e.videoUuid,rumbleVideoId:e.rumbleVideoId,durationSeconds:t.durationSeconds})}catch(r){}}}async function Xr(e,t,r){let n=Math.max(0,Math.floor(Number(t)||0));for(let i=0;i<12;i++){try{let o=Number(await Promise.resolve(e.getDuration()))||0;n>0&&await Promise.resolve(e.setCurrentTime(n));let s=Number(await Promise.resolve(e.getCurrentTime()))||0;if(n<=0||Math.abs(s-n)<=3||o>0&&i>=3){r&&e.play&&setTimeout(()=>{var d;return Promise.resolve((d=e.play)==null?void 0:d.call(e)).catch(()=>{})},250);return}}catch(o){}await new Promise(o=>setTimeout(o,450))}r&&e.play&&Promise.resolve(e.play()).catch(()=>{})}function Qr(e){e.timer&&window.clearInterval(e.timer),e.timer=window.setInterval(()=>{I(!1)},2e4),Wr(e)}function Ct(e,t){var n,i,o;try{(n=t==null?void 0:t.pause)==null||n.call(t)}catch(s){}try{(i=t==null?void 0:t.mute)==null||i.call(t)}catch(s){}try{(o=t==null?void 0:t.setVolume)==null||o.call(t,0)}catch(s){}let r=[];e&&r.push(e),document.querySelectorAll(".premium-rumble-wrapper").forEach(s=>{r.includes(s)||r.push(s)}),r.forEach(s=>{s.querySelectorAll("video, audio").forEach(a=>{let d=a;try{d.pause()}catch(p){}try{d.removeAttribute("src")}catch(p){}try{d.load()}catch(p){}}),s.querySelectorAll("iframe, object, embed").forEach(a=>{let d=a;try{d.src="about:blank"}catch(p){}try{d.setAttribute("src","about:blank")}catch(p){}try{d.setAttribute("srcdoc","<!doctype html><html><body></body></html>")}catch(p){}try{d.remove()}catch(p){}});try{s.innerHTML=""}catch(a){}})}function we(){Q="",ce="",me=0}let Ie=!1,W=null;function Yr(e){[0,120,350,900,1800].forEach(t=>{window.setTimeout(()=>{var r,n,i;try{(r=e==null?void 0:e.pause)==null||r.call(e)}catch(o){}try{(n=e==null?void 0:e.mute)==null||n.call(e)}catch(o){}try{(i=e==null?void 0:e.setVolume)==null||i.call(e,0)}catch(o){}},t)})}function Je(){U(void 0,!0)}function $t(e){if(!w()||c!=null&&c.api)return;W&&(window.clearTimeout(W),W=null);let t=R;we(),be(),Je(),W=window.setTimeout(()=>{t===R&&w()&&(c!=null&&c.api||(we(),ee(50,t)))},80),window.setTimeout(()=>{t===R&&w()&&(c!=null&&c.api||(we(),ee(50,t)))},1300),window.setTimeout(()=>{c!=null&&c.api||k(),W&&(window.clearTimeout(W),W=null)},4200)}function en(){let e=c;if(e!=null&&e.isMember)return;let t=navigator.mediaSession;if(t!=null&&t.setActionHandler){try{t.setActionHandler("play",()=>{var n,i;let r=c;if(!(r!=null&&r.isMember)){if(ze()&&w()){try{(i=(n=r==null?void 0:r.api)==null?void 0:n.play)==null||i.call(n)}catch(o){}return}_e()&&(r!=null&&r.api&&(!w()||document.hidden)?$e().catch(()=>{}):Ie&&w()&&ze()&&(Je(),$t("media-session-play")))}})}catch(r){}try{t.setActionHandler("pause",()=>{var n,i;let r=c;if(!(r!=null&&r.isMember)){try{(i=(n=r==null?void 0:r.api)==null?void 0:n.pause)==null||i.call(n)}catch(o){}I(!0).catch(()=>{})}})}catch(r){}try{t.setActionHandler("seekto",r=>{var o,s;let n=c;if(!(n!=null&&n.api)||n.isMember)return;if(_e()&&(!w()||document.hidden)){try{(s=(o=n.api).pause)==null||s.call(o)}catch(a){}return}let i=Number(r==null?void 0:r.seekTime);Number.isFinite(i)&&Promise.resolve(n.api.setCurrentTime(i)).catch(()=>{})})}catch(r){}}}async function Y(e=!0){k(),ve(!0),c&&(e&&!c.nextTriggered&&await I(!0),c.timer&&window.clearInterval(c.timer),c.autoNextTimer&&window.clearInterval(c.autoNextTimer),c.peerTubeStopTimer&&window.clearInterval(c.peerTubeStopTimer),Ct(c.wrapper,c.api),c.wrapper&&c.wrapper.remove(),Nt(c.hiddenPeerTubeChildren),$r(),c.oldPlayer&&(c.oldPlayer.style.display=""),Lr(c.oldPlayer),c=null,we())}async function tn(e=R){let t=++qe,r=fe(),n=window.location.pathname,i=()=>!he(e,r,t);if(!n.startsWith("/w/")){k(),await Y();return}let o=await Lt();if(i())return;if(!o){Ge()&&be(),n.startsWith("/w/")&&me<12&&(me++,ee(500,e));return}if(me=0,i())return;let s="".concat(window.location.href,"::").concat(o);if(Q===s||ce===s)return;ce=s,_r(o);let a;try{a=await z.getRumblePlaybackInfo(o)}catch(y){console.warn("\u26A0\uFE0F [Premium Rumble] \u0E42\u0E2B\u0E25\u0E14 playback-info \u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08:",y);return}if(i()||!(a!=null&&a.success))return;if(a.mode==="peertube"){sessionStorage.removeItem(ye(o)),ve(!0),k(),await Y(),Q=s;return}if(a.mode==="replacement"||a.mode==="locked"){sessionStorage.removeItem(ye(o)),ve(!0),k(),await Y(),Q=s;return}if(a.mode!=="rumble"||!a.rumbleVideoId){ve(!0);return}sessionStorage.setItem(ye(o),"true");let d=je();if(!d){Q="",ce="";return}if(await Y(!1),i())return;ve(!1),Q=s,be(),U(d,!0);let p=Ht(),g="premium_rumble_".concat(a.rumbleVideoId,"_").concat(Date.now());p.innerHTML='\n <div class="premium-rumble-loading-placeholder">\u0E01\u0E33\u0E25\u0E31\u0E07\u0E42\u0E2B\u0E25\u0E14\u0E40\u0E04\u0E23\u0E37\u0E48\u0E2D\u0E07\u0E40\u0E25\u0E48\u0E19</div>\n <div id="'.concat(g,'" style="width:100%;height:100%;max-width:100%;display:none;"></div>\n '),d.insertBefore(p,d.firstChild);let v=At(d,p);c={videoUuid:a.videoUuid||o,rumbleVideoId:a.rumbleVideoId,isMember:a.isMember===!0,canSaveProgress:u.isLoggedIn(),oldPlayer:d,hiddenPeerTubeChildren:v,wrapper:p,lastSavedPosition:(()=>{let y=new URLSearchParams(window.location.search),h=Number(y.get("rumbleStart")||y.get("startSeconds")||NaN);return Number.isFinite(h)&&h>0?Math.floor(h):Number(a.startSeconds||0)})(),nextTriggered:!1},c&&jr(c),Ut(Number(a.durationSeconds||0));let L=a.pubId||"4pc838";Kr(L),!(i()||!c||c.wrapper!==p)&&window.Rumble("play",{video:a.rumbleVideoId,div:g,autoplay:!1,api:async function(y){if(i()||!c||c.wrapper!==p||c.rumbleVideoId!==a.rumbleVideoId)return;let h=c;h.api=y,h.isMember||en(),Ie=!1,U(h.oldPlayer,!0),Cr(p,h);let P=new URLSearchParams(window.location.search),x=Number(P.get("rumbleStart")||P.get("startSeconds")||NaN),j=P.get("rumbleAutoplay")==="1";u.isLoggedIn()&&Mt([a.videoUuid||o,o,a.rumbleVideoId]);let A=u.isLoggedIn()?null:St(a.videoUuid||o)||St(o),G=Math.floor(Number.isFinite(x)&&x>0?x:Number(a.startSeconds||(A==null?void 0:A.positionSeconds)||0));setTimeout(()=>{!he(e,r,t)||c!==h||Xr(y,G,j).catch(_=>{console.warn("\u26A0\uFE0F [Premium Rumble] seek/resume \u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08:",_)})},400);try{y.setVolume&&await Promise.resolve(y.setVolume(1))}catch(_){}try{y.unmute&&await Promise.resolve(y.unmute())}catch(_){}let Se=p.querySelector(".premium-rumble-loading-placeholder"),oe=p.querySelector("#".concat(g));Se&&Se.remove(),oe&&(oe.style.display="block"),p.dataset.rumbleLoading="false",k(),!(i()||c!==h)&&(Ke(p),setTimeout(()=>{!he(e,r,t)||c!==h||(Ke(p),U(h.oldPlayer,!0))},800),setTimeout(()=>{!he(e,r,t)||c!==h||(Ke(p),U(h.oldPlayer,!0))},2e3),Qr(h),setTimeout(()=>{!he(e,r,t)||c!==h||(Jr(h),I(!0))},2500))}})}function ee(e=250,t=R){t===R&&(clearTimeout(le),le=setTimeout(()=>{t===R&&tn(t).catch(r=>{console.warn("\u26A0\uFE0F [Premium Rumble] mount error:",r)})},e))}let xe=null,Pe=null,Xe=!1,te=!1,re="",Dt=!1,Qe="",ne=null,Ye=null,Bt=null,Vt=0,et=!1,Ft=new WeakSet,Ae=new Map,rn="premium_native_peertube_resume_v13_",tt="premium_native_peertube_resume_pending_v13",rt=7*24*60*60*1e3,nn=5e3;function qt(e){var i,o,s,a,d,p,g,v,L,y,h,P,x,j,A,G;let t=Number((a=(s=(i=e==null?void 0:e.id)!=null?i:e==null?void 0:e.userId)!=null?s:(o=e==null?void 0:e.User)==null?void 0:o.id)!=null?a:0),r=String((h=(y=(v=(p=e==null?void 0:e.username)!=null?p:(d=e==null?void 0:e.User)==null?void 0:d.username)!=null?v:(g=e==null?void 0:e.Account)==null?void 0:g.name)!=null?y:(L=e==null?void 0:e.account)==null?void 0:L.name)!=null?h:"").toLowerCase(),n=String((G=(A=(j=(P=e==null?void 0:e.Role)==null?void 0:P.name)!=null?j:(x=e==null?void 0:e.role)==null?void 0:x.name)!=null?A:e==null?void 0:e.role)!=null?G:"").toLowerCase();return t===1||r==="root"||n==="root"}function H(){var e;if(!u.isLoggedIn())return!1;try{let t=(e=u.getUser)==null?void 0:e.call(u);if(!t)return xe;if(t.isPremium===!0||qt(t))return!0;if(t.isPremium===!1)return!1}catch(t){}return xe}async function nt(){let e=H();return e!==null?e:Pe||(Pe=(async()=>{if(!u.isLoggedIn())return xe=!1,!1;try{let t=await z.getMe(),r=(t==null?void 0:t.isPremium)===!0||qt(t);return xe=r,r}catch(t){return!0}finally{Pe=null}})(),Pe)}window.setTimeout(()=>{nt().catch(()=>{})},1200);function Te(){try{let e=ge();if(e)return"/w/".concat(e);if(window.location.pathname.startsWith("/w/p/")){let t=window.location.pathname.match(/^\/w\/p\/([a-zA-Z0-9-]+)/),r=t==null?void 0:t[1],n=new URLSearchParams(window.location.search).get("playlistPosition")||"1";if(r)return"/w/p/".concat(r,"?playlistPosition=").concat(n)}}catch(e){}return fe()}function it(e){return"".concat(rn).concat(encodeURIComponent(e))}function Ot(e,t,r=!0){try{let n=String((e==null?void 0:e.routeSignature)||""),i=Te(),o=Math.max(0,Math.floor(Number((e==null?void 0:e.positionSeconds)||0))),s=Math.max(0,Math.floor(Number((e==null?void 0:e.durationSeconds)||0))),a=Math.max(0,Math.floor(Number((e==null?void 0:e.updatedAt)||0)));return!n||r&&n!==i||!o||o<2||!a||Date.now()-a>t?null:{routeSignature:n,videoUuid:e!=null&&e.videoUuid?String(e.videoUuid):void 0,positionSeconds:o,durationSeconds:s,updatedAt:a,wasPaused:!!(e!=null&&e.wasPaused),muted:!!(e!=null&&e.muted),defaultMuted:!!(e!=null&&e.defaultMuted),volume:Number.isFinite(e==null?void 0:e.volume)?Number(e.volume):1,playbackRate:Number.isFinite(e==null?void 0:e.playbackRate)?Number(e.playbackRate):1}}catch(n){return null}}function zt(e){try{let t=localStorage.getItem(e);if(t)return JSON.parse(t)}catch(t){}return null}function Wt(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(r){}}function jt(e){try{localStorage.removeItem(e)}catch(t){}try{sessionStorage.removeItem(e)}catch(t){}}function Gt(e=Te()){jt(it(e)),Ae.delete(e)}function ie(){jt(tt),Qe="",ne&&(window.clearTimeout(ne),ne=null),Ye&&(window.clearInterval(Ye),Ye=null)}function Kt(e,t){let r=zt(it(e));return r?Ot(r,t,!1):null}function on(e=!0){let t=zt(tt),r=t?Ot(t,rt,!0):null;return!r&&e&&ie(),r}function Zt(e,t,r,n,i,o,s,a,d){let p=Math.max(0,Math.floor(Number(r||0)));return!p||p<2?null:{routeSignature:e,videoUuid:t||void 0,positionSeconds:p,durationSeconds:Math.max(0,Math.floor(Number(n||0))),updatedAt:Date.now(),wasPaused:!!i,muted:!!o,defaultMuted:!!s,volume:Number.isFinite(a)?a:1,playbackRate:Number.isFinite(d)?d:1}}function an(e,t){Ae.set(e.routeSignature,e),Wt(it(e.routeSignature),e),t&&Wt(tt,e)}function ot(){let e=ge();if(e)return e;try{if(window.location.pathname.startsWith("/w/p/")){let t=window.location.pathname.match(/^\/w\/p\/([a-zA-Z0-9-]+)/),r=t==null?void 0:t[1],n=new URLSearchParams(window.location.search).get("playlistPosition")||"1";if(r){let i=sessionStorage.getItem(We(r,n));if(i)return i}}}catch(t){}try{let t=document.querySelector('#videojs-wrapper .vjs-peertube-link[href*="/w/"], .vjs-peertube-link[href*="/w/"]'),n=((t==null?void 0:t.href)||"").match(/\/w\/(?!p\/)([a-zA-Z0-9-]+)/);if(n!=null&&n[1])return n[1]}catch(t){}}async function sn(e){if(e!=null&&e.videoUuid)return e.videoUuid;let t=ot();if(t)return t;try{return await Lt()||void 0}catch(r){return}}function Ne(){return Array.from(document.querySelectorAll("my-video-watch video, my-video-watch audio, #videojs-wrapper video, #videojs-wrapper audio")).filter(t=>!(!t||t.closest(".premium-rumble-wrapper")))}function C(e){try{let t=e.closest(".video-js"),r=t==null?void 0:t.id,n=window.videojs;return!r||typeof n!="function"?null:n(r)}catch(t){return null}}function $(e){let t=C(e);try{let r=t&&typeof t.tech=="function"?t.tech(!0):null,n=r&&typeof r.el=="function"?r.el():null;if(n&&(n instanceof HTMLVideoElement||n instanceof HTMLAudioElement))return n}catch(r){}return null}function at(e){let t=[],r=C(e),n=$(e);try{if(r&&typeof r.currentTime=="function"){let i=Number(r.currentTime());Number.isFinite(i)&&t.push(i)}}catch(i){}try{let i=Number(e.currentTime);Number.isFinite(i)&&t.push(i)}catch(i){}try{let i=Number(n==null?void 0:n.currentTime);Number.isFinite(i)&&t.push(i)}catch(i){}return Math.max(0,Math.floor(Math.max(0,...t)))}function Jt(e){let t=[],r=C(e),n=$(e);try{if(r&&typeof r.duration=="function"){let i=Number(r.duration());Number.isFinite(i)&&i>0&&t.push(i)}}catch(i){}try{let i=Number(e.duration);Number.isFinite(i)&&i>0&&t.push(i)}catch(i){}try{let i=Number(n==null?void 0:n.duration);Number.isFinite(i)&&i>0&&t.push(i)}catch(i){}return Math.max(0,Math.floor(Math.max(0,...t)))}function un(e){let t=C(e),r=$(e);try{if(t&&typeof t.paused=="function")return!!t.paused()}catch(n){}try{if(r)return!!r.paused}catch(n){}return!!e.paused}function st(e){let r=$(e)||e;return{media:e,currentTime:at(e),duration:Jt(e),paused:un(e),muted:!!r.muted,defaultMuted:!!r.defaultMuted,volume:Number.isFinite(r.volume)?r.volume:1,playbackRate:Number.isFinite(r.playbackRate)?r.playbackRate:1}}function Xt(e,t,r,n=!1){var g,v;let i=Kt(t,rt),o=Ae.get(t)||null,s=Math.max(0,Math.floor(Number(e.currentTime||0))),a=s>=2?s:Math.max(0,Math.floor(Number((v=(g=o==null?void 0:o.positionSeconds)!=null?g:i==null?void 0:i.positionSeconds)!=null?v:0))),d=ot()||(o==null?void 0:o.videoUuid)||(i==null?void 0:i.videoUuid),p=Zt(t,d,a,e.duration||(o==null?void 0:o.durationSeconds)||(i==null?void 0:i.durationSeconds)||0,e.paused,e.muted,e.defaultMuted,e.volume,e.playbackRate);return p?(an(p,r),Qt(p,n,!1).catch(()=>{}),p):null}function Ue(e,t=!1){let r=Te(),n=st(e);return Xt(n,r,!1,t)}async function Qt(e,t=!1,r=!1){if(!u.isLoggedIn()||!r&&(!(e!=null&&e.positionSeconds)||e.positionSeconds<2))return;let n=H();if(n===!0||n===null&&await nt())return;if(!t){let o=Date.now();if(et||o-Vt<nn)return}let i=await sn(e);if(i){et=!0,Vt=Date.now();try{await z.saveNativePeerTubeProgress({videoUuid:i,positionSeconds:r?0:e.positionSeconds,durationSeconds:e.durationSeconds||0,paused:r?!0:e.wasPaused,completed:r,routeSignature:r?"":e.routeSignature})}catch(o){console.warn("\u26A0\uFE0F [Premium Native] save native progress failed:",o)}finally{et=!1}}}function ut(e){try{if(e.ended)return!0}catch(n){}let t=Jt(e),r=at(e);return t>0&&r>0&&t-r<=1.5}function ke(e){if(!w()||c!=null&&c.api||H()===!0)return;let t=Te(),r=Ae.get(t)||Kt(t,rt),n=st(e),i=Zt(t,ot()||(r==null?void 0:r.videoUuid),(r==null?void 0:r.positionSeconds)||n.currentTime||2,n.duration||(r==null?void 0:r.durationSeconds)||0,!0,n.muted,n.defaultMuted,n.volume,n.playbackRate);ie(),Gt(t),i&&Qt(i,!0,!0).catch(()=>{})}function ln(e){let t=C(e),r=$(e);try{t&&typeof t.pause=="function"&&t.pause()}catch(n){}try{e.pause()}catch(n){}try{r==null||r.pause()}catch(n){}try{e.autoplay=!1}catch(n){}try{t&&typeof t.autoplay=="function"&&t.autoplay(!1)}catch(n){}}function cn(e,t){let r=C(e),n=$(e),i=Math.max(0,Math.floor(Number(t||0)));if(!(!i||i<2)){try{if(r&&typeof r.currentTime=="function"){r.currentTime(i);return}}catch(o){}try{e.currentTime=i}catch(o){}try{n&&n!==e&&(n.currentTime=i)}catch(o){}}}function mn(e,t){let r=C(e),n=$(e),i=!!t.muted,o=Number.isFinite(t.volume)?t.volume:1,s=Math.max(.01,Math.min(1,o||1));if([e,n].forEach(a=>{if(a){if(!i){try{a.defaultMuted=!1}catch(d){}try{a.muted=!1}catch(d){}try{a.volume=s}catch(d){}}try{a.playbackRate=t.playbackRate||1}catch(d){}}}),r){if(!i){try{typeof r.muted=="function"&&r.muted(!1)}catch(a){}try{typeof r.volume=="function"&&r.volume(s)}catch(a){}}try{typeof r.playbackRate=="function"&&r.playbackRate(t.playbackRate||1)}catch(a){}}}function dn(e){if(Ft.has(e))return;Ft.add(e);let t=()=>{if(w()&&!(c!=null&&c.api)&&H()!==!0){if(ut(e)){ke(e);return}Ue(e,!1)}},r=()=>{if(w()&&!(c!=null&&c.api)&&H()!==!0){if(ut(e)){ke(e);return}Ue(e,!0)}},n=()=>{ke(e)};try{e.addEventListener("timeupdate",t,{passive:!0})}catch(i){}try{e.addEventListener("pause",r,{passive:!0})}catch(i){}try{e.addEventListener("seeking",t,{passive:!0})}catch(i){}try{e.addEventListener("seeked",r,{passive:!0})}catch(i){}try{e.addEventListener("playing",r,{passive:!0})}catch(i){}try{e.addEventListener("ratechange",t,{passive:!0})}catch(i){}try{e.addEventListener("ended",n,{passive:!0})}catch(i){}}function pn(){Bt||(Bt=window.setInterval(()=>{w()&&(c!=null&&c.api||H()!==!0&&Ne().forEach(e=>{dn(e),Ue(e,!1)}))},750))}function fn(e,t){if(!t||!document.documentElement.contains(t))return;let r=!1,n=null,i=()=>{try{t.removeEventListener("loadedmetadata",o)}catch(s){}try{t.removeEventListener("loadeddata",o)}catch(s){}try{t.removeEventListener("canplay",o)}catch(s){}n&&(window.clearTimeout(n),n=null)},o=()=>{if(r)return;if(r=!0,i(),!document.documentElement.contains(t)){ie();return}let s=at(t);Math.abs(s-e.positionSeconds)>1.2&&cn(t,e.positionSeconds),mn(t,e),e.wasPaused&&ln(t),ie()};if(t.readyState>=1)o();else{try{t.addEventListener("loadedmetadata",o,{once:!0})}catch(s){}try{t.addEventListener("loadeddata",o,{once:!0})}catch(s){}try{t.addEventListener("canplay",o,{once:!0})}catch(s){}n=window.setTimeout(o,2500)}}function He(){let e=on();if(!e)return;if(!w()){ie();return}if(c!=null&&c.api)return;if(H()===!0){ie(),Gt(e.routeSignature);return}let r=Ne();if(r.length===0){ne&&window.clearTimeout(ne),ne=window.setTimeout(He,300);return}Qe!==e.routeSignature&&(Qe=e.routeSignature,r.forEach(n=>fn(e,n)))}function hn(){window.setTimeout(He,150),window.setTimeout(He,700),window.setTimeout(He,1800)}function yn(e,t){if(!e||e.closest(".premium-rumble-wrapper"))return;let r=C(e),n=$(e);try{r&&typeof r.pause=="function"&&r.pause()}catch(i){}if(t)try{r&&typeof r.autoplay=="function"&&r.autoplay(!1)}catch(i){}try{r&&typeof r.src=="function"&&r.src([])}catch(i){}try{r&&typeof r.reset=="function"&&r.reset()}catch(i){}[e,n].forEach(i=>{var o,s;if(!(!i||(o=i.closest)!=null&&o.call(i,".premium-rumble-wrapper"))){try{i.pause()}catch(a){}if(t)try{i.autoplay=!1}catch(a){}try{i.removeAttribute("src")}catch(a){}try{Array.from(((s=i.querySelectorAll)==null?void 0:s.call(i,"source"))||[]).forEach(a=>{try{a.removeAttribute("src")}catch(d){}})}catch(a){}try{i.load()}catch(a){}}});try{"mediaSession"in navigator&&(navigator.mediaSession.playbackState="none")}catch(i){}}function gn(){let e=fe(),t=Te(),r=0;Ne().forEach(n=>{let i=st(n);Xt(i,t,!0,!0)&&r++,yn(n,i.paused)}),te=r>0,re=te?e:""}function bn(){if(!te||Dt||document.hidden)return;let e=fe();if(!w()||!re||e!==re){te=!1,re="";return}if(c!=null&&c.api){te=!1,re="";return}Dt=!0,te=!1,re="";try{"mediaSession"in navigator&&(navigator.mediaSession.playbackState="none")}catch(t){}window.location.reload()}async function vn(){return!_e()||!w()||c!=null&&c.api?!1:!await nt()}async function lt(){if(!Xe&&await vn()&&document.hidden){Xe=!0;try{gn()}finally{window.setTimeout(()=>{Xe=!1},900)}}}function ct(){document.hidden||bn()}pn(),hn();try{window.addEventListener("pagehide",()=>{w()&&(c!=null&&c.api||H()!==!0&&Ne().forEach(e=>{ut(e)?ke(e):Ue(e,!0)}))})}catch(e){}let mt=!1;function Ce(e){return!(!(e!=null&&e.api)||e.isMember||!_e()||w()&&ze())}async function $e(){var r,n,i;let e=c;if(!Ce(e)||!(e!=null&&e.api)||mt)return;mt=!0,Ie=!0;let t=e.api;try{await Zr(e);try{await Promise.resolve((r=t.pause)==null?void 0:r.call(t))}catch(o){}try{await Promise.resolve((n=t.mute)==null?void 0:n.call(t))}catch(o){}try{await Promise.resolve((i=t.setVolume)==null?void 0:i.call(t,0))}catch(o){}Yr(t),Ct(e.wrapper,t),await Y(!1),we(),Je()}finally{window.setTimeout(()=>{mt=!1},900)}}function dt(e){Ie&&(document.hidden||window.location.pathname.startsWith("/w/")&&$t(e))}document.addEventListener("visibilitychange",()=>{let e=c;if(document.hidden){if(e!=null&&e.api&&e.isMember){I(!0).catch(()=>{});return}if(Ce(e)){$e().catch(()=>{});return}if(!(e!=null&&e.api)){lt().catch(()=>{});return}e!=null&&e.api&&I(!0);return}if(c!=null&&c.api){I(!0);return}dt("visibilitychange-visible"),ct()}),window.addEventListener("pageshow",()=>{dt("pageshow"),ct()}),window.addEventListener("focus",()=>{dt("focus"),ct()}),window.addEventListener("pagehide",()=>{let e=c;if(e!=null&&e.api&&e.isMember){I(!0).catch(()=>{});return}if(Ce(e)){$e().catch(()=>{});return}if(!(e!=null&&e.api)){lt().catch(()=>{});return}e!=null&&e.api&&I(!0)});try{document.addEventListener("freeze",()=>{let e=c;if(e!=null&&e.api&&e.isMember){I(!0).catch(()=>{});return}if(Ce(e)){$e().catch(()=>{});return}lt().catch(()=>{})})}catch(e){}let pt=window.location.href;function De(e=!1){if(!e&&window.location.href===pt)return;let t=Pr();pt=window.location.href,ce="",me=0,ir(),Y(!1).finally(()=>{t===R&&(Ge()&&be(),ee(80,t))})}let wn=history.pushState;history.pushState=function(...e){let t=wn.apply(this,e);return setTimeout(De,50),t};let Pn=history.replaceState;history.replaceState=function(...e){let t=Pn.apply(this,e);return setTimeout(De,50),t},window.addEventListener("popstate",()=>setTimeout(De,50)),new MutationObserver(e=>{e.length>0&&e.every(r=>{var i;let n=r.target;return!!n&&!!((i=n.closest)!=null&&i.call(n,".premium-rumble-wrapper"))})||(window.location.href!==pt&&De(!1),clearTimeout(window.badgeTimeout),window.badgeTimeout=setTimeout(()=>{X(),ue()},450))}).observe(document.body,{childList:!0,subtree:!0});let ft=0,Tn=setInterval(()=>{X(),ue(),ft<6&&ee(700),ft++,ft>=10&&clearInterval(Tn)},700);Ge()&&be(),ee(150),setTimeout(ue,500)}export{Jn as register};
1
+ var Sn=Object.defineProperty,En=Object.defineProperties;var Mn=Object.getOwnPropertyDescriptors;var Yt=Object.getOwnPropertySymbols;var Rn=Object.prototype.hasOwnProperty,Ln=Object.prototype.propertyIsEnumerable;var er=(u,l,m)=>l in u?Sn(u,l,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[l]=m,D=(u,l)=>{for(var m in l||(l={}))Rn.call(l,m)&&er(u,m,l[m]);if(Yt)for(var m of Yt(l))Ln.call(l,m)&&er(u,m,l[m]);return u},ae=(u,l)=>En(u,Mn(l));var Be=class{constructor(l){this.rootEl=l}renderRow(l,m){return this.div([this.div(l,m?"col-12 col-lg-4 col-xl-3":"col-12"),...m?[this.div(m,"col-12 col-lg-8 col-xl-9")]:[]],"row")}div(l,m){let f=document.createElement("div");return m&&(f.className=m),l.forEach(b=>f.appendChild(b)),f}a(l,m){let f=document.createElement("a");f.innerHTML=l;for(let b in m)f.setAttribute(b,m[b]);return f}h2(l){let m=document.createElement("h2");return m.innerText=l,m}h3(l){let m=document.createElement("h2");return m.innerText=l,m}p(l,m){let f=document.createElement("p");return f.innerHTML=l,m&&(f.className=m),f}img(l,m){let f=document.createElement("img");return f.src=l,f.className=m,f}ul(l,m){let f=document.createElement("ul");return m&&(f.className=m),l.forEach(b=>{let M=document.createElement("li");M.innerText=b,f.appendChild(M)}),f}};var tr="enable-plugin";var ht=(u,l)=>{"gtag"in window&&window.gtag("event",u,D({event_category:"premium-users"},l))},se=(u,l)=>new Intl.NumberFormat(navigator.language,{style:"currency",currency:l,minimumFractionDigits:0}).format(u),yt=u=>{var l;return!((l=u.coupon)!=null&&l.valid)||!u.unit_amount?null:u.coupon.amount_off?(u.unit_amount-u.coupon.amount_off)/100:u.coupon.percent_off?Math.round((u.unit_amount-u.unit_amount*(u.coupon.percent_off/100))/100):null};var _n=u=>{var l,m,f;return(l=u.coupon)!=null&&l.percent_off?"".concat(u.coupon.percent_off," %"):se((f=(m=u.coupon)==null?void 0:m.amount_off)!=null?f:0,u.currency)},xn=async(u,l)=>{var m,f,b;return((m=u.recurring)==null?void 0:m.interval)==="month"?(await l("discount the first MONTHS_COUNT months.")).replace("MONTHS_COUNT",String((f=u.coupon)==null?void 0:f.duration_in_months)):((b=u.recurring)==null?void 0:b.interval)==="year"?l("discount for a whole year."):""},In=u=>{var m,f,b,M,B,R,V,N,S,E;let l=0;return((m=u.recurring)==null?void 0:m.interval)==="month"?(u.unit_amount&&((f=u.coupon)!=null&&f.amount_off)&&((b=u.coupon)!=null&&b.duration_in_months)&&(l=u.coupon.amount_off*((M=u.coupon)==null?void 0:M.duration_in_months)/100),u.unit_amount&&((B=u.coupon)!=null&&B.percent_off)&&((R=u.coupon)!=null&&R.duration_in_months)&&(l=u.unit_amount*(u.coupon.percent_off/100)*((V=u.coupon)==null?void 0:V.duration_in_months)/100)):((N=u.recurring)==null?void 0:N.interval)==="year"&&(u.unit_amount&&((S=u.coupon)!=null&&S.amount_off)&&(l=u.coupon.amount_off*12/100),u.unit_amount&&((E=u.coupon)!=null&&E.percent_off)&&(l=u.unit_amount*(u.coupon.percent_off/100)/100)),l},An=async(u,l)=>{var b;let m=yt(u),f;return m!==null?f='\n <span class="original-price">\n '.concat(se(u.unit_amount/100,u.currency),"</span>\n ").concat(se(m,u.currency)):f=se(u.unit_amount/100,u.currency),(b=u.recurring)!=null&&b.interval?f+=" / "+await l(u.recurring.interval):f+=" / "+await l("1 \u0E40\u0E14\u0E37\u0E2D\u0E19"),f},rr=async({buttonOnClick:u,price:l,uiBuilder:m,translate:f})=>{var F,q;let b=yt(l),M=await xn(l,f),B=In(l),R=_n(l),V=await An(l,f),N=!!u,S="";(F=l.recurring)!=null&&F.interval?S=await f("Pay "+(l.recurring.interval==="day"?"daily":l.recurring.interval+"ly")):S=await f("\u0E0A\u0E33\u0E23\u0E30 1 \u0E40\u0E14\u0E37\u0E2D\u0E19 (QR \u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E40\u0E1E\u0E22\u0E4C)");let E=m.a(V,{class:"primary-button peertube-button-link mb-4","data-testid":"premium_users-button-pay_"+(((q=l.recurring)==null?void 0:q.interval)||"onetime")});return N&&E.addEventListener("click",u),m.div([m.p(S,"fw-bold"),...b===null?[]:[m.ul([R+" "+M,(await f("You'll save AMOUNT_TO_SAVE.")).replace("AMOUNT_TO_SAVE",String(se(Math.round(B),l.currency)))],"text-start")],...N?[E]:[m.p(V,"mt-auto")]],"d-flex flex-grow-1 flex-column")};var nr={name:"peertube-plugin-premium-members",description:"peertube-plugin-premium-members",version:"3.2.1",author:"Vee",bugs:"",clientScripts:[{script:"dist/client/my-account/index.js",scopes:["my-account"]},{script:"dist/client/common.js",scopes:["common"]},{script:"dist/client/video-edit.js",scopes:["video-edit"]},{script:"dist/client/admin-manage.js",scopes:["common"]}],css:["dist/assets/style.css"],engine:{peertube:">=6.0.0"},homepage:"",keywords:["peertube","plugin"],library:"./dist/server/server/main.js",scripts:{clean:"rm -rf dist/*",prepare:"npm run build","build:client":"node ./scripts/build.cjs","build:server":"tsc --build server/tsconfig.json","build:styles":"npx --yes sass --no-source-map assets:dist/assets",build:"npm-run-all -s clean check:client:tsc -p build:server build:client build:styles","check:client:tsc":"npx tsc --p client/tsconfig.json --noEmit","lint:script":"npx eslint .",test:"npm-run-all -p lint:script test:unit","test:unit":"TS_NODE_PROJECT=server/tsconfig.test.json mocha server/*.spec.ts","test:e2e":"cd demo && npm ci && npm test"},staticDirs:{images:"public/images"},translations:{"sv-SE":"./languages/sv.json","th-TH":"./languages/th.json",th:"./languages/th.json"},devDependencies:{"@tsconfig/node16":"^16.0.0","@types/mocha":"^10.0.8","@typescript-eslint/eslint-plugin":"^8.9.0","@typescript-eslint/parser":"^8.9.0",esbuild:"^0.24.0",eslint:"^9.12.0","eslint-config-love":"^87.0.0",globals:"^15.3.0",mocha:"^10.7.3","npm-run-all":"^4.1.5",tsx:"^4.19.1",typescript:"^5.4.3"},dependencies:{"@peertube/peertube-types":"^6.3.0","@types/gtag.js":"^0.0.20","@types/sequelize":"^4.28.20",express:"^4.19.2","short-uuid":"^5.2.0",stripe:"^18.1.0"}};var K=class{constructor(l){this.pluginBasePath="/plugins/".concat(nr.name.replace("peertube-plugin-",""),"/router");this.getAuthHeader=l||(()=>{})}async get(l){return fetch(l,{method:"GET",headers:this.getAuthHeader(),credentials:"include"}).then(async m=>m.json())}async patch(l,m){await fetch(l,{method:"PATCH",headers:ae(D({},this.getAuthHeader()),{"Content-Type":"application/json"}),credentials:"include",body:JSON.stringify(m)})}async post(l,m){return fetch(l,{method:"POST",headers:ae(D({},this.getAuthHeader()),{"Content-Type":"application/json"}),credentials:"include",body:JSON.stringify(m)}).then(async f=>f.json())}async delete(l){return fetch(l,{method:"DELETE",headers:this.getAuthHeader(),credentials:"include"}).then(async m=>m.json())}async getMe(){return this.get("/api/v1/users/me")}async getPrices(){return this.get(this.pluginBasePath+"/price")}async getSubscription(){return this.get(this.pluginBasePath+"/subscription")}async updateSubscription(l){return this.patch(this.pluginBasePath+"/subscription",l)}async createCheckout({allowPromotionCodes:l,couponId:m,priceId:f,paymentMode:b,paymentMethod:M}){return this.post(this.pluginBasePath+"/checkout",{allowPromotionCodes:l,couponId:m,priceId:f,paymentMode:b,paymentMethod:M})}async getRumblePlaybackInfo(l){return this.get(this.pluginBasePath+"/rumble/playback-info/".concat(encodeURIComponent(l)))}async saveRumbleProgress(l){return this.post(this.pluginBasePath+"/rumble/progress",l)}async saveRumbleDuration(l){return this.post(this.pluginBasePath+"/rumble/duration",l)}async getRumbleProgress(l){return this.get(this.pluginBasePath+"/rumble/progress/".concat(encodeURIComponent(l)))}async saveNativePeerTubeProgress(l){return this.post(this.pluginBasePath+"/native/progress",l)}async getNativePeerTubeProgress(l){return this.get(this.pluginBasePath+"/native/progress/".concat(encodeURIComponent(l)))}async getRumbleHistory(l=50,m=0){return this.get(this.pluginBasePath+"/rumble/history?limit=".concat(l,"&offset=").concat(m))}async deleteRumbleHistoryItem(l){return this.delete(this.pluginBasePath+"/rumble/history/".concat(encodeURIComponent(l)))}async clearRumbleHistory(){return this.delete(this.pluginBasePath+"/rumble/history")}};async function Jn({peertubeHelpers:u,registerClientRoute:l,registerHook:m}){let b=!!(await u.getSettings())[tr];m({target:"filter:left-menu.links.create.result",handler:async e=>{if(!b)return e;let t=!1;if(u.isLoggedIn())try{let i=u.getAuthHeader;t=(await new K(i).getMe()).isPremium===!0}catch(i){console.error("\u274C [Premium Plugin] Failed to fetch premium status for menu:",i)}let r=u.isLoggedIn()?"/my-account/p/premium":"/p/premium",n=await u.translate(t?"Premium account":"Become premium");return e.map(i=>i.key==="quick-access"?ae(D({},i),{links:[...i.links,{path:r,icon:t?"premium":void 0,label:n,shortLabel:n,isPrimaryButton:!t}]}):u.isLoggedIn()&&i.key==="my-library"?ae(D({},i),{links:[...i.links,{path:"/p/rumble-history",label:"\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21",shortLabel:"\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34",icon:"history"}]}):i)}}),m({target:"filter:internal.common.svg-icons.get-content.result",handler:(e,t)=>t.name==="premium"?'\n\n <svg\n\n fill="gray"\n\n version="1.1"\n\n xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"\n\n viewBox="0 0 45.402 45.402"\n\n xml:space="preserve">\n\n <g>\n\n <path d="M41.267,18.557H26.832V4.134C26.832,1.851,24.99,0,22.707,0c-2.283,0-4.124,1.851-4.124,4.135v14.432H4.141\n\n c-2.283,0-4.139,1.851-4.138,4.135c-0.001,1.141,0.46,2.187,1.207,2.934c0.748,0.749,1.78,1.222,2.92,1.222h14.453V41.27\n\n c0,1.142,0.453,2.176,1.201,2.922c0.748,0.748,1.777,1.211,2.919,1.211c2.282,0,4.129-1.851,4.129-4.133V26.857h14.435\n\n c2.283,0,4.134-1.867,4.133-4.15C45.399,20.425,43.548,18.557,41.267,18.557z"/>\n\n </g>\n\n </svg>':e});let M=e=>()=>{let t=new URLSearchParams(window.location.search).get("redirect");t&&m({target:"action:auth-user.logged-in",handler:()=>{ht("tutorial_complete",{event_label:e}),window.location.href=t}})};if(m({target:"action:login.init",handler:M("login")}),m({target:"action:signup.register.init",handler:M("signup")}),l({route:"/premium",title:await u.translate("Become premium"),onMount:async({rootEl:e})=>{if(u.isLoggedIn()){window.location.href="/my-account/p/premium";return}ht("tutorial_begin");let r=await new K().getPrices(),n=new Be(e),i=await Promise.all(r.map(s=>rr({price:s,uiBuilder:n,translate:u.translate}))),o=n.div([n.img("/client/assets/images/icons/icon-192x192.png","instance-logo"),n.h2(await u.translate("Become a premium user")),n.p(await u.translate("Get access to premium videos and helps us to continue our work.")),n.div(i.map(s=>n.div([s],"col-12 col-sm-6 d-flex")),"prices-alternatives row my-5 mx-auto"),n.div([n.a(await u.translate("Create an account"),{class:"primary-button peertube-button-link button-md mb-2",href:"/signup?redirect=/my-account/p/premium","data-testid":"premium_users-button-create_account"}),n.p(await u.translate("or"),"mb-0"),n.a(await u.translate("Login"),{class:"secondary-button peertube-button-link mt-2 button-md",href:"/login?redirect=/my-account/p/premium"})],"action-buttons d-flex justify-content-center flex-column mb-4 mx-sm-auto")],"plugin-premium-users become-premium margin-content pt-4 text-center mx-auto px-4 px-md-0");e.appendChild(o)}}),!b)return;function B(e){e=Math.max(0,Math.floor(Number(e)||0));let t=Math.floor(e/3600),r=Math.floor(e%3600/60),n=e%60;return t>0?"".concat(t,":").concat(String(r).padStart(2,"0"),":").concat(String(n).padStart(2,"0")):"".concat(r,":").concat(String(n).padStart(2,"0"))}function R(e){return String(e!=null?e:"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function V(e){var r,n;let t=(e==null?void 0:e.thumbnailPath)||(e==null?void 0:e.previewPath)||(e==null?void 0:e.thumbnailUrl)||(e==null?void 0:e.previewUrl)||((n=(r=e==null?void 0:e.files)==null?void 0:r[0])==null?void 0:n.thumbnailPath)||"";return t?/^https?:\/\//i.test(t)?t:"".concat(window.location.origin).concat(t.startsWith("/")?"":"/").concat(t):""}async function N(e){var n;if(e.innerHTML='<div class="margin-content"><h1>\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</h1><p>\u0E01\u0E33\u0E25\u0E31\u0E07\u0E42\u0E2B\u0E25\u0E14...</p></div>',!u.isLoggedIn()){e.innerHTML='<div class="margin-content"><h1>\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</h1><p>\u0E01\u0E23\u0E38\u0E13\u0E32\u0E40\u0E02\u0E49\u0E32\u0E2A\u0E39\u0E48\u0E23\u0E30\u0E1A\u0E1A\u0E01\u0E48\u0E2D\u0E19</p></div>';return}let t=new K(u.getAuthHeader),r=()=>N(e);try{let i=await t.getRumbleHistory(50,0),o=Array.isArray(i==null?void 0:i.data)?i.data:[];if(o.length===0){e.innerHTML='\n <div class="margin-content">\n <h1>\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</h1>\n <p>\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</p>\n </div>\n ';return}let s=await Promise.all(o.map(async a=>{var j,A,G,Se;let d=a.videoUuid,p="/w/".concat(encodeURIComponent(a.videoUuid)),g="",v="";try{let oe=await fetch("/api/v1/videos/".concat(encodeURIComponent(a.videoUuid)),{headers:((j=u.getAuthHeader)==null?void 0:j.call(u))||{},credentials:"include"});if(oe.ok){let _=await oe.json();d=_.name||d,_.shortUUID&&(p="/w/".concat(_.shortUUID)),g=V(_),v=((A=_.channel)==null?void 0:A.displayName)||((G=_.account)==null?void 0:G.displayName)||((Se=_.account)==null?void 0:Se.name)||""}}catch(oe){}let P=Math.max(0,Math.floor(Number(a.lastPositionSeconds||0))),y=Math.max(0,Math.floor(Number(a.durationSeconds||0))),h=Number(a.watchedPercent||0),T="".concat(p).concat(p.includes("?")?"&":"?","rumbleStart=").concat(P,"&rumbleAutoplay=1"),I=String(a.videoUuid||"");return'\n <div class="premium-rumble-history-row" data-video-uuid="'.concat(R(I),'" style="display:flex;gap:14px;align-items:flex-start;padding:14px 0;border-bottom:1px solid var(--greyForegroundColor, #ddd);">\n <a href="').concat(R(T),'" style="display:block;width:180px;max-width:35%;flex:0 0 180px;background:#111;border-radius:4px;overflow:hidden;">\n ').concat(g?'<img src="'.concat(R(g),'" alt="" loading="lazy" style="display:block;width:100%;aspect-ratio:16/9;object-fit:cover;">'):'<div style="width:100%;aspect-ratio:16/9;background:#111;"></div>','\n </a>\n <div style="min-width:0;flex:1;">\n <a href="').concat(R(T),'" style="font-weight:600;font-size:16px;line-height:1.35;display:block;word-break:break-word;">').concat(R(d),"</a>\n ").concat(v?'<div style="font-size:13px;opacity:.75;margin-top:4px;">'.concat(R(v),"</div>"):"",'\n <div style="font-size:13px;opacity:.85;margin-top:5px;">\u0E14\u0E39\u0E16\u0E36\u0E07 ').concat(B(P)," / ").concat(B(y)," (").concat(h,'%)</div>\n <div style="margin-top:10px;display:flex;gap:8px;align-items:center;flex-wrap:wrap;">\n <button class="peertube-button secondary-button button-sm premium-rumble-delete-history" data-video-uuid="').concat(R(I),'" type="button">\u0E25\u0E1A\u0E2D\u0E2D\u0E01\u0E08\u0E32\u0E01\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34</button>\n </div>\n </div>\n </div>\n ')}));e.innerHTML='\n <div class="margin-content">\n <div style="display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;margin-bottom:16px;">\n <div>\n <h1 style="margin-bottom:4px;">\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</h1>\n </div>\n <button class="peertube-button secondary-button premium-rumble-clear-history" type="button">\u0E25\u0E49\u0E32\u0E07\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E17\u0E31\u0E49\u0E07\u0E2B\u0E21\u0E14</button>\n </div>\n <div>'.concat(s.join(""),"</div>\n </div>\n "),e.querySelectorAll(".premium-rumble-delete-history").forEach(a=>{a.addEventListener("click",async()=>{let d=a.dataset.videoUuid;if(d)try{await t.deleteRumbleHistoryItem(d),await r()}catch(p){console.error("\u274C [Premium Rumble] delete history failed:",p)}})}),(n=e.querySelector(".premium-rumble-clear-history"))==null||n.addEventListener("click",async()=>{if(window.confirm("\u0E25\u0E49\u0E32\u0E07\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21\u0E17\u0E31\u0E49\u0E07\u0E2B\u0E21\u0E14?"))try{await t.clearRumbleHistory(),await r()}catch(a){console.error("\u274C [Premium Rumble] clear history failed:",a)}})}catch(i){console.error("\u274C [Premium Rumble] Failed to load history:",i),e.innerHTML='<div class="margin-content"><h1>\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21</h1><p>\u0E42\u0E2B\u0E25\u0E14\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08</p></div>'}}l({route:"/rumble-history",title:"\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E23\u0E31\u0E1A\u0E0A\u0E21",parentRoute:"/",onMount:async({rootEl:e})=>N(e)});let S=new Map,E=[],F=!1,q=window.location.origin,Ee=new AbortController;function ir(){Ee.abort(),Ee=new AbortController,E=[],S.clear(),F=!1}async function or(){if(!(F||E.length===0)){for(F=!0;E.length>0;){let e=E[0];if(!e)break;try{let t=await fetch(e.url,{signal:Ee.signal});if(t.status===429){await new Promise(r=>setTimeout(r,1e3));continue}E.shift(),e.resolve(t),S.delete(e.url)}catch(t){E.shift(),e.resolve(null),S.delete(e.url)}Ee.signal.aborted||await new Promise(t=>setTimeout(t,100))}F=!1}}function Me(e){if(S.has(e))return S.get(e);let t=new Promise(r=>{E.push({url:e,resolve:r}),or()});return S.set(e,t),t}function gt(e){return"premium_cache_checked_videos_".concat(e)}function bt(e){return"premium_cache_checked_shortUUID_".concat(e)}function Z(e){return"premium_cache_map_uuid_to_short_".concat(e)}function J(e){return"premium_cache_map_short_to_uuid_".concat(e)}function ar(e){e=Math.max(0,Math.floor(Number(e)||0));let t=Math.floor(e/3600),r=Math.floor(e%3600/60),n=e%60;return t>0?"".concat(t,":").concat(String(r).padStart(2,"0"),":").concat(String(n).padStart(2,"0")):"".concat(r,":").concat(String(n).padStart(2,"0"))}function sr(e){if(!e)return;let t=e.pluginData||{},r=t["use-rumble-player"]==="true"||t["use-rumble-player"]===!0||t["use-rumble-player"]==="1",n=Number(t["rumble-duration-seconds"]||0);if(!r||!n||n<=0)return;[e.uuid,e.shortUUID].filter(Boolean).forEach(o=>{sessionStorage.setItem(ye(o),"true"),sessionStorage.setItem(Tt(o),String(Math.floor(n)))})}function ur(e){try{let r=new URL(e,window.location.origin).pathname.match(/^\/w\/(?!p\/)([a-zA-Z0-9-]+)/);return(r==null?void 0:r[1])||null}catch(t){let r=e.match(/\/w\/(?!p\/)([a-zA-Z0-9-]+)/);return(r==null?void 0:r[1])||null}}let Ve=new Set;function lr(e,t){let r=Math.max(1,Math.floor(Number(t)||1)),n=Math.floor((r-1)/100)*100,i="".concat(e,"_").concat(n);Ve.has(i)||sessionStorage.getItem("premium_rumble_playlist_duration_page_".concat(i))!=="true"&&(Ve.add(i),setTimeout(async()=>{try{let o=await Me("".concat(q,"/api/v1/video-playlists/").concat(e,"/videos?start=").concat(n,"&count=100"));if(!o||!o.ok)return;let s=await o.json();O(s,"/api/v1/video-playlists/".concat(e,"/videos?start=").concat(n,"&count=100")),sessionStorage.setItem("premium_rumble_playlist_duration_page_".concat(i),"true"),setTimeout(ue,120)}catch(o){console.warn("\u26A0\uFE0F [Premium Rumble] playlist duration metadata fetch failed:",o)}finally{Ve.delete(i)}},250))}function cr(e){let t=e.closest('a[href*="/w/"]'),r=e.closest('a[href*="/w/"], .video-thumbnail, .video-miniature, .video-wrapper, .video, my-video-miniature, my-video-playlist-element-miniature'),n=t||(r==null?void 0:r.querySelector('a[href*="/w/"]'));if(!(n!=null&&n.href))return null;let i=ur(n.href);if(i)return i;let o=Mr(n.href);if(o){let s=sessionStorage.getItem(We(o.playlistUuid,o.position));if(s)return s;lr(o.playlistUuid,o.position)}return null}function ue(){document.querySelectorAll(".duration-overlay").forEach(e=>{let t=e,r=cr(t);if(!r)return;let n=Number(sessionStorage.getItem(Tt(r))||0);if(!n||n<=0)return;let i=ar(n);t.textContent!==i&&(t.textContent=i),t.setAttribute("aria-label","Video duration is ".concat(i))})}function mr(e,t){e!=null&&e.uuid&&(sessionStorage.setItem(gt(e.uuid),"true"),e.shortUUID&&(sessionStorage.setItem(bt(e.shortUUID),"true"),sessionStorage.setItem(Z(e.uuid),e.shortUUID),sessionStorage.setItem(J(e.shortUUID),e.uuid)),t?(sessionStorage.setItem("premium_cache_videos_".concat(e.uuid),"true"),e.shortUUID&&sessionStorage.setItem("premium_cache_shortUUID_".concat(e.shortUUID),"true")):(sessionStorage.removeItem("premium_cache_videos_".concat(e.uuid)),e.shortUUID&&sessionStorage.removeItem("premium_cache_shortUUID_".concat(e.shortUUID))))}function vt(e){let t=e.match(/\/api\/v1\/videos\/([^/?#]+)/);return t!=null&&t[1]?decodeURIComponent(t[1]):null}function dr(){let e=[];for(let t=0;t<sessionStorage.length;t++){let r=sessionStorage.key(t);r&&r.startsWith("premium_cache_playlist_")&&e.push(r)}e.forEach(t=>sessionStorage.removeItem(t))}function pr(e){let t=sessionStorage.getItem(Z(e)),r=sessionStorage.getItem(J(e)),n=new Set([e]);t&&n.add(t),r&&n.add(r),n.forEach(i=>{sessionStorage.removeItem("premium_cache_videos_".concat(i)),sessionStorage.removeItem("premium_cache_shortUUID_".concat(i)),sessionStorage.removeItem(gt(i)),sessionStorage.removeItem(bt(i)),sessionStorage.removeItem(Z(i)),sessionStorage.removeItem(J(i))}),dr()}function fr(e){let t=e.querySelector(".custom-member-badge");t&&t.remove(),e.classList.remove("has-premium-badge"),delete e.dataset.premiumFetchRequested}function wt(e){let t=sessionStorage.getItem(Z(e)),r=sessionStorage.getItem(J(e)),n=new Set([e]);t&&n.add(t),r&&n.add(r),pr(e);let i=["my-video-miniature",".video-miniature","ptb-video-miniature","my-video-playlist-element-miniature",".video-playlist-miniature","my-video-cell","my-video-list-element","my-user-video-history-element","tr.p-selectable-row","my-video-playlist-element","my-recommended-videos my-video-miniature"].join(", ");document.querySelectorAll(i).forEach(o=>{let s=o.tagName.toLowerCase()==="a"?o:o.querySelector('a.video-title, a.title, a.video-name, a.pt-router-link, a[href*="/w/"], a[href*="/video-playlists/"]');if(!s)return;let a=s.href||"",d=!1;for(let p of n)if(a.includes("/w/".concat(p))){d=!0;break}!d&&(a.includes("/w/p/")||a.includes("/video-playlists/"))&&(d=!0),d&&fr(o)}),setTimeout(X,50),setTimeout(X,250)}function Pt(){let e=[];for(let t=0;t<sessionStorage.length;t++){let r=sessionStorage.key(t);r&&r.startsWith("premium_cache_")&&e.push(r)}e.forEach(t=>sessionStorage.removeItem(t)),S.clear(),document.querySelectorAll(".has-premium-badge, [data-premium-fetch-requested]").forEach(t=>{let r=t.querySelector(".custom-member-badge");r&&r.remove(),t.classList.remove("has-premium-badge"),delete t.dataset.premiumFetchRequested}),setTimeout(X,200)}function O(e,t){let r=!1;e&&e.data&&Array.isArray(e.data)&&e.data.forEach(n=>{let i=n.video||n;if(i&&i.uuid){let o=t.match(/\/api\/v1\/video-playlists\/([a-zA-Z0-9-]+)/);if(o!=null&&o[1]&&n.position){let a=i.shortUUID||i.uuid;sessionStorage.setItem(We(o[1],n.position),a),i.shortUUID&&(sessionStorage.setItem(J(i.shortUUID),i.uuid),sessionStorage.setItem(Z(i.uuid),i.shortUUID))}sr(i);let s=!1;if(i.pluginData){let a=i.pluginData["is-premium-content"];s=a==="true"||a===!0||a==="1"}if(s||(s=sessionStorage.getItem("premium_cache_videos_".concat(i.uuid))==="true"),mr(i,s),s){if(n.position&&t.includes("/video-playlists/")){let a=t.match(/\/api\/v1\/video-playlists\/([a-zA-Z0-9-]+)/);a&&a[1]&&sessionStorage.setItem("premium_cache_playlist_".concat(a[1],"_pos_").concat(n.position),"true")}r=!0}else if(n.position&&t.includes("/video-playlists/")){let a=t.match(/\/api\/v1\/video-playlists\/([a-zA-Z0-9-]+)/);a&&a[1]&&sessionStorage.removeItem("premium_cache_playlist_".concat(a[1],"_pos_").concat(n.position))}}}),setTimeout(ue,150),r&&setTimeout(X,100)}window.processPeerTubePremiumData=O;let hr=XMLHttpRequest.prototype.open,yr=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(e,t){return this._customMethod=e.toUpperCase(),this._customUrl=t.toString(),hr.apply(this,arguments)},XMLHttpRequest.prototype.send=function(){return this.addEventListener("load",function(){let e=this._customUrl,t=this._customMethod;if(e){if(t==="PUT"&&e.includes("/api/v1/videos/")&&!e.includes("/views")&&!e.includes("/rate")&&!e.includes("/passwords")&&this.status>=200&&this.status<300){let n=vt(e);setTimeout(n?()=>wt(n):Pt,300)}if(e.includes("/api/v1/"))try{let n=typeof this.response=="string"?JSON.parse(this.response):this.response;n&&n.data&&Array.isArray(n.data)&&O(n,e)}catch(n){}}}),yr.apply(this,arguments)};let gr=window.fetch;window.fetch=async function(...e){let t=e[0]instanceof Request?e[0]:null,r=t?t.url:e[0],i=(t?t.method.toUpperCase():e[1]&&e[1].method?e[1].method.toUpperCase():"GET")==="PUT"&&r.includes("/api/v1/videos/")&&!r.includes("/views")&&!r.includes("/rate")&&!r.includes("/passwords"),o=await gr.apply(this,e);if(i&&o.ok){let a=vt(r);setTimeout(a?()=>wt(a):Pt,300)}let s=o.clone();try{r.includes("/api/v1/")&&s.json().then(a=>{a&&a.data&&Array.isArray(a.data)&&O(a,r)}).catch(()=>{})}catch(a){}return o};function br(e,t="append",r="block"){var a;if(!e)return!1;let n=t==="after"?e.parentNode:e;if(!n||n.querySelector(".custom-member-badge"))return!1;let i=document.createElement("div");i.className="custom-member-badge";let o="display: inline-flex; align-items: center; color: #127a1b; font-size: 12px; font-weight: 500; margin-top: 4px; margin-bottom: 2px; border: none; outline: none; box-shadow: none;";r==="block"?o+=" width: 100%;":r==="inline"&&(o+=" margin-left: 8px; vertical-align: middle;"),i.style.cssText=o,i.innerHTML='<svg style="width: 14px; height: 14px; margin-right: 4px; fill: currentColor;" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm4.24 16L12 15.45 7.77 18l1.12-4.81-3.73-3.23 4.92-.42L12 5l1.92 4.53 4.92.42-3.73 3.23L16.23 18z"/></svg>\u0E40\u0E09\u0E1E\u0E32\u0E30\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01';let s=r==="block"?(()=>{let d=document.createElement("div");return d.style.cssText="display: block; width: 100%; clear: both; border: none; margin: 0; padding: 0;",d.appendChild(i),d})():i;return t==="after"?(a=e.parentNode)==null||a.insertBefore(s,e.nextSibling):e.appendChild(s),!0}async function vr(e,t){let r="premium_cache_playlist_".concat(e,"_pos_").concat(t);if(sessionStorage.getItem(r)==="true")return!0;let n=100,i=0;try{for(;;){let o=await Me("".concat(q,"/api/v1/video-playlists/").concat(e,"/videos?start=").concat(i,"&count=").concat(n));if(!o||!o.ok)break;let s=await o.json();if(O(s,"/api/v1/video-playlists/".concat(e,"/videos?start=").concat(i,"&count=").concat(n)),sessionStorage.getItem(r)==="true")return!0;if((Array.isArray(s==null?void 0:s.data)?s.data:[]).length<n)break;i+=n}}catch(o){}return!1}function X(){let e=["my-video-miniature",".video-miniature","ptb-video-miniature","my-video-playlist-element-miniature",".video-playlist-miniature","my-video-cell","my-video-list-element","my-user-video-history-element","tr.p-selectable-row","my-video-playlist-element","my-recommended-videos my-video-miniature"].join(", "),t=document.querySelectorAll(e),r=window.location.pathname;t.forEach(n=>{if(n.querySelector(".custom-member-badge")){n.classList.add("has-premium-badge");return}let i=n.tagName.toLowerCase()==="a"?n:n.querySelector('a.video-title, a.title, a.video-name, a.pt-router-link, a[href*="/w/"], a[href*="/video-playlists/"]');if(i)try{let o=new URL(i.href,window.location.origin),s=o.searchParams.get("playlistPosition"),a=null,d=!1,p=n.tagName.toLowerCase().includes("playlist")||n.classList.contains("video-playlist-miniature")||n.classList.contains("my-video-playlist-element");if(o.pathname.includes("/w/p/")||o.pathname.includes("/video-playlists/")||p){let g=o.pathname.match(/(?:\/w\/p\/|\/video-playlists\/)([a-zA-Z0-9-]+)/);g&&(a=g[1]),d=!0}else{let g=o.pathname.match(/\/w\/([a-zA-Z0-9-]+)/);g&&(a=g[1])}if(!a){let g=n.querySelector('img[src*="/thumbnails/"]');if(g){let v=g.src.match(/\/thumbnails\/([a-zA-Z0-9-]+)\.jpg/);v&&v[1]&&(a=v[1])}}if(a){let g=!!(n.closest("my-recommended-videos")||n.closest(".other-videos")),v=sessionStorage.getItem("premium_cache_videos_".concat(a))==="true"||sessionStorage.getItem("premium_cache_shortUUID_".concat(a))==="true";!v&&s&&!g&&(v=sessionStorage.getItem("premium_cache_playlist_".concat(a,"_pos_").concat(s))==="true");let P=()=>{let y=null,h="append",T="block";r.includes("/admin/overview/videos")||r.includes("/my-library/videos")?(y=n.querySelector('a.channel.ellipsis[href*="/c/"]'),y&&(h="after",T="block")):r.includes("/my-library/history/videos")?(y=n.querySelector('a.inherit-parent-style[href*="/c/"]'),y&&(h="after",T="block")):g?(y=n.querySelector(".video-info-owner")||n.querySelector(".video-info"),y&&(h="append",T="block")):r.includes("/w/p/")?(y=n.querySelector(".video-info-owner"),y&&(h="after",T="block")):(y=n.querySelector(".video-info")||n.querySelector(".video-miniature-info")||n.querySelector(".metadata"),y&&(h="append",T="block")),y&&br(y,h,T)&&n.classList.add("has-premium-badge")};if(!v&&d&&s&&!g){if(n.dataset.premiumFetchRequested)return;n.dataset.premiumFetchRequested="true",vr(a,s).then(y=>{y?P():n.dataset.premiumFetchRequested="failed"}).catch(()=>{n.dataset.premiumFetchRequested="failed"})}else if(!v&&!d){if(a.includes("playlist-")||sessionStorage.getItem("premium_cache_checked_videos_".concat(a))==="true"||sessionStorage.getItem("premium_cache_checked_shortUUID_".concat(a))==="true"||n.dataset.premiumFetchRequested)return;n.dataset.premiumFetchRequested="true",Me("".concat(q,"/api/v1/videos/").concat(a)).then(h=>!h||!h.ok?(n.dataset.premiumFetchRequested="failed",null):h.json()).then(h=>{h&&(O({data:[h]},"/api/v1/videos/".concat(a)),sessionStorage.getItem("premium_cache_videos_".concat(a))==="true"&&P()),n.dataset.premiumFetchRequested="failed"}).catch(()=>{n.dataset.premiumFetchRequested="failed"})}else v&&P()}}catch(o){}})}let wr=u.getAuthHeader,z=new K(wr),c=null,Q="",le=null,ce="",Re=null,Fe="",me=0,de=null,pe=null,Le=null,qe=0,L=0;function fe(){return"".concat(window.location.pathname).concat(window.location.search)}function Pr(){return L++,qe++,le&&(clearTimeout(le),le=null),L}function he(e,t,r){return!(e!==L||t!==fe()||typeof r=="number"&&r!==qe)}let Tr="premium_rumble_duration_",Sr="premium_rumble_use_player_",Er="premium_rumble_local_progress_";function ye(e){return"".concat(Sr).concat(e)}function Tt(e){return"".concat(Tr).concat(e)}function Oe(e){return"".concat(Er).concat(e)}function St(e){if(!e)return null;try{let t=localStorage.getItem(Oe(e));if(!t)return null;let r=JSON.parse(t),n=Math.max(0,Math.floor(Number(r.positionSeconds)||0)),i=Math.max(0,Math.floor(Number(r.durationSeconds)||0)),o=Math.max(0,Math.floor(Number(r.updatedAt)||0));return!i||i<=0||i-n<=2?null:{positionSeconds:n,durationSeconds:i,updatedAt:o}}catch(t){return null}}function Et(e,t,r){let n=Math.max(0,Math.floor(Number(t)||0)),i=Math.max(0,Math.floor(Number(r)||0));if(!i||i<=0||u.isLoggedIn()||i-n<=2)return;let o=JSON.stringify({positionSeconds:n,durationSeconds:i,updatedAt:Date.now()}),s=new Set;s.add(e.videoUuid);let a=ge();a&&s.add(a),s.forEach(d=>{try{localStorage.setItem(Oe(d),o)}catch(p){}}),e.lastSavedPosition=n}function Mt(e){let t=new Set;e.forEach(n=>{let i=String(n||"").trim();i&&t.add(i)});let r=ge();r&&t.add(r),t.forEach(n=>{try{localStorage.removeItem(Oe(n))}catch(i){}})}function Rt(e){e&&Mt([e.videoUuid,e.rumbleVideoId])}function w(){return window.location.pathname.startsWith("/w/")}function ze(){return document.visibilityState==="visible"&&!document.hidden}function We(e,t){return"premium_rumble_playlist_".concat(e,"_pos_").concat(t,"_video")}function Mr(e){try{let t=new URL(e,window.location.origin),r=t.pathname.match(/^\/w\/p\/([a-zA-Z0-9-]+)/),n=t.searchParams.get("playlistPosition")||"1";return r!=null&&r[1]?{playlistUuid:r[1],position:n}:null}catch(t){let r=e.match(/\/w\/p\/([a-zA-Z0-9-]+).*?[?&]playlistPosition=(\d+)/);return r!=null&&r[1]?{playlistUuid:r[1],position:r[2]||"1"}:null}}function ge(){let e=window.location.pathname.match(/^\/w\/(?!p\/)([a-zA-Z0-9-]+)/);return(e==null?void 0:e[1])||null}async function Rr(e,t){let r=Number(t);if(!e||!Number.isFinite(r)||r<=0)return null;let n="premium_rumble_playlist_video_".concat(e,"_pos_").concat(t),i=sessionStorage.getItem(n);if(i)return i;let o=Math.max(0,Math.floor(r)-1),s=await Me("".concat(q,"/api/v1/video-playlists/").concat(e,"/videos?start=").concat(o,"&count=1"));if(!s||!s.ok)return null;let a=await s.json();O(a,"/api/v1/video-playlists/".concat(e,"/videos?start=").concat(o,"&count=1"));let d=Array.isArray(a==null?void 0:a.data)?a.data[0]:null,p=(d==null?void 0:d.video)||d,g=(p==null?void 0:p.shortUUID)||(p==null?void 0:p.uuid)||null;return g&&(sessionStorage.setItem(n,g),p!=null&&p.uuid&&sessionStorage.setItem(J(g),p.uuid),p!=null&&p.shortUUID&&sessionStorage.setItem(Z(p.uuid),p.shortUUID)),g}async function Lt(){if(window.location.pathname.startsWith("/w/p/")){let e=window.location.pathname.match(/^\/w\/p\/([a-zA-Z0-9-]+)/),t=e==null?void 0:e[1],r=new URLSearchParams(window.location.search).get("playlistPosition")||"1";if(!t)return null;let n=await Rr(t,r);if(n)return n;let i=document.querySelector('#videojs-wrapper .vjs-peertube-link[href*="/w/"], .vjs-peertube-link[href*="/w/"]');if(i!=null&&i.href){let o=i.href.match(/\/w\/(?!p\/)([a-zA-Z0-9-]+)/);if(o!=null&&o[1])return o[1]}return null}return ge()}function je(){let e=["my-video-watch #videojs-wrapper","#videojs-wrapper","my-video-watch .player-wrapper","my-video-watch my-video-watch-player","my-video-watch .video-player","my-video-watch .player-container",".player-wrapper"];for(let r of e){let n=document.querySelector(r);if(n)return n}let t=document.querySelector("my-video-watch .video-js, my-video-watch video");return t?t.closest("#videojs-wrapper, .player-wrapper, my-video-watch-player, .video-player, .player-container, .player")||t.parentElement:null}function _t(e,t=!1){if(!e.closest(".premium-rumble-wrapper")){try{e.pause()}catch(r){}if(t){try{e.autoplay=!1}catch(r){}try{e.setAttribute("preload","none")}catch(r){}}}}function U(e,t=!0){(e||document).querySelectorAll("video").forEach(n=>{let i=n;i.closest(".premium-rumble-wrapper")||_t(i,t)})}function Lr(e){(e||je()||document).querySelectorAll("video").forEach(r=>{let n=r;if(!n.closest(".premium-rumble-wrapper")){try{n.muted=!1}catch(i){}try{n.volume===0&&(n.volume=1)}catch(i){}}})}function Ge(){let e=new URLSearchParams(window.location.search);return e.has("rumbleStart")||e.get("rumbleAutoplay")==="1"||e.has("startSeconds")}function xt(){(document.querySelector("my-video-watch, #videojs-wrapper")||document).querySelectorAll("video").forEach(t=>{_t(t,!1)})}function be(){de||(xt(),de=window.setInterval(()=>{if(c!=null&&c.api){k();return}if(!window.location.pathname.startsWith("/w/")){k();return}xt()},250))}function k(){de&&(window.clearInterval(de),de=null)}function ve(e=!0){pe&&(pe.remove(),pe=null),e&&Le&&Nt(Le),Le=null}function _r(e){if(c||pe||sessionStorage.getItem(ye(e))!=="true")return;let t=je();if(!t)return;U(t,!1);let r=Ht();r.innerHTML='<div class="premium-rumble-loading-placeholder">\u0E01\u0E33\u0E25\u0E31\u0E07\u0E42\u0E2B\u0E25\u0E14\u0E40\u0E04\u0E23\u0E37\u0E48\u0E2D\u0E07\u0E40\u0E25\u0E48\u0E19</div>',t.insertBefore(r,t.firstChild),pe=r,Le=At(t,r)}function It(){if(document.getElementById("premium-rumble-style"))return;let e=document.createElement("style");e.id="premium-rumble-style",e.textContent='\n .premium-rumble-wrapper {\n display: block !important;\n width: 100% !important;\n max-width: 100% !important;\n aspect-ratio: 16 / 9 !important;\n background: #000 !important;\n position: relative !important;\n overflow: hidden !important;\n margin: 0 !important;\n padding: 0 !important;\n line-height: 0 !important;\n }\n .premium-rumble-loading-placeholder {\n width: 100% !important;\n height: 100% !important;\n display: flex !important;\n align-items: center !important;\n justify-content: center !important;\n background: #000 !important;\n color: #aaa !important;\n font-size: 14px !important;\n line-height: 1.4 !important;\n box-sizing: border-box !important;\n }\n .premium-rumble-pending > *:not(.premium-rumble-wrapper) {\n display: none !important;\n }\n .premium-rumble-wrapper > div,\n .premium-rumble-wrapper [id^="vid_"],\n .premium-rumble-wrapper iframe,\n .premium-rumble-wrapper video,\n .premium-rumble-wrapper object,\n .premium-rumble-wrapper embed {\n width: 100% !important;\n height: 100% !important;\n max-width: 100% !important;\n max-height: 100% !important;\n margin: 0 !important;\n border: 0 !important;\n box-sizing: border-box !important;\n }\n /* \u2705 v9.3: \u0E41\u0E01\u0E49\u0E40\u0E09\u0E1E\u0E32\u0E30\u0E1B\u0E38\u0E48\u0E21 play \u0E43\u0E2B\u0E0D\u0E48\u0E01\u0E25\u0E32\u0E07\u0E08\u0E2D\u0E02\u0E2D\u0E07 Rumble \u0E44\u0E21\u0E48\u0E22\u0E38\u0E48\u0E07 control bar */\n .premium-rumble-wrapper .premium-rumble-big-play-fixed {\n position: absolute !important;\n left: 50% !important;\n top: 50% !important;\n transform: translate(-50%, -50%) !important;\n width: 96px !important;\n height: 96px !important;\n max-width: 96px !important;\n max-height: 96px !important;\n min-width: 96px !important;\n min-height: 96px !important;\n z-index: 100 !important;\n align-items: center !important;\n justify-content: center !important;\n padding: 0 !important;\n margin: 0 !important;\n overflow: visible !important;\n box-sizing: border-box !important;\n pointer-events: auto !important;\n }\n .premium-rumble-wrapper .premium-rumble-big-play-inner-fixed {\n width: 96px !important;\n height: 96px !important;\n max-width: 96px !important;\n max-height: 96px !important;\n min-width: 96px !important;\n min-height: 96px !important;\n padding: 24px !important;\n margin: 0 !important;\n border-radius: 50% !important;\n box-sizing: border-box !important;\n display: flex !important;\n align-items: center !important;\n justify-content: center !important;\n }\n .premium-rumble-wrapper .premium-rumble-big-play-inner-fixed svg,\n .premium-rumble-wrapper svg.premium-rumble-big-play-svg-fixed {\n width: 48px !important;\n height: 48px !important;\n max-width: 48px !important;\n max-height: 48px !important;\n display: block !important;\n }\n .premium-rumble-wrapper .premium-rumble-title-hidden,\n .premium-rumble-wrapper .premium-rumble-logo-hidden,\n .premium-rumble-wrapper .premium-rumble-autoplay-hidden {\n display: none !important;\n visibility: hidden !important;\n pointer-events: none !important;\n }\n .premium-rumble-peertube-hidden {\n display: none !important;\n }\n ',document.head.appendChild(e)}function xr(e){It();let t=Array.from(e.children).find(n=>{var o;return(o=n.id)==null?void 0:o.startsWith("premium_rumble_")}),r=e.querySelector('[id^="vid_"]');[e,t,r].forEach(n=>{n&&(n.style.width="100%",n.style.height="100%",n.style.maxWidth="100%",n.style.maxHeight="100%",n.style.boxSizing="border-box")}),e.querySelectorAll("iframe, object, embed").forEach(n=>{let i=n;i.style.width="100%",i.style.height="100%",i.style.maxWidth="100%",i.style.maxHeight="100%",i.style.boxSizing="border-box"})}function Ir(e){let t=e.querySelector('[id^="vid_"]')||e,r=t.querySelector(".bigPlayUI.ctp");if(r){r.classList.add("premium-rumble-big-play-fixed"),window.getComputedStyle(r).display!=="none"&&(r.style.display="flex");let o=r.querySelector(".bigPlayUIInner.ctp");o&&o.classList.add("premium-rumble-big-play-inner-fixed");let s=r.querySelector("svg.RumbleSVG-bplay, svg");s&&s.classList.add("premium-rumble-big-play-svg-fixed")}let n=t.querySelector(".touched_overlay_item");if(n){let i=n.querySelector(".play_pause_wrap");i&&(i.style.width="96px",i.style.height="96px",i.style.maxWidth="96px",i.style.maxHeight="96px",i.style.margin="0 18px",i.style.padding="0"),n.querySelectorAll(".play_svg, .pause_svg").forEach(o=>{let s=o;s.style.width="96px",s.style.height="96px",s.style.maxWidth="96px",s.style.maxHeight="96px",s.style.padding="24px",s.style.boxSizing="border-box"})}}function Ar(e){var r,n,i;let t=Array.from(e.querySelectorAll('a[href*="rumble.com/v"], a[href^="//rumble.com/v"]'));for(let o of t){let s=window.getComputedStyle(o);(o.textContent||"").trim().length>0&&s.position==="absolute"&&(s.top==="0px"||((r=o.getAttribute("style"))==null?void 0:r.includes("top: 0px")))&&(s.left==="0px"||((n=o.getAttribute("style"))==null?void 0:n.includes("left: 0px")))&&(s.right==="0px"||((i=o.getAttribute("style"))==null?void 0:i.includes("right: 0px")))&&o.classList.add("premium-rumble-title-hidden")}}function Nr(e){let t=Array.from(e.querySelectorAll('svg.RumbleElm[viewBox="0 0 140 35"], svg.RumbleElm[viewBox="0 0 35 35"]'));for(let r of t){let n=r.outerHTML||"";if(!(n.includes('fill="#85C742"')||n.includes("fill='#85C742'")))continue;(r.closest('div[style*="float: right"], div[title*="Rumble"], a, div')||r).classList.add("premium-rumble-logo-hidden")}}function Ur(e){return e.querySelector('div[title="Autoplay"], [title="Autoplay"]')}function kr(e){if(!e)return;let t=["setAutoplay","setAutoPlay","setAutoplayNext","setAutoPlayNext"];for(let r of t){let n=e[r];if(typeof n=="function")try{let i=n.call(e,!1);i!=null&&i.catch&&i.catch(()=>{})}catch(i){}}}function Hr(e){if(e.dataset.rumbleAutoplayUserGuardAttached==="true")return;e.dataset.rumbleAutoplayUserGuardAttached="true";let t=()=>{let r=Ur(e);if(!r||r.dataset.premiumAutoplayGuardAttached==="true")return;r.dataset.premiumAutoplayGuardAttached="true";let n=()=>{e.dataset.rumbleAutoplayUserTouched="true"};r.addEventListener("pointerdown",n,{passive:!0}),r.addEventListener("mousedown",n,{passive:!0}),r.addEventListener("touchstart",n,{passive:!0}),r.addEventListener("click",n,{passive:!0})};t(),window.setTimeout(t,500),window.setTimeout(t,1500),window.setTimeout(t,3e3)}function Cr(e,t){if(e.dataset.rumbleAutoplayArmed==="true")return;e.dataset.rumbleAutoplayArmed="true",Hr(e);let r=0,n=window.setInterval(()=>{if(r++,!c||c!==t||t.wrapper!==e){window.clearInterval(n);return}if(e.dataset.rumbleAutoplayUserTouched==="true"){window.clearInterval(n);return}kr(t.api),r>=6&&window.clearInterval(n)},700)}function Ke(e){xr(e),Ir(e),Ar(e),Nr(e)}function At(e,t){let r=[];return e.classList.add("premium-rumble-pending"),Array.from(e.children).forEach(n=>{let i=n;i!==t&&(i.classList.contains("premium-rumble-wrapper")||(i.classList.add("premium-rumble-peertube-hidden"),r.push(i)))}),r}function Nt(e){(e||[]).forEach(t=>{var r;t.classList.remove("premium-rumble-peertube-hidden"),(r=t.parentElement)==null||r.classList.remove("premium-rumble-pending")}),document.querySelectorAll(".premium-rumble-pending").forEach(t=>{t.classList.remove("premium-rumble-pending")})}function Ut(e){if(!e||e<=0)return;let t=Dr(e);document.querySelectorAll(".attribute-duration .attribute-value, .attribute.attribute-duration .attribute-value").forEach(r=>{let n=r,i=(c==null?void 0:c.videoUuid)||window.location.href;Fe!==i&&(Re=n.textContent||"",Fe=i),n.textContent=t,n.dataset.rumbleDuration="true"})}function $r(){document.querySelectorAll('.attribute-duration .attribute-value[data-rumble-duration="true"], .attribute.attribute-duration .attribute-value[data-rumble-duration="true"]').forEach(e=>{let t=e;Re!==null&&(t.textContent=Re),delete t.dataset.rumbleDuration}),Re=null,Fe=""}function Dr(e){e=Math.max(0,Math.floor(Number(e)||0));let t=Math.floor(e/3600),r=Math.floor(e%3600/60),n=e%60;return t>0?"".concat(t," \u0E0A\u0E21. ").concat(r," \u0E19\u0E32\u0E17\u0E35 ").concat(n,"sec"):r>0?"".concat(r," \u0E19\u0E32\u0E17\u0E35 ").concat(n,"sec"):"".concat(n,"sec")}function _e(){return/Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent)}function Br(){try{let e=new URL(window.location.href),t=Number(e.searchParams.get("playlistPosition"));return Number.isFinite(t)&&t>0?t:null}catch(e){return null}}function Vr(){return window.location.pathname.includes("/w/p/")}function kt(e){return e?(e.click(),!0):!1}function Fr(){let e=Br();if(!e)return null;let t=e+1,r=Array.from(document.querySelectorAll('a[href*="/w/p/"][href*="playlistPosition="]'));for(let n of r)try{let i=new URL(n.href,window.location.origin);if(Number(i.searchParams.get("playlistPosition"))===t)return n}catch(i){}return null}function qr(){let e=document.querySelector('my-input-switch input[name="autoplay-next-video"], input#autoplay-next-video, input[name="autoplay-next-video"]');if(e)return e.checked===!0;let t=document.querySelector('my-input-switch[inputname="autoplay-next-video"], [role="switch"][name="autoplay-next-video"], [aria-label*="\u0E40\u0E25\u0E48\u0E19\u0E27\u0E34\u0E14\u0E35\u0E42\u0E2D\u0E16\u0E31\u0E14\u0E44\u0E1B"], [aria-label*="autoplay"]');if(!t)return!1;let r=t.getAttribute("aria-checked");return r==="true"?!0:r==="false"?!1:t.classList.contains("active")||t.classList.contains("checked")||t.classList.contains("enabled")}function Or(){let e=["my-recommended-videos",".other-videos",".recommendations","aside"];for(let t of e){let r=document.querySelector(t);if(!r)continue;let n=Array.from(r.querySelectorAll('a[href*="/w/"]:not([href*="/w/p/"])'));for(let i of n)try{let o=new URL(i.href,window.location.origin);if(!o.pathname.includes("/w/")||o.pathname===window.location.pathname)continue;return i}catch(o){}}return null}async function zr(e){if(!(e.nextTriggered||!e.api))try{if(!!await Promise.resolve(e.api.getPaused()))return;let r=Number(await Promise.resolve(e.api.getCurrentTime()))||0,n=Number(await Promise.resolve(e.api.getDuration()))||0;if(!n||n<=0)return;let i=n-r;if(r<=10||i>2)return;e.nextTriggered=!0;try{e.api.pause&&await Promise.resolve(e.api.pause())}catch(s){}try{await Promise.resolve(e.api.setCurrentTime(0))}catch(s){}try{e.api.pause&&await Promise.resolve(e.api.pause())}catch(s){}if(U(e.oldPlayer,!0),await Gr(e,Math.floor(n)),e.canSaveProgress=!1,Vr()){let s=Fr();s&&kt(s);return}if(!qr())return;let o=Or();o&&kt(o)}catch(t){console.warn("\u26A0\uFE0F [Premium Rumble] auto-next failed:",t)}}function Wr(e){e.autoNextTimer&&window.clearInterval(e.autoNextTimer),e.autoNextTimer=window.setInterval(()=>{zr(e).catch(()=>{})},500)}function jr(e){e.peerTubeStopTimer&&window.clearInterval(e.peerTubeStopTimer);let t=0;e.peerTubeStopTimer=window.setInterval(()=>{if(t++,!c||c!==e||t>45){e.peerTubeStopTimer&&window.clearInterval(e.peerTubeStopTimer),e.peerTubeStopTimer=void 0;return}U(e.oldPlayer,!0)},700)}async function Gr(e,t){if(!e.canSaveProgress)return;let r=Math.max(0,Math.floor(Number(t)||0));if(!(!r||r<=0))try{await z.saveRumbleProgress({videoUuid:e.videoUuid,rumbleVideoId:e.rumbleVideoId,positionSeconds:0,durationSeconds:r,paused:!0,completed:!1}),e.lastSavedPosition=0}catch(n){console.warn("\u26A0\uFE0F [Premium Rumble] reset progress to start failed:",n)}}function Kr(e){window.Rumble||function(t,r,n,i,o,s){t._Rumble=i,t[i]||(t[i]=function(){var a;(t[i]._=t[i]._||[]).push(arguments),t[i]._.length===1&&(o=r.createElement(n),s=r.getElementsByTagName(n)[0],o.async=!0,o.src="https://rumble.com/embedJS/u"+e+(arguments[1].video?"."+arguments[1].video:"")+"/?url="+encodeURIComponent(location.href)+"&args="+encodeURIComponent(JSON.stringify([].slice.apply(arguments))),(a=s.parentNode)==null||a.insertBefore(o,s))})}(window,document,"script","Rumble")}function Ht(){It();let e=document.createElement("div");return e.className="premium-rumble-wrapper",e}async function Ze(e){if(!e.api)return null;try{let t=Math.floor(Number(await Promise.resolve(e.api.getCurrentTime()))||0),r=Math.round(Number(await Promise.resolve(e.api.getDuration()))||0),n=!!await Promise.resolve(e.api.getPaused());return!r||r<=0||t<0?null:{positionSeconds:t,durationSeconds:r,paused:n}}catch(t){return console.warn("\u26A0\uFE0F [Premium Rumble] \u0E2D\u0E48\u0E32\u0E19\u0E40\u0E27\u0E25\u0E32 Rumble \u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08:",t),null}}async function x(e=!1){let t=c;if(!(t!=null&&t.api))return;let r=await Ze(t);if(!r||r.positionSeconds<=2&&t.lastSavedPosition>30||t.nextTriggered&&r.positionSeconds<=5)return;let n=Math.abs(r.positionSeconds-t.lastSavedPosition);if(!(!e&&n<10&&!r.paused)){if(t.canSaveProgress){try{let i=await z.saveRumbleProgress({videoUuid:t.videoUuid,rumbleVideoId:t.rumbleVideoId,positionSeconds:r.positionSeconds,durationSeconds:r.durationSeconds,paused:r.paused});i&&i.success!==!0&&(i.error||i.status===401||i.status===403)?(t.canSaveProgress=!1,console.warn("\u26A0\uFE0F [Premium Rumble] \u0E1B\u0E34\u0E14\u0E01\u0E32\u0E23\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01 progress \u0E0A\u0E31\u0E48\u0E27\u0E04\u0E23\u0E32\u0E27 \u0E40\u0E1E\u0E23\u0E32\u0E30 backend \u0E44\u0E21\u0E48\u0E2D\u0E19\u0E38\u0E0D\u0E32\u0E15:",i)):(t.lastSavedPosition=r.positionSeconds,Rt(t))}catch(i){t.canSaveProgress=!1,console.warn("\u26A0\uFE0F [Premium Rumble] \u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01 progress \u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08 \u0E1B\u0E34\u0E14\u0E01\u0E32\u0E23\u0E22\u0E34\u0E07\u0E0B\u0E49\u0E33\u0E0A\u0E31\u0E48\u0E27\u0E04\u0E23\u0E32\u0E27:",i)}return}u.isLoggedIn()||Et(t,r.positionSeconds,r.durationSeconds)}}async function Zr(e){if(!e.api)return;let t=await Ze(e);if(!(!t||t.durationSeconds-t.positionSeconds<=2)){if(e.canSaveProgress){try{let n=await z.saveRumbleProgress({videoUuid:e.videoUuid,rumbleVideoId:e.rumbleVideoId,positionSeconds:t.positionSeconds,durationSeconds:t.durationSeconds,paused:!0,completed:!1});n&&n.success!==!0&&(n.error||n.status===401||n.status===403)?e.canSaveProgress=!1:(e.lastSavedPosition=t.positionSeconds,Rt(e))}catch(n){e.canSaveProgress=!1,console.warn("\u26A0\uFE0F [Premium Rumble] \u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01 progress \u0E01\u0E48\u0E2D\u0E19\u0E1B\u0E34\u0E14\u0E1E\u0E37\u0E49\u0E19\u0E2B\u0E25\u0E31\u0E07\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08:",n)}return}u.isLoggedIn()||Et(e,t.positionSeconds,t.durationSeconds)}}async function Jr(e){let t=await Ze(e);if(!(!t||!t.durationSeconds)){Ut(t.durationSeconds);try{await z.saveRumbleDuration({videoUuid:e.videoUuid,rumbleVideoId:e.rumbleVideoId,durationSeconds:t.durationSeconds})}catch(r){}}}async function Xr(e,t,r){let n=Math.max(0,Math.floor(Number(t)||0));for(let i=0;i<12;i++){try{let o=Number(await Promise.resolve(e.getDuration()))||0;n>0&&await Promise.resolve(e.setCurrentTime(n));let s=Number(await Promise.resolve(e.getCurrentTime()))||0;if(n<=0||Math.abs(s-n)<=3||o>0&&i>=3){r&&e.play&&setTimeout(()=>{var d;return Promise.resolve((d=e.play)==null?void 0:d.call(e)).catch(()=>{})},250);return}}catch(o){}await new Promise(o=>setTimeout(o,450))}r&&e.play&&Promise.resolve(e.play()).catch(()=>{})}function Qr(e){e.timer&&window.clearInterval(e.timer),e.timer=window.setInterval(()=>{x(!1)},2e4),Wr(e)}function Ct(e,t){var n,i,o;try{(n=t==null?void 0:t.pause)==null||n.call(t)}catch(s){}try{(i=t==null?void 0:t.mute)==null||i.call(t)}catch(s){}try{(o=t==null?void 0:t.setVolume)==null||o.call(t,0)}catch(s){}let r=[];e&&r.push(e),document.querySelectorAll(".premium-rumble-wrapper").forEach(s=>{r.includes(s)||r.push(s)}),r.forEach(s=>{s.querySelectorAll("video, audio").forEach(a=>{let d=a;try{d.pause()}catch(p){}try{d.removeAttribute("src")}catch(p){}try{d.load()}catch(p){}}),s.querySelectorAll("iframe, object, embed").forEach(a=>{let d=a;try{d.src="about:blank"}catch(p){}try{d.setAttribute("src","about:blank")}catch(p){}try{d.setAttribute("srcdoc","<!doctype html><html><body></body></html>")}catch(p){}try{d.remove()}catch(p){}});try{s.innerHTML=""}catch(a){}})}function we(){Q="",ce="",me=0}let xe=!1,W=null;function Yr(e){[0,120,350,900,1800].forEach(t=>{window.setTimeout(()=>{var r,n,i;try{(r=e==null?void 0:e.pause)==null||r.call(e)}catch(o){}try{(n=e==null?void 0:e.mute)==null||n.call(e)}catch(o){}try{(i=e==null?void 0:e.setVolume)==null||i.call(e,0)}catch(o){}},t)})}function Je(){U(void 0,!0)}function $t(e){if(!w()||c!=null&&c.api)return;W&&(window.clearTimeout(W),W=null);let t=L;we(),be(),Je(),W=window.setTimeout(()=>{t===L&&w()&&(c!=null&&c.api||(we(),ee(50,t)))},80),window.setTimeout(()=>{t===L&&w()&&(c!=null&&c.api||(we(),ee(50,t)))},1300),window.setTimeout(()=>{c!=null&&c.api||k(),W&&(window.clearTimeout(W),W=null)},4200)}function en(){let e=c;if(e!=null&&e.isMember)return;let t=navigator.mediaSession;if(t!=null&&t.setActionHandler){try{t.setActionHandler("play",()=>{var n,i;let r=c;if(!(r!=null&&r.isMember)){if(ze()&&w()){try{(i=(n=r==null?void 0:r.api)==null?void 0:n.play)==null||i.call(n)}catch(o){}return}_e()&&(r!=null&&r.api&&(!w()||document.hidden)?$e().catch(()=>{}):xe&&w()&&ze()&&(Je(),$t("media-session-play")))}})}catch(r){}try{t.setActionHandler("pause",()=>{var n,i;let r=c;if(!(r!=null&&r.isMember)){try{(i=(n=r==null?void 0:r.api)==null?void 0:n.pause)==null||i.call(n)}catch(o){}x(!0).catch(()=>{})}})}catch(r){}try{t.setActionHandler("seekto",r=>{var o,s;let n=c;if(!(n!=null&&n.api)||n.isMember)return;if(_e()&&(!w()||document.hidden)){try{(s=(o=n.api).pause)==null||s.call(o)}catch(a){}return}let i=Number(r==null?void 0:r.seekTime);Number.isFinite(i)&&Promise.resolve(n.api.setCurrentTime(i)).catch(()=>{})})}catch(r){}}}async function Y(e=!0){k(),ve(!0),c&&(e&&!c.nextTriggered&&await x(!0),c.timer&&window.clearInterval(c.timer),c.autoNextTimer&&window.clearInterval(c.autoNextTimer),c.peerTubeStopTimer&&window.clearInterval(c.peerTubeStopTimer),Ct(c.wrapper,c.api),c.wrapper&&c.wrapper.remove(),Nt(c.hiddenPeerTubeChildren),$r(),c.oldPlayer&&(c.oldPlayer.style.display=""),Lr(c.oldPlayer),c=null,we())}async function tn(e=L){let t=++qe,r=fe(),n=window.location.pathname,i=()=>!he(e,r,t);if(!n.startsWith("/w/")){k(),await Y();return}let o=await Lt();if(i())return;if(!o){Ge()&&be(),n.startsWith("/w/")&&me<12&&(me++,ee(500,e));return}if(me=0,i())return;let s="".concat(window.location.href,"::").concat(o);if(Q===s||ce===s)return;ce=s,_r(o);let a;try{a=await z.getRumblePlaybackInfo(o)}catch(y){console.warn("\u26A0\uFE0F [Premium Rumble] \u0E42\u0E2B\u0E25\u0E14 playback-info \u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08:",y);return}if(i()||!(a!=null&&a.success))return;if(a.mode==="peertube"){sessionStorage.removeItem(ye(o)),ve(!0),k(),await Y(),Q=s;return}if(a.mode==="replacement"||a.mode==="locked"){sessionStorage.removeItem(ye(o)),ve(!0),k(),await Y(),Q=s;return}if(a.mode!=="rumble"||!a.rumbleVideoId){ve(!0);return}sessionStorage.setItem(ye(o),"true");let d=je();if(!d){Q="",ce="";return}if(await Y(!1),i())return;ve(!1),Q=s,be(),U(d,!0);let p=Ht(),g="premium_rumble_".concat(a.rumbleVideoId,"_").concat(Date.now());p.innerHTML='\n <div class="premium-rumble-loading-placeholder">\u0E01\u0E33\u0E25\u0E31\u0E07\u0E42\u0E2B\u0E25\u0E14\u0E40\u0E04\u0E23\u0E37\u0E48\u0E2D\u0E07\u0E40\u0E25\u0E48\u0E19</div>\n <div id="'.concat(g,'" style="width:100%;height:100%;max-width:100%;display:none;"></div>\n '),d.insertBefore(p,d.firstChild);let v=At(d,p);c={videoUuid:a.videoUuid||o,rumbleVideoId:a.rumbleVideoId,isMember:a.isMember===!0,canSaveProgress:u.isLoggedIn(),oldPlayer:d,hiddenPeerTubeChildren:v,wrapper:p,lastSavedPosition:(()=>{let y=new URLSearchParams(window.location.search),h=Number(y.get("rumbleStart")||y.get("startSeconds")||NaN);return Number.isFinite(h)&&h>0?Math.floor(h):Number(a.startSeconds||0)})(),nextTriggered:!1},c&&jr(c),Ut(Number(a.durationSeconds||0));let P=a.pubId||"4pc838";Kr(P),!(i()||!c||c.wrapper!==p)&&window.Rumble("play",{video:a.rumbleVideoId,div:g,autoplay:!1,api:async function(y){if(i()||!c||c.wrapper!==p||c.rumbleVideoId!==a.rumbleVideoId)return;let h=c;h.api=y,h.isMember||en(),xe=!1,U(h.oldPlayer,!0),Cr(p,h);let T=new URLSearchParams(window.location.search),I=Number(T.get("rumbleStart")||T.get("startSeconds")||NaN),j=T.get("rumbleAutoplay")==="1";u.isLoggedIn()&&Mt([a.videoUuid||o,o,a.rumbleVideoId]);let A=u.isLoggedIn()?null:St(a.videoUuid||o)||St(o),G=Math.floor(Number.isFinite(I)&&I>0?I:Number(a.startSeconds||(A==null?void 0:A.positionSeconds)||0));setTimeout(()=>{!he(e,r,t)||c!==h||Xr(y,G,j).catch(_=>{console.warn("\u26A0\uFE0F [Premium Rumble] seek/resume \u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08:",_)})},400);try{y.setVolume&&await Promise.resolve(y.setVolume(1))}catch(_){}try{y.unmute&&await Promise.resolve(y.unmute())}catch(_){}let Se=p.querySelector(".premium-rumble-loading-placeholder"),oe=p.querySelector("#".concat(g));Se&&Se.remove(),oe&&(oe.style.display="block"),p.dataset.rumbleLoading="false",k(),!(i()||c!==h)&&(Ke(p),setTimeout(()=>{!he(e,r,t)||c!==h||(Ke(p),U(h.oldPlayer,!0))},800),setTimeout(()=>{!he(e,r,t)||c!==h||(Ke(p),U(h.oldPlayer,!0))},2e3),Qr(h),setTimeout(()=>{!he(e,r,t)||c!==h||(Jr(h),x(!0))},2500))}})}function ee(e=250,t=L){t===L&&(clearTimeout(le),le=setTimeout(()=>{t===L&&tn(t).catch(r=>{console.warn("\u26A0\uFE0F [Premium Rumble] mount error:",r)})},e))}let Ie=null,Pe=null,Xe=!1,te=!1,re="",Dt=!1,Qe="",ne=null,Ye=null,Bt=null,Vt=0,et=!1,Ft=new WeakSet,Ae=new Map,rn="premium_native_peertube_resume_v13_",tt="premium_native_peertube_resume_pending_v13",rt=7*24*60*60*1e3,nn=5e3;function qt(e){var i,o,s,a,d,p,g,v,P,y,h,T,I,j,A,G;let t=Number((a=(s=(i=e==null?void 0:e.id)!=null?i:e==null?void 0:e.userId)!=null?s:(o=e==null?void 0:e.User)==null?void 0:o.id)!=null?a:0),r=String((h=(y=(v=(p=e==null?void 0:e.username)!=null?p:(d=e==null?void 0:e.User)==null?void 0:d.username)!=null?v:(g=e==null?void 0:e.Account)==null?void 0:g.name)!=null?y:(P=e==null?void 0:e.account)==null?void 0:P.name)!=null?h:"").toLowerCase(),n=String((G=(A=(j=(T=e==null?void 0:e.Role)==null?void 0:T.name)!=null?j:(I=e==null?void 0:e.role)==null?void 0:I.name)!=null?A:e==null?void 0:e.role)!=null?G:"").toLowerCase();return t===1||r==="root"||n==="root"}function H(){var e;if(!u.isLoggedIn())return!1;try{let t=(e=u.getUser)==null?void 0:e.call(u);if(!t)return Ie;if(t.isPremium===!0||qt(t))return!0;if(t.isPremium===!1)return!1}catch(t){}return Ie}async function nt(){let e=H();return e!==null?e:Pe||(Pe=(async()=>{if(!u.isLoggedIn())return Ie=!1,!1;try{let t=await z.getMe(),r=(t==null?void 0:t.isPremium)===!0||qt(t);return Ie=r,r}catch(t){return!0}finally{Pe=null}})(),Pe)}window.setTimeout(()=>{nt().catch(()=>{})},1200);function Te(){try{let e=ge();if(e)return"/w/".concat(e);if(window.location.pathname.startsWith("/w/p/")){let t=window.location.pathname.match(/^\/w\/p\/([a-zA-Z0-9-]+)/),r=t==null?void 0:t[1],n=new URLSearchParams(window.location.search).get("playlistPosition")||"1";if(r)return"/w/p/".concat(r,"?playlistPosition=").concat(n)}}catch(e){}return fe()}function it(e){return"".concat(rn).concat(encodeURIComponent(e))}function Ot(e,t,r=!0){try{let n=String((e==null?void 0:e.routeSignature)||""),i=Te(),o=Math.max(0,Math.floor(Number((e==null?void 0:e.positionSeconds)||0))),s=Math.max(0,Math.floor(Number((e==null?void 0:e.durationSeconds)||0))),a=Math.max(0,Math.floor(Number((e==null?void 0:e.updatedAt)||0)));return!n||r&&n!==i||!o||o<2||!a||Date.now()-a>t?null:{routeSignature:n,videoUuid:e!=null&&e.videoUuid?String(e.videoUuid):void 0,positionSeconds:o,durationSeconds:s,updatedAt:a,wasPaused:!!(e!=null&&e.wasPaused),muted:!!(e!=null&&e.muted),defaultMuted:!!(e!=null&&e.defaultMuted),volume:Number.isFinite(e==null?void 0:e.volume)?Number(e.volume):1,playbackRate:Number.isFinite(e==null?void 0:e.playbackRate)?Number(e.playbackRate):1}}catch(n){return null}}function zt(e){try{let t=localStorage.getItem(e);if(t)return JSON.parse(t)}catch(t){}return null}function Wt(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(r){}}function jt(e){try{localStorage.removeItem(e)}catch(t){}try{sessionStorage.removeItem(e)}catch(t){}}function Gt(e=Te()){jt(it(e)),Ae.delete(e)}function ie(){jt(tt),Qe="",ne&&(window.clearTimeout(ne),ne=null),Ye&&(window.clearInterval(Ye),Ye=null)}function Kt(e,t){let r=zt(it(e));return r?Ot(r,t,!1):null}function on(e=!0){let t=zt(tt),r=t?Ot(t,rt,!0):null;return!r&&e&&ie(),r}function Zt(e,t,r,n,i,o,s,a,d){let p=Math.max(0,Math.floor(Number(r||0)));return!p||p<2?null:{routeSignature:e,videoUuid:t||void 0,positionSeconds:p,durationSeconds:Math.max(0,Math.floor(Number(n||0))),updatedAt:Date.now(),wasPaused:!!i,muted:!!o,defaultMuted:!!s,volume:Number.isFinite(a)?a:1,playbackRate:Number.isFinite(d)?d:1}}function an(e,t){Ae.set(e.routeSignature,e),Wt(it(e.routeSignature),e),t&&Wt(tt,e)}function ot(){let e=ge();if(e)return e;try{if(window.location.pathname.startsWith("/w/p/")){let t=window.location.pathname.match(/^\/w\/p\/([a-zA-Z0-9-]+)/),r=t==null?void 0:t[1],n=new URLSearchParams(window.location.search).get("playlistPosition")||"1";if(r){let i=sessionStorage.getItem(We(r,n));if(i)return i}}}catch(t){}try{let t=document.querySelector('#videojs-wrapper .vjs-peertube-link[href*="/w/"], .vjs-peertube-link[href*="/w/"]'),n=((t==null?void 0:t.href)||"").match(/\/w\/(?!p\/)([a-zA-Z0-9-]+)/);if(n!=null&&n[1])return n[1]}catch(t){}}async function sn(e){if(e!=null&&e.videoUuid)return e.videoUuid;let t=ot();if(t)return t;try{return await Lt()||void 0}catch(r){return}}function Ne(){return Array.from(document.querySelectorAll("my-video-watch video, my-video-watch audio, #videojs-wrapper video, #videojs-wrapper audio")).filter(t=>!(!t||t.closest(".premium-rumble-wrapper")))}function C(e){try{let t=e.closest(".video-js"),r=t==null?void 0:t.id,n=window.videojs;return!r||typeof n!="function"?null:n(r)}catch(t){return null}}function $(e){let t=C(e);try{let r=t&&typeof t.tech=="function"?t.tech(!0):null,n=r&&typeof r.el=="function"?r.el():null;if(n&&(n instanceof HTMLVideoElement||n instanceof HTMLAudioElement))return n}catch(r){}return null}function at(e){let t=[],r=C(e),n=$(e);try{if(r&&typeof r.currentTime=="function"){let i=Number(r.currentTime());Number.isFinite(i)&&t.push(i)}}catch(i){}try{let i=Number(e.currentTime);Number.isFinite(i)&&t.push(i)}catch(i){}try{let i=Number(n==null?void 0:n.currentTime);Number.isFinite(i)&&t.push(i)}catch(i){}return Math.max(0,Math.floor(Math.max(0,...t)))}function Jt(e){let t=[],r=C(e),n=$(e);try{if(r&&typeof r.duration=="function"){let i=Number(r.duration());Number.isFinite(i)&&i>0&&t.push(i)}}catch(i){}try{let i=Number(e.duration);Number.isFinite(i)&&i>0&&t.push(i)}catch(i){}try{let i=Number(n==null?void 0:n.duration);Number.isFinite(i)&&i>0&&t.push(i)}catch(i){}return Math.max(0,Math.floor(Math.max(0,...t)))}function un(e){let t=C(e),r=$(e);try{if(t&&typeof t.paused=="function")return!!t.paused()}catch(n){}try{if(r)return!!r.paused}catch(n){}return!!e.paused}function st(e){let r=$(e)||e;return{media:e,currentTime:at(e),duration:Jt(e),paused:un(e),muted:!!r.muted,defaultMuted:!!r.defaultMuted,volume:Number.isFinite(r.volume)?r.volume:1,playbackRate:Number.isFinite(r.playbackRate)?r.playbackRate:1}}function Xt(e,t,r,n=!1){let i=Kt(t,rt),o=Ae.get(t)||null,s=Math.max(0,Math.floor(Number(e.currentTime||0))),a=Math.max(0,Math.floor(Number((o==null?void 0:o.positionSeconds)||0))),d=Math.max(0,Math.floor(Number((i==null?void 0:i.positionSeconds)||0))),p=a||d,g=p;s>=2&&(g=s<10&&p>=10?p:s);let v=ot()||(o==null?void 0:o.videoUuid)||(i==null?void 0:i.videoUuid),P=Zt(t,v,g,e.duration||(o==null?void 0:o.durationSeconds)||(i==null?void 0:i.durationSeconds)||0,e.paused,e.muted,e.defaultMuted,e.volume,e.playbackRate);return P?(an(P,r),Qt(P,n,!1).catch(()=>{}),P):null}function Ue(e,t=!1){let r=Te(),n=st(e);return Xt(n,r,!1,t)}async function Qt(e,t=!1,r=!1){if(!u.isLoggedIn()||!r&&(!(e!=null&&e.positionSeconds)||e.positionSeconds<2))return;let n=H();if(n===!0||n===null&&await nt())return;if(!t){let o=Date.now();if(et||o-Vt<nn)return}let i=await sn(e);if(i){et=!0,Vt=Date.now();try{await z.saveNativePeerTubeProgress({videoUuid:i,positionSeconds:r?0:e.positionSeconds,durationSeconds:e.durationSeconds||0,paused:r?!0:e.wasPaused,completed:r,routeSignature:r?"":e.routeSignature})}catch(o){console.warn("\u26A0\uFE0F [Premium Native] save native progress failed:",o)}finally{et=!1}}}function ut(e){try{if(e.ended)return!0}catch(n){}let t=Jt(e),r=at(e);return t>0&&r>0&&t-r<=1.5&&r/t>=.995}function ke(e){if(!w()||c!=null&&c.api||H()===!0)return;let t=Te(),r=Ae.get(t)||Kt(t,rt),n=st(e),i=Zt(t,ot()||(r==null?void 0:r.videoUuid),(r==null?void 0:r.positionSeconds)||n.currentTime||2,n.duration||(r==null?void 0:r.durationSeconds)||0,!0,n.muted,n.defaultMuted,n.volume,n.playbackRate);ie(),Gt(t),i&&Qt(i,!0,!0).catch(()=>{})}function ln(e){let t=C(e),r=$(e);try{t&&typeof t.pause=="function"&&t.pause()}catch(n){}try{e.pause()}catch(n){}try{r==null||r.pause()}catch(n){}try{e.autoplay=!1}catch(n){}try{t&&typeof t.autoplay=="function"&&t.autoplay(!1)}catch(n){}}function cn(e,t){let r=C(e),n=$(e),i=Math.max(0,Math.floor(Number(t||0)));if(!(!i||i<2)){try{if(r&&typeof r.currentTime=="function"){r.currentTime(i);return}}catch(o){}try{e.currentTime=i}catch(o){}try{n&&n!==e&&(n.currentTime=i)}catch(o){}}}function mn(e,t){let r=C(e),n=$(e),i=!!t.muted,o=Number.isFinite(t.volume)?t.volume:1,s=Math.max(.01,Math.min(1,o||1));if([e,n].forEach(a=>{if(a){if(!i){try{a.defaultMuted=!1}catch(d){}try{a.muted=!1}catch(d){}try{a.volume=s}catch(d){}}try{a.playbackRate=t.playbackRate||1}catch(d){}}}),r){if(!i){try{typeof r.muted=="function"&&r.muted(!1)}catch(a){}try{typeof r.volume=="function"&&r.volume(s)}catch(a){}}try{typeof r.playbackRate=="function"&&r.playbackRate(t.playbackRate||1)}catch(a){}}}function dn(e){if(Ft.has(e))return;Ft.add(e);let t=()=>{if(w()&&!(c!=null&&c.api)&&H()!==!0){if(ut(e)){ke(e);return}Ue(e,!1)}},r=()=>{if(w()&&!(c!=null&&c.api)&&H()!==!0){if(ut(e)){ke(e);return}Ue(e,!0)}},n=()=>{ke(e)};try{e.addEventListener("timeupdate",t,{passive:!0})}catch(i){}try{e.addEventListener("pause",r,{passive:!0})}catch(i){}try{e.addEventListener("seeking",t,{passive:!0})}catch(i){}try{e.addEventListener("seeked",r,{passive:!0})}catch(i){}try{e.addEventListener("playing",r,{passive:!0})}catch(i){}try{e.addEventListener("ratechange",t,{passive:!0})}catch(i){}try{e.addEventListener("ended",n,{passive:!0})}catch(i){}}function pn(){Bt||(Bt=window.setInterval(()=>{w()&&(c!=null&&c.api||H()!==!0&&Ne().forEach(e=>{dn(e),Ue(e,!1)}))},750))}function fn(e,t){if(!t||!document.documentElement.contains(t))return;let r=!1,n=null,i=()=>{try{t.removeEventListener("loadedmetadata",o)}catch(s){}try{t.removeEventListener("loadeddata",o)}catch(s){}try{t.removeEventListener("canplay",o)}catch(s){}n&&(window.clearTimeout(n),n=null)},o=()=>{if(r)return;if(r=!0,i(),!document.documentElement.contains(t)){ie();return}let s=at(t);Math.abs(s-e.positionSeconds)>1.2&&cn(t,e.positionSeconds),mn(t,e),e.wasPaused&&ln(t),ie()};if(t.readyState>=1)o();else{try{t.addEventListener("loadedmetadata",o,{once:!0})}catch(s){}try{t.addEventListener("loadeddata",o,{once:!0})}catch(s){}try{t.addEventListener("canplay",o,{once:!0})}catch(s){}n=window.setTimeout(o,2500)}}function He(){let e=on();if(!e)return;if(!w()){ie();return}if(c!=null&&c.api)return;if(H()===!0){ie(),Gt(e.routeSignature);return}let r=Ne();if(r.length===0){ne&&window.clearTimeout(ne),ne=window.setTimeout(He,300);return}Qe!==e.routeSignature&&(Qe=e.routeSignature,r.forEach(n=>fn(e,n)))}function hn(){window.setTimeout(He,150),window.setTimeout(He,700),window.setTimeout(He,1800)}function yn(e,t){if(!e||e.closest(".premium-rumble-wrapper"))return;let r=C(e),n=$(e);try{r&&typeof r.pause=="function"&&r.pause()}catch(i){}if(t)try{r&&typeof r.autoplay=="function"&&r.autoplay(!1)}catch(i){}try{r&&typeof r.src=="function"&&r.src([])}catch(i){}try{r&&typeof r.reset=="function"&&r.reset()}catch(i){}[e,n].forEach(i=>{var o,s;if(!(!i||(o=i.closest)!=null&&o.call(i,".premium-rumble-wrapper"))){try{i.pause()}catch(a){}if(t)try{i.autoplay=!1}catch(a){}try{i.removeAttribute("src")}catch(a){}try{Array.from(((s=i.querySelectorAll)==null?void 0:s.call(i,"source"))||[]).forEach(a=>{try{a.removeAttribute("src")}catch(d){}})}catch(a){}try{i.load()}catch(a){}}});try{"mediaSession"in navigator&&(navigator.mediaSession.playbackState="none")}catch(i){}}function gn(){let e=fe(),t=Te(),r=0;Ne().forEach(n=>{let i=st(n);Xt(i,t,!0,!0)&&r++,yn(n,i.paused)}),te=r>0,re=te?e:""}function bn(){if(!te||Dt||document.hidden)return;let e=fe();if(!w()||!re||e!==re){te=!1,re="";return}if(c!=null&&c.api){te=!1,re="";return}Dt=!0,te=!1,re="";try{"mediaSession"in navigator&&(navigator.mediaSession.playbackState="none")}catch(t){}window.location.reload()}async function vn(){return!_e()||!w()||c!=null&&c.api?!1:!await nt()}async function lt(){if(!Xe&&await vn()&&document.hidden){Xe=!0;try{gn()}finally{window.setTimeout(()=>{Xe=!1},900)}}}function ct(){document.hidden||bn()}pn(),hn();try{window.addEventListener("pagehide",()=>{w()&&(c!=null&&c.api||H()!==!0&&Ne().forEach(e=>{ut(e)?ke(e):Ue(e,!0)}))})}catch(e){}let mt=!1;function Ce(e){return!(!(e!=null&&e.api)||e.isMember||!_e()||w()&&ze())}async function $e(){var r,n,i;let e=c;if(!Ce(e)||!(e!=null&&e.api)||mt)return;mt=!0,xe=!0;let t=e.api;try{await Zr(e);try{await Promise.resolve((r=t.pause)==null?void 0:r.call(t))}catch(o){}try{await Promise.resolve((n=t.mute)==null?void 0:n.call(t))}catch(o){}try{await Promise.resolve((i=t.setVolume)==null?void 0:i.call(t,0))}catch(o){}Yr(t),Ct(e.wrapper,t),await Y(!1),we(),Je()}finally{window.setTimeout(()=>{mt=!1},900)}}function dt(e){xe&&(document.hidden||window.location.pathname.startsWith("/w/")&&$t(e))}document.addEventListener("visibilitychange",()=>{let e=c;if(document.hidden){if(e!=null&&e.api&&e.isMember){x(!0).catch(()=>{});return}if(Ce(e)){$e().catch(()=>{});return}if(!(e!=null&&e.api)){lt().catch(()=>{});return}e!=null&&e.api&&x(!0);return}if(c!=null&&c.api){x(!0);return}dt("visibilitychange-visible"),ct()}),window.addEventListener("pageshow",()=>{dt("pageshow"),ct()}),window.addEventListener("focus",()=>{dt("focus"),ct()}),window.addEventListener("pagehide",()=>{let e=c;if(e!=null&&e.api&&e.isMember){x(!0).catch(()=>{});return}if(Ce(e)){$e().catch(()=>{});return}if(!(e!=null&&e.api)){lt().catch(()=>{});return}e!=null&&e.api&&x(!0)});try{document.addEventListener("freeze",()=>{let e=c;if(e!=null&&e.api&&e.isMember){x(!0).catch(()=>{});return}if(Ce(e)){$e().catch(()=>{});return}lt().catch(()=>{})})}catch(e){}let pt=window.location.href;function De(e=!1){if(!e&&window.location.href===pt)return;let t=Pr();pt=window.location.href,ce="",me=0,ir(),Y(!1).finally(()=>{t===L&&(Ge()&&be(),ee(80,t))})}let wn=history.pushState;history.pushState=function(...e){let t=wn.apply(this,e);return setTimeout(De,50),t};let Pn=history.replaceState;history.replaceState=function(...e){let t=Pn.apply(this,e);return setTimeout(De,50),t},window.addEventListener("popstate",()=>setTimeout(De,50)),new MutationObserver(e=>{e.length>0&&e.every(r=>{var i;let n=r.target;return!!n&&!!((i=n.closest)!=null&&i.call(n,".premium-rumble-wrapper"))})||(window.location.href!==pt&&De(!1),clearTimeout(window.badgeTimeout),window.badgeTimeout=setTimeout(()=>{X(),ue()},450))}).observe(document.body,{childList:!0,subtree:!0});let ft=0,Tn=setInterval(()=>{X(),ue(),ft<6&&ee(700),ft++,ft>=10&&clearInterval(Tn)},700);Ge()&&be(),ee(150),setTimeout(ue,500)}export{Jn as register};
@@ -1 +1 @@
1
- var V=Object.defineProperty,$=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var O=(t,e,n)=>e in t?V(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,w=(t,e)=>{for(var n in e||(e={}))z.call(e,n)&&O(t,n,e[n]);if(U)for(var n of U(e))J.call(e,n)&&O(t,n,e[n]);return t},C=(t,e)=>$(t,F(e));var N="enable-plugin";var H="stripe-customer-portal-url";var D={name:"peertube-plugin-premium-members",description:"peertube-plugin-premium-members",version:"3.2.0",author:"Vee",bugs:"",clientScripts:[{script:"dist/client/my-account/index.js",scopes:["my-account"]},{script:"dist/client/common.js",scopes:["common"]},{script:"dist/client/video-edit.js",scopes:["video-edit"]},{script:"dist/client/admin-manage.js",scopes:["common"]}],css:["dist/assets/style.css"],engine:{peertube:">=6.0.0"},homepage:"",keywords:["peertube","plugin"],library:"./dist/server/server/main.js",scripts:{clean:"rm -rf dist/*",prepare:"npm run build","build:client":"node ./scripts/build.cjs","build:server":"tsc --build server/tsconfig.json","build:styles":"npx --yes sass --no-source-map assets:dist/assets",build:"npm-run-all -s clean check:client:tsc -p build:server build:client build:styles","check:client:tsc":"npx tsc --p client/tsconfig.json --noEmit","lint:script":"npx eslint .",test:"npm-run-all -p lint:script test:unit","test:unit":"TS_NODE_PROJECT=server/tsconfig.test.json mocha server/*.spec.ts","test:e2e":"cd demo && npm ci && npm test"},staticDirs:{images:"public/images"},translations:{"sv-SE":"./languages/sv.json","th-TH":"./languages/th.json",th:"./languages/th.json"},devDependencies:{"@tsconfig/node16":"^16.0.0","@types/mocha":"^10.0.8","@typescript-eslint/eslint-plugin":"^8.9.0","@typescript-eslint/parser":"^8.9.0",esbuild:"^0.24.0",eslint:"^9.12.0","eslint-config-love":"^87.0.0",globals:"^15.3.0",mocha:"^10.7.3","npm-run-all":"^4.1.5",tsx:"^4.19.1",typescript:"^5.4.3"},dependencies:{"@peertube/peertube-types":"^6.3.0","@types/gtag.js":"^0.0.20","@types/sequelize":"^4.28.20",express:"^4.19.2","short-uuid":"^5.2.0",stripe:"^18.1.0"}};var f=class{constructor(e){this.pluginBasePath="/plugins/".concat(D.name.replace("peertube-plugin-",""),"/router");this.getAuthHeader=e||(()=>{})}async get(e){return fetch(e,{method:"GET",headers:this.getAuthHeader(),credentials:"include"}).then(async n=>n.json())}async patch(e,n){await fetch(e,{method:"PATCH",headers:C(w({},this.getAuthHeader()),{"Content-Type":"application/json"}),credentials:"include",body:JSON.stringify(n)})}async post(e,n){return fetch(e,{method:"POST",headers:C(w({},this.getAuthHeader()),{"Content-Type":"application/json"}),credentials:"include",body:JSON.stringify(n)}).then(async o=>o.json())}async delete(e){return fetch(e,{method:"DELETE",headers:this.getAuthHeader(),credentials:"include"}).then(async n=>n.json())}async getMe(){return this.get("/api/v1/users/me")}async getPrices(){return this.get(this.pluginBasePath+"/price")}async getSubscription(){return this.get(this.pluginBasePath+"/subscription")}async updateSubscription(e){return this.patch(this.pluginBasePath+"/subscription",e)}async createCheckout({allowPromotionCodes:e,couponId:n,priceId:o,paymentMode:s,paymentMethod:r}){return this.post(this.pluginBasePath+"/checkout",{allowPromotionCodes:e,couponId:n,priceId:o,paymentMode:s,paymentMethod:r})}async getRumblePlaybackInfo(e){return this.get(this.pluginBasePath+"/rumble/playback-info/".concat(encodeURIComponent(e)))}async saveRumbleProgress(e){return this.post(this.pluginBasePath+"/rumble/progress",e)}async saveRumbleDuration(e){return this.post(this.pluginBasePath+"/rumble/duration",e)}async getRumbleProgress(e){return this.get(this.pluginBasePath+"/rumble/progress/".concat(encodeURIComponent(e)))}async saveNativePeerTubeProgress(e){return this.post(this.pluginBasePath+"/native/progress",e)}async getNativePeerTubeProgress(e){return this.get(this.pluginBasePath+"/native/progress/".concat(encodeURIComponent(e)))}async getRumbleHistory(e=50,n=0){return this.get(this.pluginBasePath+"/rumble/history?limit=".concat(e,"&offset=").concat(n))}async deleteRumbleHistoryItem(e){return this.delete(this.pluginBasePath+"/rumble/history/".concat(encodeURIComponent(e)))}async clearRumbleHistory(){return this.delete(this.pluginBasePath+"/rumble/history")}};var _=class{constructor(e){this.rootEl=e}renderRow(e,n){return this.div([this.div(e,n?"col-12 col-lg-4 col-xl-3":"col-12"),...n?[this.div(n,"col-12 col-lg-8 col-xl-9")]:[]],"row")}div(e,n){let o=document.createElement("div");return n&&(o.className=n),e.forEach(s=>o.appendChild(s)),o}a(e,n){let o=document.createElement("a");o.innerHTML=e;for(let s in n)o.setAttribute(s,n[s]);return o}h2(e){let n=document.createElement("h2");return n.innerText=e,n}h3(e){let n=document.createElement("h2");return n.innerText=e,n}p(e,n){let o=document.createElement("p");return o.innerHTML=e,n&&(o.className=n),o}img(e,n){let o=document.createElement("img");return o.src=e,o.className=n,o}ul(e,n){let o=document.createElement("ul");return n&&(o.className=n),e.forEach(s=>{let r=document.createElement("li");r.innerText=s,o.appendChild(r)}),o}};var M=t=>{if(!t)return"-";let e=new Date(t);return isNaN(e.getTime())?"-":e.toLocaleDateString("th-TH",{year:"numeric",month:"numeric",day:"numeric"})},k=async({peertubeHelpers:t,rootEl:e,subscription:n})=>{var v;let{translate:o}=t,s=new f(t.getAuthHeader),r=new _(e),g=n.cancelAt&&!n.cancelAtPeriodEnd,i=n.status==="one_time"||n.status==="manual"||n.status==="manual_added"||g,a=document.createElement("span");i?a.innerHTML='\u0E04\u0E38\u0E13\u0E04\u0E37\u0E2D <strong style="color: #00b14f; font-size: 1.1em;">\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01</strong> \u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C\u0E01\u0E32\u0E23\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E08\u0E30\u0E2A\u0E34\u0E49\u0E19\u0E2A\u0E38\u0E14\u0E43\u0E19\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48 '.concat(M(n.currentPeriodEnd)):n.cancelAtPeriodEnd||n.status==="canceled"?a.innerHTML='\u0E04\u0E38\u0E13\u0E04\u0E37\u0E2D <strong style="color: #00b14f; font-size: 1.1em;">\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01</strong> \u0E01\u0E32\u0E23\u0E2A\u0E21\u0E31\u0E04\u0E23\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13 <span style="color: #dc3545; font-weight: bold;">\u0E16\u0E39\u0E01\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01\u0E41\u0E25\u0E49\u0E27</span> \u0E08\u0E30\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19\u0E44\u0E14\u0E49\u0E16\u0E36\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48 '.concat(M(n.currentPeriodEnd)):a.innerHTML='\u0E04\u0E38\u0E13\u0E04\u0E37\u0E2D <strong style="color: #00b14f; font-size: 1.1em;">\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01</strong> \u0E01\u0E32\u0E23\u0E2A\u0E21\u0E31\u0E04\u0E23\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13 <span style="color: #007bff; text-decoration: underline;">\u0E08\u0E30\u0E15\u0E48\u0E2D\u0E2D\u0E32\u0E22\u0E38\u0E2D\u0E31\u0E15\u0E42\u0E19\u0E21\u0E31\u0E15\u0E34</span> \u0E43\u0E19\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48 '.concat(M(n.currentPeriodEnd));let u=r.div([],"mt-3");if(u.style.display="flex",u.style.gap="10px",!i){let y=await t.getSettings(),p=r.a(await o("\u0E08\u0E31\u0E14\u0E01\u0E32\u0E23\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01"),{href:y[H],target:"_blank"});p.style.cssText="background-color: #fd7e14; color: white; padding: 8px 16px; border-radius: 5px; font-weight: bold; text-decoration: none; border: none; cursor: pointer;";let h=n.cancelAtPeriodEnd?"\u0E15\u0E48\u0E2D\u0E2D\u0E32\u0E22\u0E38\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07":"\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01\u0E01\u0E32\u0E23\u0E2A\u0E21\u0E31\u0E04\u0E23\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01",c=r.a(await o(h),{href:"#"});c.style.cssText="background-color: #fd7e14; color: white; padding: 8px 16px; border-radius: 5px; font-weight: bold; text-decoration: none; border: none; cursor: pointer;",c.addEventListener("click",d=>{d.preventDefault(),c.style.opacity="0.5",c.style.pointerEvents="none",s.updateSubscription({cancelAtPeriodEnd:!n.cancelAtPeriodEnd}).then(()=>window.location.reload()).catch(async I=>{t.showModal({title:await o("\u0E40\u0E01\u0E34\u0E14\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14"),content:await o("\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E44\u0E14\u0E49\u0E43\u0E19\u0E02\u0E13\u0E30\u0E19\u0E35\u0E49 \u0E42\u0E1B\u0E23\u0E14\u0E25\u0E2D\u0E07\u0E43\u0E2B\u0E21\u0E48\u0E20\u0E32\u0E22\u0E2B\u0E25\u0E31\u0E07"),close:!0}),c.style.opacity="1",c.style.pointerEvents="auto"})}),u.appendChild(p),u.appendChild(c)}let m=r.div([a,u]),l=r.renderRow([r.p(await o("\u0E2A\u0E16\u0E32\u0E19\u0E30:"),"fw-bold")],[m]);l.style.borderBottom="1px solid #eee",l.style.paddingBottom="20px",l.style.marginBottom="20px",e.appendChild(l);let b=await(async y=>!y||y.length===0?[r.p(await o("\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E0A\u0E33\u0E23\u0E30\u0E40\u0E07\u0E34\u0E19"),"text-muted")]:Promise.all(y.map(async p=>{var L,A;let h=r.div([],"mb-4");h.appendChild(r.p(M(p.created),"fw-bold mb-2"));let c=r.div([]);c.style.display="grid",c.style.gridTemplateColumns="100px 1fr",c.style.marginBottom="8px",c.appendChild(r.p(await o("\u0E22\u0E2D\u0E14\u0E23\u0E27\u0E21"))),c.appendChild(r.p("".concat(((L=p.amountTotal)!=null?L:0)/100," ").concat(p.currency.toUpperCase())));let d=r.div([]);d.style.display="grid",d.style.gridTemplateColumns="100px 1fr",d.appendChild(r.p(await o("\u0E2A\u0E16\u0E32\u0E19\u0E30")));let I=(A=p.status)!=null?A:"canceled";return I.includes("paid")&&(I="paid"),d.appendChild(r.p(await o(I))),h.appendChild(c),h.appendChild(d),h})))((v=n.invoices)!=null?v:[]),x=r.div(b),S=r.renderRow([r.p(await o("\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E0A\u0E33\u0E23\u0E30\u0E40\u0E07\u0E34\u0E19:"),"fw-bold")],[x]);e.appendChild(S)};var R=(t,e)=>{"gtag"in window&&window.gtag("event",t,w({event_category:"premium-users"},e))},E=(t,e)=>new Intl.NumberFormat(navigator.language,{style:"currency",currency:e,minimumFractionDigits:0}).format(t),T=t=>{var e;return!((e=t.coupon)!=null&&e.valid)||!t.unit_amount?null:t.coupon.amount_off?(t.unit_amount-t.coupon.amount_off)/100:t.coupon.percent_off?Math.round((t.unit_amount-t.unit_amount*(t.coupon.percent_off/100))/100):null};var q=t=>{var e,n,o;return(e=t.coupon)!=null&&e.percent_off?"".concat(t.coupon.percent_off," %"):E((o=(n=t.coupon)==null?void 0:n.amount_off)!=null?o:0,t.currency)},K=async(t,e)=>{var n,o,s;return((n=t.recurring)==null?void 0:n.interval)==="month"?(await e("discount the first MONTHS_COUNT months.")).replace("MONTHS_COUNT",String((o=t.coupon)==null?void 0:o.duration_in_months)):((s=t.recurring)==null?void 0:s.interval)==="year"?e("discount for a whole year."):""},W=t=>{var n,o,s,r,g,i,a,u,m,l;let e=0;return((n=t.recurring)==null?void 0:n.interval)==="month"?(t.unit_amount&&((o=t.coupon)!=null&&o.amount_off)&&((s=t.coupon)!=null&&s.duration_in_months)&&(e=t.coupon.amount_off*((r=t.coupon)==null?void 0:r.duration_in_months)/100),t.unit_amount&&((g=t.coupon)!=null&&g.percent_off)&&((i=t.coupon)!=null&&i.duration_in_months)&&(e=t.unit_amount*(t.coupon.percent_off/100)*((a=t.coupon)==null?void 0:a.duration_in_months)/100)):((u=t.recurring)==null?void 0:u.interval)==="year"&&(t.unit_amount&&((m=t.coupon)!=null&&m.amount_off)&&(e=t.coupon.amount_off*12/100),t.unit_amount&&((l=t.coupon)!=null&&l.percent_off)&&(e=t.unit_amount*(t.coupon.percent_off/100)/100)),e},Q=async(t,e)=>{var s;let n=T(t),o;return n!==null?o='\n <span class="original-price">\n '.concat(E(t.unit_amount/100,t.currency),"</span>\n ").concat(E(n,t.currency)):o=E(t.unit_amount/100,t.currency),(s=t.recurring)!=null&&s.interval?o+=" / "+await e(t.recurring.interval):o+=" / "+await e("1 \u0E40\u0E14\u0E37\u0E2D\u0E19"),o},B=async({buttonOnClick:t,price:e,uiBuilder:n,translate:o})=>{var P,b;let s=T(e),r=await K(e,o),g=W(e),i=q(e),a=await Q(e,o),u=!!t,m="";(P=e.recurring)!=null&&P.interval?m=await o("Pay "+(e.recurring.interval==="day"?"daily":e.recurring.interval+"ly")):m=await o("\u0E0A\u0E33\u0E23\u0E30 1 \u0E40\u0E14\u0E37\u0E2D\u0E19 (QR \u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E40\u0E1E\u0E22\u0E4C)");let l=n.a(a,{class:"primary-button peertube-button-link mb-4","data-testid":"premium_users-button-pay_"+(((b=e.recurring)==null?void 0:b.interval)||"onetime")});return u&&l.addEventListener("click",t),n.div([n.p(m,"fw-bold"),...s===null?[]:[n.ul([i+" "+r,(await o("You'll save AMOUNT_TO_SAVE.")).replace("AMOUNT_TO_SAVE",String(E(Math.round(g),e.currency)))],"text-start")],...u?[l]:[n.p(a,"mt-auto")]],"d-flex flex-grow-1 flex-column")};var j=async({peertubeHelpers:t,rootEl:e})=>{let n=new f(t.getAuthHeader),{translate:o}=t,s=new _(e),r=await n.getPrices();R("view_item_list",{items:r.map(i=>{var a,u,m,l,P;return{item_id:i.product,item_name:"Premium subscription",item_variant:(a=i.recurring)==null?void 0:a.interval,price:(u=i.unit_amount)!=null?u:0,discount:i.unit_amount?i.unit_amount-((m=T(i))!=null?m:0):0,coupon:(P=(l=i.coupon)==null?void 0:l.name)!=null?P:void 0,quantity:1}})});let g=await Promise.all(r.map(async i=>{let a=T(i),u=!i.recurring,m=u?"payment":"subscription",l=u?"promptpay":"card";return B({buttonOnClick:b=>{var S,v,y,p,h,c;let x=b.target;x.setAttribute("disabled","disabled"),R("add_to_cart",{value:a===null?((S=i.unit_amount)!=null?S:0)/100:a,currency:i.currency,items:[{item_id:i.product,item_name:"Premium subscription",item_variant:(v=i.recurring)==null?void 0:v.interval,price:(y=i.unit_amount)!=null?y:0,discount:i.unit_amount?i.unit_amount-(a!=null?a:0):0,coupon:(h=(p=i.coupon)==null?void 0:p.name)!=null?h:void 0,quantity:1}]}),n.createCheckout({allowPromotionCodes:!!new URLSearchParams(window.location.search).get("allowPromotionCodes"),couponId:(c=i.coupon)==null?void 0:c.id,priceId:i.id,paymentMode:m,paymentMethod:l}).then(({checkoutUrl:d})=>{window.location.href=d}).catch(async d=>{t.showModal({title:await o("Something went wrong"),content:await o("Couldn't create subcsription due to technical issues. Please try again later."),close:!0}),console.error("Couldn't create checkout",{err:d})}).finally(()=>{x.removeAttribute("disabled")})},price:i,uiBuilder:s,translate:o})}));e.appendChild(s.renderRow([s.h2(await o("Become premium"))],[s.p(await o("As a premium user you'll get access to premium videos and helps us to continue our work."))])),e.appendChild(s.renderRow([],[s.div(g.map(i=>s.div([i],"col-12 col-sm-6 d-flex")),"row")]))};var G=t=>async({rootEl:e})=>{let{translate:n}=t,o=new f(t.getAuthHeader);e.className="plugin-premium-users my-account",new URLSearchParams(window.location.search).get("checkout_status")==="success"&&(R("purchase"),t.showModal({title:await n("Payment succeeded"),cancel:{value:await n("Close")},content:await n("Your payment succeeded and will short be registered, it may take awhile depending on your payment method."),close:!0}));let r=await o.getSubscription();(await t.getUser()).isPremium?await k({peertubeHelpers:t,rootEl:e,subscription:r}):await j({peertubeHelpers:t,rootEl:e})};async function Re({registerClientRoute:t,peertubeHelpers:e}){let{translate:n}=e,o=await e.getSettings();t({route:"/premium",parentRoute:"/my-account",menuItem:o[N]?{label:await n("Premium account")}:void 0,title:await n("Premium account"),onMount:G(e)})}export{Re as register};
1
+ var V=Object.defineProperty,$=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var O=(t,e,n)=>e in t?V(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,w=(t,e)=>{for(var n in e||(e={}))z.call(e,n)&&O(t,n,e[n]);if(U)for(var n of U(e))J.call(e,n)&&O(t,n,e[n]);return t},C=(t,e)=>$(t,F(e));var N="enable-plugin";var H="stripe-customer-portal-url";var D={name:"peertube-plugin-premium-members",description:"peertube-plugin-premium-members",version:"3.2.1",author:"Vee",bugs:"",clientScripts:[{script:"dist/client/my-account/index.js",scopes:["my-account"]},{script:"dist/client/common.js",scopes:["common"]},{script:"dist/client/video-edit.js",scopes:["video-edit"]},{script:"dist/client/admin-manage.js",scopes:["common"]}],css:["dist/assets/style.css"],engine:{peertube:">=6.0.0"},homepage:"",keywords:["peertube","plugin"],library:"./dist/server/server/main.js",scripts:{clean:"rm -rf dist/*",prepare:"npm run build","build:client":"node ./scripts/build.cjs","build:server":"tsc --build server/tsconfig.json","build:styles":"npx --yes sass --no-source-map assets:dist/assets",build:"npm-run-all -s clean check:client:tsc -p build:server build:client build:styles","check:client:tsc":"npx tsc --p client/tsconfig.json --noEmit","lint:script":"npx eslint .",test:"npm-run-all -p lint:script test:unit","test:unit":"TS_NODE_PROJECT=server/tsconfig.test.json mocha server/*.spec.ts","test:e2e":"cd demo && npm ci && npm test"},staticDirs:{images:"public/images"},translations:{"sv-SE":"./languages/sv.json","th-TH":"./languages/th.json",th:"./languages/th.json"},devDependencies:{"@tsconfig/node16":"^16.0.0","@types/mocha":"^10.0.8","@typescript-eslint/eslint-plugin":"^8.9.0","@typescript-eslint/parser":"^8.9.0",esbuild:"^0.24.0",eslint:"^9.12.0","eslint-config-love":"^87.0.0",globals:"^15.3.0",mocha:"^10.7.3","npm-run-all":"^4.1.5",tsx:"^4.19.1",typescript:"^5.4.3"},dependencies:{"@peertube/peertube-types":"^6.3.0","@types/gtag.js":"^0.0.20","@types/sequelize":"^4.28.20",express:"^4.19.2","short-uuid":"^5.2.0",stripe:"^18.1.0"}};var f=class{constructor(e){this.pluginBasePath="/plugins/".concat(D.name.replace("peertube-plugin-",""),"/router");this.getAuthHeader=e||(()=>{})}async get(e){return fetch(e,{method:"GET",headers:this.getAuthHeader(),credentials:"include"}).then(async n=>n.json())}async patch(e,n){await fetch(e,{method:"PATCH",headers:C(w({},this.getAuthHeader()),{"Content-Type":"application/json"}),credentials:"include",body:JSON.stringify(n)})}async post(e,n){return fetch(e,{method:"POST",headers:C(w({},this.getAuthHeader()),{"Content-Type":"application/json"}),credentials:"include",body:JSON.stringify(n)}).then(async o=>o.json())}async delete(e){return fetch(e,{method:"DELETE",headers:this.getAuthHeader(),credentials:"include"}).then(async n=>n.json())}async getMe(){return this.get("/api/v1/users/me")}async getPrices(){return this.get(this.pluginBasePath+"/price")}async getSubscription(){return this.get(this.pluginBasePath+"/subscription")}async updateSubscription(e){return this.patch(this.pluginBasePath+"/subscription",e)}async createCheckout({allowPromotionCodes:e,couponId:n,priceId:o,paymentMode:s,paymentMethod:r}){return this.post(this.pluginBasePath+"/checkout",{allowPromotionCodes:e,couponId:n,priceId:o,paymentMode:s,paymentMethod:r})}async getRumblePlaybackInfo(e){return this.get(this.pluginBasePath+"/rumble/playback-info/".concat(encodeURIComponent(e)))}async saveRumbleProgress(e){return this.post(this.pluginBasePath+"/rumble/progress",e)}async saveRumbleDuration(e){return this.post(this.pluginBasePath+"/rumble/duration",e)}async getRumbleProgress(e){return this.get(this.pluginBasePath+"/rumble/progress/".concat(encodeURIComponent(e)))}async saveNativePeerTubeProgress(e){return this.post(this.pluginBasePath+"/native/progress",e)}async getNativePeerTubeProgress(e){return this.get(this.pluginBasePath+"/native/progress/".concat(encodeURIComponent(e)))}async getRumbleHistory(e=50,n=0){return this.get(this.pluginBasePath+"/rumble/history?limit=".concat(e,"&offset=").concat(n))}async deleteRumbleHistoryItem(e){return this.delete(this.pluginBasePath+"/rumble/history/".concat(encodeURIComponent(e)))}async clearRumbleHistory(){return this.delete(this.pluginBasePath+"/rumble/history")}};var _=class{constructor(e){this.rootEl=e}renderRow(e,n){return this.div([this.div(e,n?"col-12 col-lg-4 col-xl-3":"col-12"),...n?[this.div(n,"col-12 col-lg-8 col-xl-9")]:[]],"row")}div(e,n){let o=document.createElement("div");return n&&(o.className=n),e.forEach(s=>o.appendChild(s)),o}a(e,n){let o=document.createElement("a");o.innerHTML=e;for(let s in n)o.setAttribute(s,n[s]);return o}h2(e){let n=document.createElement("h2");return n.innerText=e,n}h3(e){let n=document.createElement("h2");return n.innerText=e,n}p(e,n){let o=document.createElement("p");return o.innerHTML=e,n&&(o.className=n),o}img(e,n){let o=document.createElement("img");return o.src=e,o.className=n,o}ul(e,n){let o=document.createElement("ul");return n&&(o.className=n),e.forEach(s=>{let r=document.createElement("li");r.innerText=s,o.appendChild(r)}),o}};var M=t=>{if(!t)return"-";let e=new Date(t);return isNaN(e.getTime())?"-":e.toLocaleDateString("th-TH",{year:"numeric",month:"numeric",day:"numeric"})},k=async({peertubeHelpers:t,rootEl:e,subscription:n})=>{var v;let{translate:o}=t,s=new f(t.getAuthHeader),r=new _(e),g=n.cancelAt&&!n.cancelAtPeriodEnd,i=n.status==="one_time"||n.status==="manual"||n.status==="manual_added"||g,a=document.createElement("span");i?a.innerHTML='\u0E04\u0E38\u0E13\u0E04\u0E37\u0E2D <strong style="color: #00b14f; font-size: 1.1em;">\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01</strong> \u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C\u0E01\u0E32\u0E23\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E08\u0E30\u0E2A\u0E34\u0E49\u0E19\u0E2A\u0E38\u0E14\u0E43\u0E19\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48 '.concat(M(n.currentPeriodEnd)):n.cancelAtPeriodEnd||n.status==="canceled"?a.innerHTML='\u0E04\u0E38\u0E13\u0E04\u0E37\u0E2D <strong style="color: #00b14f; font-size: 1.1em;">\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01</strong> \u0E01\u0E32\u0E23\u0E2A\u0E21\u0E31\u0E04\u0E23\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13 <span style="color: #dc3545; font-weight: bold;">\u0E16\u0E39\u0E01\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01\u0E41\u0E25\u0E49\u0E27</span> \u0E08\u0E30\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19\u0E44\u0E14\u0E49\u0E16\u0E36\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48 '.concat(M(n.currentPeriodEnd)):a.innerHTML='\u0E04\u0E38\u0E13\u0E04\u0E37\u0E2D <strong style="color: #00b14f; font-size: 1.1em;">\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01</strong> \u0E01\u0E32\u0E23\u0E2A\u0E21\u0E31\u0E04\u0E23\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13 <span style="color: #007bff; text-decoration: underline;">\u0E08\u0E30\u0E15\u0E48\u0E2D\u0E2D\u0E32\u0E22\u0E38\u0E2D\u0E31\u0E15\u0E42\u0E19\u0E21\u0E31\u0E15\u0E34</span> \u0E43\u0E19\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48 '.concat(M(n.currentPeriodEnd));let u=r.div([],"mt-3");if(u.style.display="flex",u.style.gap="10px",!i){let y=await t.getSettings(),p=r.a(await o("\u0E08\u0E31\u0E14\u0E01\u0E32\u0E23\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01"),{href:y[H],target:"_blank"});p.style.cssText="background-color: #fd7e14; color: white; padding: 8px 16px; border-radius: 5px; font-weight: bold; text-decoration: none; border: none; cursor: pointer;";let h=n.cancelAtPeriodEnd?"\u0E15\u0E48\u0E2D\u0E2D\u0E32\u0E22\u0E38\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07":"\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01\u0E01\u0E32\u0E23\u0E2A\u0E21\u0E31\u0E04\u0E23\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01",c=r.a(await o(h),{href:"#"});c.style.cssText="background-color: #fd7e14; color: white; padding: 8px 16px; border-radius: 5px; font-weight: bold; text-decoration: none; border: none; cursor: pointer;",c.addEventListener("click",d=>{d.preventDefault(),c.style.opacity="0.5",c.style.pointerEvents="none",s.updateSubscription({cancelAtPeriodEnd:!n.cancelAtPeriodEnd}).then(()=>window.location.reload()).catch(async I=>{t.showModal({title:await o("\u0E40\u0E01\u0E34\u0E14\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14"),content:await o("\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E44\u0E14\u0E49\u0E43\u0E19\u0E02\u0E13\u0E30\u0E19\u0E35\u0E49 \u0E42\u0E1B\u0E23\u0E14\u0E25\u0E2D\u0E07\u0E43\u0E2B\u0E21\u0E48\u0E20\u0E32\u0E22\u0E2B\u0E25\u0E31\u0E07"),close:!0}),c.style.opacity="1",c.style.pointerEvents="auto"})}),u.appendChild(p),u.appendChild(c)}let m=r.div([a,u]),l=r.renderRow([r.p(await o("\u0E2A\u0E16\u0E32\u0E19\u0E30:"),"fw-bold")],[m]);l.style.borderBottom="1px solid #eee",l.style.paddingBottom="20px",l.style.marginBottom="20px",e.appendChild(l);let b=await(async y=>!y||y.length===0?[r.p(await o("\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E0A\u0E33\u0E23\u0E30\u0E40\u0E07\u0E34\u0E19"),"text-muted")]:Promise.all(y.map(async p=>{var L,A;let h=r.div([],"mb-4");h.appendChild(r.p(M(p.created),"fw-bold mb-2"));let c=r.div([]);c.style.display="grid",c.style.gridTemplateColumns="100px 1fr",c.style.marginBottom="8px",c.appendChild(r.p(await o("\u0E22\u0E2D\u0E14\u0E23\u0E27\u0E21"))),c.appendChild(r.p("".concat(((L=p.amountTotal)!=null?L:0)/100," ").concat(p.currency.toUpperCase())));let d=r.div([]);d.style.display="grid",d.style.gridTemplateColumns="100px 1fr",d.appendChild(r.p(await o("\u0E2A\u0E16\u0E32\u0E19\u0E30")));let I=(A=p.status)!=null?A:"canceled";return I.includes("paid")&&(I="paid"),d.appendChild(r.p(await o(I))),h.appendChild(c),h.appendChild(d),h})))((v=n.invoices)!=null?v:[]),x=r.div(b),S=r.renderRow([r.p(await o("\u0E1B\u0E23\u0E30\u0E27\u0E31\u0E15\u0E34\u0E01\u0E32\u0E23\u0E0A\u0E33\u0E23\u0E30\u0E40\u0E07\u0E34\u0E19:"),"fw-bold")],[x]);e.appendChild(S)};var R=(t,e)=>{"gtag"in window&&window.gtag("event",t,w({event_category:"premium-users"},e))},E=(t,e)=>new Intl.NumberFormat(navigator.language,{style:"currency",currency:e,minimumFractionDigits:0}).format(t),T=t=>{var e;return!((e=t.coupon)!=null&&e.valid)||!t.unit_amount?null:t.coupon.amount_off?(t.unit_amount-t.coupon.amount_off)/100:t.coupon.percent_off?Math.round((t.unit_amount-t.unit_amount*(t.coupon.percent_off/100))/100):null};var q=t=>{var e,n,o;return(e=t.coupon)!=null&&e.percent_off?"".concat(t.coupon.percent_off," %"):E((o=(n=t.coupon)==null?void 0:n.amount_off)!=null?o:0,t.currency)},K=async(t,e)=>{var n,o,s;return((n=t.recurring)==null?void 0:n.interval)==="month"?(await e("discount the first MONTHS_COUNT months.")).replace("MONTHS_COUNT",String((o=t.coupon)==null?void 0:o.duration_in_months)):((s=t.recurring)==null?void 0:s.interval)==="year"?e("discount for a whole year."):""},W=t=>{var n,o,s,r,g,i,a,u,m,l;let e=0;return((n=t.recurring)==null?void 0:n.interval)==="month"?(t.unit_amount&&((o=t.coupon)!=null&&o.amount_off)&&((s=t.coupon)!=null&&s.duration_in_months)&&(e=t.coupon.amount_off*((r=t.coupon)==null?void 0:r.duration_in_months)/100),t.unit_amount&&((g=t.coupon)!=null&&g.percent_off)&&((i=t.coupon)!=null&&i.duration_in_months)&&(e=t.unit_amount*(t.coupon.percent_off/100)*((a=t.coupon)==null?void 0:a.duration_in_months)/100)):((u=t.recurring)==null?void 0:u.interval)==="year"&&(t.unit_amount&&((m=t.coupon)!=null&&m.amount_off)&&(e=t.coupon.amount_off*12/100),t.unit_amount&&((l=t.coupon)!=null&&l.percent_off)&&(e=t.unit_amount*(t.coupon.percent_off/100)/100)),e},Q=async(t,e)=>{var s;let n=T(t),o;return n!==null?o='\n <span class="original-price">\n '.concat(E(t.unit_amount/100,t.currency),"</span>\n ").concat(E(n,t.currency)):o=E(t.unit_amount/100,t.currency),(s=t.recurring)!=null&&s.interval?o+=" / "+await e(t.recurring.interval):o+=" / "+await e("1 \u0E40\u0E14\u0E37\u0E2D\u0E19"),o},B=async({buttonOnClick:t,price:e,uiBuilder:n,translate:o})=>{var P,b;let s=T(e),r=await K(e,o),g=W(e),i=q(e),a=await Q(e,o),u=!!t,m="";(P=e.recurring)!=null&&P.interval?m=await o("Pay "+(e.recurring.interval==="day"?"daily":e.recurring.interval+"ly")):m=await o("\u0E0A\u0E33\u0E23\u0E30 1 \u0E40\u0E14\u0E37\u0E2D\u0E19 (QR \u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E40\u0E1E\u0E22\u0E4C)");let l=n.a(a,{class:"primary-button peertube-button-link mb-4","data-testid":"premium_users-button-pay_"+(((b=e.recurring)==null?void 0:b.interval)||"onetime")});return u&&l.addEventListener("click",t),n.div([n.p(m,"fw-bold"),...s===null?[]:[n.ul([i+" "+r,(await o("You'll save AMOUNT_TO_SAVE.")).replace("AMOUNT_TO_SAVE",String(E(Math.round(g),e.currency)))],"text-start")],...u?[l]:[n.p(a,"mt-auto")]],"d-flex flex-grow-1 flex-column")};var j=async({peertubeHelpers:t,rootEl:e})=>{let n=new f(t.getAuthHeader),{translate:o}=t,s=new _(e),r=await n.getPrices();R("view_item_list",{items:r.map(i=>{var a,u,m,l,P;return{item_id:i.product,item_name:"Premium subscription",item_variant:(a=i.recurring)==null?void 0:a.interval,price:(u=i.unit_amount)!=null?u:0,discount:i.unit_amount?i.unit_amount-((m=T(i))!=null?m:0):0,coupon:(P=(l=i.coupon)==null?void 0:l.name)!=null?P:void 0,quantity:1}})});let g=await Promise.all(r.map(async i=>{let a=T(i),u=!i.recurring,m=u?"payment":"subscription",l=u?"promptpay":"card";return B({buttonOnClick:b=>{var S,v,y,p,h,c;let x=b.target;x.setAttribute("disabled","disabled"),R("add_to_cart",{value:a===null?((S=i.unit_amount)!=null?S:0)/100:a,currency:i.currency,items:[{item_id:i.product,item_name:"Premium subscription",item_variant:(v=i.recurring)==null?void 0:v.interval,price:(y=i.unit_amount)!=null?y:0,discount:i.unit_amount?i.unit_amount-(a!=null?a:0):0,coupon:(h=(p=i.coupon)==null?void 0:p.name)!=null?h:void 0,quantity:1}]}),n.createCheckout({allowPromotionCodes:!!new URLSearchParams(window.location.search).get("allowPromotionCodes"),couponId:(c=i.coupon)==null?void 0:c.id,priceId:i.id,paymentMode:m,paymentMethod:l}).then(({checkoutUrl:d})=>{window.location.href=d}).catch(async d=>{t.showModal({title:await o("Something went wrong"),content:await o("Couldn't create subcsription due to technical issues. Please try again later."),close:!0}),console.error("Couldn't create checkout",{err:d})}).finally(()=>{x.removeAttribute("disabled")})},price:i,uiBuilder:s,translate:o})}));e.appendChild(s.renderRow([s.h2(await o("Become premium"))],[s.p(await o("As a premium user you'll get access to premium videos and helps us to continue our work."))])),e.appendChild(s.renderRow([],[s.div(g.map(i=>s.div([i],"col-12 col-sm-6 d-flex")),"row")]))};var G=t=>async({rootEl:e})=>{let{translate:n}=t,o=new f(t.getAuthHeader);e.className="plugin-premium-users my-account",new URLSearchParams(window.location.search).get("checkout_status")==="success"&&(R("purchase"),t.showModal({title:await n("Payment succeeded"),cancel:{value:await n("Close")},content:await n("Your payment succeeded and will short be registered, it may take awhile depending on your payment method."),close:!0}));let r=await o.getSubscription();(await t.getUser()).isPremium?await k({peertubeHelpers:t,rootEl:e,subscription:r}):await j({peertubeHelpers:t,rootEl:e})};async function Re({registerClientRoute:t,peertubeHelpers:e}){let{translate:n}=e,o=await e.getSettings();t({route:"/premium",parentRoute:"/my-account",menuItem:o[N]?{label:await n("Premium account")}:void 0,title:await n("Premium account"),onMount:G(e)})}export{Re as register};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "peertube-plugin-premium-members",
3
3
  "description": "peertube-plugin-premium-members",
4
- "version": "3.2.0",
4
+ "version": "3.2.1",
5
5
  "author": "Vee",
6
6
  "bugs": "",
7
7
  "clientScripts": [