Files
audio-voice-converter/google-meet-transcripts-extension/feature/record/meetingInfo.js
T

1 line
5.9 KiB
JavaScript

const getMeetingName=()=>{let e=xpath(XPATH_TITLE_V20220324)?.innerText;e||(e=xpath(XPATH_TITLE)?.innerText),e===SEARCH_TEXT_NO_MEETING_NAME&&(e=xpath(XPATH_TITLE_TOOLTIP)?.innerText);const t=document.location.pathname.match(/\/(.+)/)[1];if(e&&e!==SEARCH_TEXT_NO_MEETING_NAME&&e!==t)return e},checkMeetingStatus=()=>{const e=xpath("//body[@id='yDmH0d']/c-wiz/div/div[2]/div/div/div[3]/div/div/div/div/button/div[2]"),t=getElementWithXPathFallback(document,'//div[contains(@jscontroller,"VQ0pCb")]','//*[contains(text(), "You left the meeting")]');xpath(),e?meetingStatus=0:findButtonContainer()?meetingStatus=1:t&&(meetingStatus=2,clearInterval(checkCaptionStatusInterval),clearInterval(autoSaveInterval),Export2App(!0,!0).then((e=>{increment(`hangout_${currentTranscriptId}`),window.open(`${domainUrl}/transcript/${e}`,"_blank")})).catch((e=>{console.error(e);const t=get(ERROR_SAVING)||[];set(ERROR_SAVING,[...t,e])})))},renewToken=e=>{chrome.storage.local.get(["refreshToken"],(function(t){let n=JSON.stringify({idToken:e,refreshToken:t.refreshToken}),o={Authorization:`Bearer ${e}`,"Content-Type":"application/json"};window.fetch(`${domainUrl}/api/v1/users/token`,{method:"POST",headers:o,body:n}).then((t=>{200===t.status?t.json().then((e=>{const t=new Date;chrome.storage.local.set({last_refresh_date:t},(function(){console.log(t)})),chrome.storage.local.set({token:e.id_token,refreshToken:e.refreshToken},(function(){console.log("Token refreshed")}))})):401===t.status?(debug("Unauthorized"),t.json().then((t=>{saveLog(`renewToken 401 fail ${e} ${t.message}`)})),reDisplayPrompt(),reDisplayRemindLogin()):(t.json().then((t=>{saveLog(`renewToken request fail ${e} ${t.message}`),debug(t.message)})),reDisplayPrompt(),reDisplayRemindLogin())})).catch((t=>{saveLog(`renewToken request exception ${e} ${t}`),debug(t),reDisplayPrompt(),reDisplayRemindLogin()}))}))},checkToken=()=>{chrome.storage.local.get(["token"],(function(e){if(e.token){tryTo((()=>{1e3*JSON.parse(atob(e.token.split(".")[1])).exp-Date.now()<6048e5&&(debug("Refresh JWT token"),renewToken(e.token))})(),"check whether token expired");const t={method:"GET",headers:{Authorization:`Bearer ${e.token}`}},n=()=>window.fetch(`${domainUrl}/api/v1/users/info`,t),o=()=>window.fetch(`${domainUrl}/api/v2/templates?quick-note=true`,t),s=e=>window.fetch(`${domainUrl}/api/v2/templates/${e}/topics`,t);Promise.all([n(),o()]).then((n=>{if(200===n[0].status&&200===n[1].status){loginStatus=1;const e=document.getElementById("login-prompt");e&&(e.style.display="none");const o=document.getElementById("laxis-remindLogin");o&&(o.style.display="none"),n[0].json().then((e=>{const n=e;appUser=`${n.firstName} ${n.lastName}`,window.fetch(`${domainUrl}/api/v1/teams/isAdmin`,t).then((e=>{e.json().then((e=>{e.isAdmin||e.hasTeam?window.fetch(`${domainUrl}/api/v1/teams/info`,t).then((e=>{e.json().then((e=>{console.log(e),displayGoogleMeetQuota(e.usedSecondsQuota/60,-1)}))})):"free"===n.plan?displayGoogleMeetQuota(n.usedSecondsQuota/60,n.secondsQuota/60):displayGoogleMeetQuota(n.usedSecondsQuota/60,-1)}))}))})),n[1].json().then((e=>{let t=bookmarkList;s(e.items[0].id).then((e=>e.json().then((e=>{e.items.forEach((e=>{let n=bookmarkList.findIndex((t=>t.code===e.color));if(-1!==n){if(t[n].name=e.name,document.getElementById(`laxis-highlight-${e.color}-title`)){document.getElementById(`laxis-highlight-${e.color}-title`).innerHTML=e.name}let o=document.getElementById(`laxis-highlight-${e.color}`),s=document.getElementById(`laxis-highlight-${e.color}-mini`);o&&(o.title=`Highlight as ${e.name}`),s&&(s.title=`Highlight as ${e.name}`)}}))})))),bookmarkList=t}))}else 401===n[0].status||401===n[1].status?(401===n[0].status?n[0].json().then((t=>{saveLog(`checkToken 401 fail ${e.token} ${t.message}`)})):n[1].json().then((t=>{saveLog(`checkToken 401 fail ${e.token} ${t.message}`)})),reDisplayPrompt(),reDisplayRemindLogin()):n[0].json().then((e=>{window.alert(e.message)}))})).catch((e=>{window.alert(e)}))}else saveLog(`checkToken token empty ${e.token}`),reDisplayPrompt(),reDisplayRemindLogin()}))};let hasCaptionButtons=!1;const checkCaptionStatus=()=>{if(checkMeetingStatus(),1===meetingStatus){const e=getElementWithXPathFallback(document,XPATH_TURN_ON_CAPTIONS_BUTTON,XPATH_TURN_ON_CAPTIONS_BUTTON_V20210602),t=getElementWithXPathFallback(document,XPATH_TURN_OFF_CAPTIONS_BUTTON,XPATH_TURN_OFF_CAPTIONS_BUTTON_V20210602);if(null==e&&null==t)return void tryTo(startTranscribing(),"start");hasCaptionButtons=!0;let n=!1;if(e&&!t&&(n=!1),!e&&t&&(n=!0),firstStart||n!==weTurnedCaptionsOn){firstStart=!1,weTurnedCaptionsOn=n;const e=document.getElementById("feature"),t=document.getElementById("laxis-caption-toggle");e&&t&&(n?(isCaptionTurnedOn=!0,notificationsOn(),tryTo(startTranscribing(),"start")):tryTo(stopTranscribing(),"stop"))}}},setCurrentTranscriptDetails=()=>{const e=new Date,t=`${e.getFullYear()}-${pad(e.getMonth()+1)}-${pad(e.getDate())}`,n=`${document.location.pathname.match(/\/(.+)/)[1]}-${t}`,o=get(KEY_TRANSCRIPT_IDS)||[],s=!o.includes(n);if(currentTranscriptId=n,chrome.runtime.sendMessage({type:"meetingId",meetingId:n}),s){o.unshift(currentTranscriptId),set(KEY_TRANSCRIPT_IDS,o),currentSessionIndex=increment(`hangout_${currentTranscriptId}`);const e=getMeetingName();e&&set(`${makeTranscriptKey(currentTranscriptId)}_name`,e)}else{currentSessionIndex=get(makeTranscriptKey(currentTranscriptId))||0;const e=get(makeTranscriptKey(currentTranscriptId,currentSessionIndex))||0,t=get(makeTranscriptKey(currentTranscriptId,currentSessionIndex,e));if(t){const e=new Date(t.endedAt),n=parseInt(get(CURRENT_INTERVAL))||10;(new Date).getTime()-e.getTime()>6e4*n?currentSessionIndex=increment(`hangout_${currentTranscriptId}`):checkTranscriptionId()}else checkTranscriptionId()}debug({currentTranscriptId:currentTranscriptId,currentSessionIndex:currentSessionIndex}),loadLocalStorage=1};function saveLog(e){const t={message:e,time:(new Date).toISOString()};chrome.storage.local.get("logs",(function(e){var n=structuredClone(e.logs);void 0===n?n=[t]:n.push(t),chrome.storage.local.set({logs:n})}))}