Files
google-meet-captions/feature/utilities/util.js
T

1 line
2.4 KiB
JavaScript

const pad=t=>t<10?`0${t}`:t,debug=(...t)=>{DEBUG&&console.log("[laxis debug]",...t)},tryTo=(t,e)=>async(...n)=>{try{return await t(...n)}catch(t){console.error(`error ${e}:`,t)}},getTimeStr=(t,e)=>{const n=new Date(e)-t,o=Math.trunc(n/1e3)%60,a=Math.trunc(n/1e3/60);return pad(a)+":"+pad(o)},signup=()=>{window.open(loginUrl)},upgrade=()=>{window.open(upgradeUrl)},getDefaultName=()=>{const t=new Date,e=t.getDate(),n=t.getMonth(),o=t.getFullYear(),a=t.getHours(),r=t.getMinutes();return`Meeting_${o}${pad(n+1)}${pad(e)}_${pad(a)}${pad(r)}`};function onShortcut(t){var e="";document.addEventListener("keydown",(function(n){if(n.shiftKey){if((e+=""+n.key)===SHORTCUT_KEY)return t();SHORTCUT_KEY.indexOf(e)&&(e=""+n.key)}}))}onShortcut((function(){const t=document.getElementById("laxis-repair");t&&(t.style.display="block")}));const getCurrentLanguage=()=>{const t=xpath('//button[contains(@jsname,"gnzhTe")]',document);if(t){const e=t.ariaLabel;return e.substring(0,e.length-17)}return""},getToSettings=()=>{const t='//div[contains(@jscontroller,"bZ0mod")]';if(xpath('//div[contains(@aria-label, "Settings")]',document)){const t=xpath('//button[contains(@aria-label, "Close dialog")]',document);if(t)return void t.click()}else{const e=xpath('//button[contains(@aria-label, "More options") and contains(@jscontroller, "PIVayb")]',document);e&&e.click();let n=!1;const o=xpath(t,document);if(o&&"none"!==o?.style?.display&&(o.style.display="none",n=!0),!n){let e=setInterval((()=>{const n=xpath(t,document);n&&"none"!==n?.style?.display&&(n.style.display="none",clearInterval(e))}),[50])}let a=setInterval((()=>{const t=xpath('//i[contains(text(), "settings")]',document);if(t){t.click(),clearInterval(a);let e=setInterval((()=>{const t=xpath('//button[contains(@aria-label, "Captions")]',document);t&&(t.click(),clearInterval(e))}),[50])}}),[50])}},extractLocalStorage=()=>{const t=(t,e="")=>{let n=document.createElement("a");const o=new File([t],"filename"),a=URL.createObjectURL(o);return n.href=a,n.download=`${e}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),Promise.resolve(1)};console.log((()=>{var e,n={};for(e in window.localStorage)e.includes("laxis")&&(value=window.localStorage.getItem(e),n[e]=value);if(!chrome||!chrome.storage)return t(JSON.stringify(n),"dumplocalStorage"),n;chrome.storage.local.get(null,(function(e){for(var o in e)return n[o]=e[o],t(JSON.stringify(n),"dumplocalStorage"),n}))})())};