2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
|
|
import{b as i}from"./browser-polyfill-CZ_dLIqp.js";import{n as P,a as j}from"./downloadIntent-Dv31jC2S.js";import{g as h}from"./settings-Bo6W9Drl.js";const z="org.gdown.nativehost";async function J(e){return i.runtime.sendNativeMessage(z,{action:"addUri",...e})}async function Z(){return i.runtime.sendNativeMessage(z,{action:"focus"})}const C="history";async function ee(){const t=(await i.storage.local.get([C]))[C];return Array.isArray(t)?t:[]}async function te(e){await i.storage.local.set({[C]:e.slice(0,300)})}async function ne(e){const t=await ee(),n=t.findIndex(r=>r.gid===e.gid);n>=0?t[n]=e:t.unshift(e),await te(t)}function G(e,t){const n=Array.isArray(e?.responseHeaders)?e.responseHeaders:[],r=t.toLowerCase(),o=n.find(s=>String(s?.name||"").toLowerCase()===r);return String(o?.value||"")}function re(e){const t=e.toLowerCase();return t?t.includes("application/vnd.apple.mpegurl")||t.includes("application/x-mpegurl")||t.includes("audio/mpegurl")?"m3u8":t.includes("video/mp4")?"mp4":t.includes("application/octet-stream")&&t.includes("m3u8")?"m3u8":t.includes("hls")?"hls":"unknown":"unknown"}function oe(e){const t=String(e||"").toLowerCase();return t.includes(".m3u8")?"m3u8":t.includes(".m3u")?"m3u":t.includes(".mp4")?"mp4":t.includes("m3u8")?"m3u8":t.includes("hls")?"hls":"unknown"}function B(e,t){const n=re(t);return n!=="unknown"?n:oe(e)}function ie(e){if(!e?.url)return!1;const t=String(e?.method||"").toUpperCase();if(t&&t!=="GET")return!1;const n=Number(e?.statusCode||0);if(n>0&&(n<200||n>299))return!1;const r=String(e?.type||"");if(!["xmlhttprequest","media","other","main_frame","sub_frame","fetch"].includes(r))return!1;const o=G(e,"content-type");return B(e.url,o)!=="unknown"}function se(e,t=""){const n=G(e,"content-type"),r=String(e?.url||""),o=B(r,n),s=Number.isInteger(e?.tabId)?Number(e.tabId):-1,a=Date.now();return{id:`${a}:${s}:${o}:${r}`,url:r,kind:o,tabId:s,pageUrl:String(e?.documentUrl||e?.initiator||""),referer:String(t||e?.documentUrl||e?.initiator||""),contentType:n,detectedAt:a}}function q(e){try{const t=new URL(e);return`${t.protocol}//${t.host}${t.pathname}`.toLowerCase()}catch{return String(e||"").toLowerCase()}}const b="media_candidates",ae=200;async function W(){const t=(await i.storage.local.get([b]))[b];return Array.isArray(t)?t:[]}async function ue(e){const t=[...e].sort((n,r)=>r.detectedAt-n.detectedAt);await i.storage.local.set({[b]:t.slice(0,ae)})}async function ce(e,t){const n=await W(),r=n.findIndex(o=>{try{const s=new URL(o.url);return`${s.protocol}//${s.host}${s.pathname}`.toLowerCase()===t}catch{return o.url.toLowerCase()===t}});r>=0?n[r]={...n[r],...e,detectedAt:Date.now()}:n.unshift(e),await ue(n)}async function le(){await i.storage.local.set({[b]:[]})}const k=8e3,de=7e3,U="gomdown-helper-download-context-menu-option",m=new Map,M=new Map,I=new Map,L=new Map,w=new Map,R=new Map,A=new Map;let $=!1,E=!1,_=!1,p=null;const K="bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]/best",fe=[{hosts:["youtube.com","www.youtube.com","m.youtube.com","youtu.be"],extractor:"yt-dlp",format:K}];function x(e){try{const t=new URL(e),n=(t.pathname||"/").replace(/\/+$/,"")||"/";return`${t.protocol}//${t.host}${n}`.toLowerCase()}catch{return String(e||"").toLowerCase()}}function f(e){const t=Date.now();for(const[n,r]of e.entries())r<=t&&e.delete(n)}function Y(e){const t=Date.now()+k;M.set(P(e),t),I.set(x(e),t)}function Q(e){!Number.isInteger(e)||(e??-1)<0||R.set(e,Date.now()+k)}function pe(e){f(M),f(I);const t=P(e);return M.has(t)||I.has(x(e))}function me(e){return f(R),!Number.isInteger(e)||(e??-1)<0?!1:R.has(e)}function we(e){return f(L),L.has(x(e))}function ge(e){L.set(x(e),Date.now()+de)}function he(e){return f(w),!!e&&w.has(e)}function ye(e){e&&w.set(e,Date.now()+k)}function Se(e){f(A);const t=q(e);return A.has(t)}function be(e){A.set(q(e),Date.now()+k)}async function ke(){try{await Z()}catch{}}async function v(e){await i.notifications.create(`gomdown-notice-${Date.now()}`,{type:"basic",iconUrl:"/images/icon-large.png",title:"Gomdown Helper",message:e}).catch(()=>null)}async function d(e,t="",n,r,o,s){if(we(e))return{ok
|