-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
2 lines (2 loc) · 4.33 KB
/
popup.js
1
2
(()=>{"use strict";const e="timer_alert_time",t={DEFAULT_ALERT_MINUTES:10,MIN_ALERT_MINUTES:0,MAX_ALERT_MINUTES:60,STEP_MINUTES:.5,FLASH_INTERVAL:500,FLASH_COUNT:10,SAVE_MESSAGE_DURATION:2e3,DEFAULT_POSITION:{X_OFFSET:150,Y_OFFSET:10}};var n,o;!function(e){e.SESSION_START="session:start",e.SESSION_END="session:end",e.SESSION_UPDATE="session:update",e.SESSION_LEAVE="session:leave",e.SESSION_RETURN="session:return",e.SESSION_UPDATE_ACTIVITY="session:update_activity",e.SUBMISSION_ADD="session:submission_add",e.DATA_PROBLEM_UPDATE="data:problem_update",e.DATA_CLEAR_ALL="data:clear_all",e.DATA_EXPORT="data:export",e.DATA_IMPORT="data:import",e.DATA_GET_STATS="data:get_stats",e.DATA_GET_SESSIONS="data:get_sessions",e.DATA_GET_PROBLEMS="data:get_problems",e.DATA_GET_SETTINGS="data:get_settings",e.DATA_UPDATE_SETTINGS="data:update_settings"}(n||(n={})),function(e){e.SESSION_INITIALIZE_ERROR="session:initialize_error",e.SESSION_LEAVE_ERROR="session:leave_error",e.SESSION_RETURN_ERROR="session:return_error",e.SESSION_UPDATE_ERROR="session:update_error",e.SESSION_CLOSE_ERROR="session:close_error",e.SESSION_NOT_FOUND="session:not_found",e.SUBMISSION_ADD_ERROR="submission:add_error",e.DATA_CLEAR_ERROR="data:clear_error",e.DATA_EXPORT_ERROR="data:export_error",e.DATA_IMPORT_ERROR="data:import_error",e.DATA_PROBLEM_UPDATE_ERROR="data:problem_update_error",e.DATA_SETTINGS_UPDATE_ERROR="data:settings_update_error",e.DATA_STATS_ERROR="data:stats_error",e.UNKNOWN_ERROR="error:unknown"}(o||(o={}));var s=function(e,t,n,o){return new(n||(n=Promise))((function(s,r){function a(e){try{E(o.next(e))}catch(e){r(e)}}function i(e){try{E(o.throw(e))}catch(e){r(e)}}function E(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,i)}E((o=o.apply(e,t||[])).next())}))};function r(e){return e<t.MIN_ALERT_MINUTES?t.MIN_ALERT_MINUTES:e>t.MAX_ALERT_MINUTES?t.MAX_ALERT_MINUTES:Math.round(10*e)/10}function a(){return s(this,void 0,void 0,(function*(){const n=document.getElementById("alertTime"),o=document.getElementById("saveTime"),s=parseFloat(n.value);if(isNaN(s))return void(n.value=t.DEFAULT_ALERT_MINUTES.toString());o.textContent="保存中...",o.disabled=!0;const a=r(s);n.value=a.toString();try{yield chrome.storage.sync.set({[e]:a});const n=document.getElementById("saveStatus");n&&(n.classList.add("show"),setTimeout((()=>{n.classList.remove("show")}),t.SAVE_MESSAGE_DURATION))}catch(e){}finally{o.textContent="保存",o.disabled=!1}}))}function i(){chrome.tabs.create({url:chrome.runtime.getURL("records.html")})}function E(e){const t=document.getElementById("confirmDialog");t&&(e?t.classList.remove("hidden"):t.classList.add("hidden"))}document.addEventListener("DOMContentLoaded",(()=>{var o,d,_,c,l;!function(){s(this,void 0,void 0,(function*(){try{const n=(yield chrome.storage.sync.get(e))[e]||t.DEFAULT_ALERT_MINUTES,o=document.getElementById("alertTime");o&&(o.value=n.toString())}catch(e){}}))}();const S=document.getElementById("alertTime");S&&(S.min=t.MIN_ALERT_MINUTES.toString(),S.max=t.MAX_ALERT_MINUTES.toString(),S.step=t.STEP_MINUTES.toString()),null===(o=document.getElementById("saveTime"))||void 0===o||o.addEventListener("click",a),null===(d=document.getElementById("openRecords"))||void 0===d||d.addEventListener("click",i),null==S||S.addEventListener("change",(()=>{const e=parseFloat(S.value);isNaN(e)||(S.value=r(e).toString())})),null===(_=document.getElementById("clearAllBtn"))||void 0===_||_.addEventListener("click",(()=>{E(!0)})),null===(c=document.getElementById("cancelClear"))||void 0===c||c.addEventListener("click",(()=>{E(!1)})),null===(l=document.getElementById("confirmClear"))||void 0===l||l.addEventListener("click",(()=>s(void 0,void 0,void 0,(function*(){const e=document.getElementById("cleanupStatus"),t=document.getElementById("clearAllBtn"),o=document.getElementById("confirmClear");if(e)try{t.disabled=!0,o.disabled=!0,o.textContent="正在清除...",e.textContent="正在清除所有数据...";const s=yield chrome.runtime.sendMessage({action:n.DATA_CLEAR_ALL});s.success?(e.textContent="✓ 所有数据已清除",e.style.color="#00c853"):(e.textContent="✗ 清除失败:"+s.error,e.style.color="#dc3545")}catch(t){e.textContent="✗ 清除出错:"+(t instanceof Error?t.message:"未知错误"),e.style.color="#dc3545"}finally{t.disabled=!1,o.textContent="确认清除",o.disabled=!1,E(!1)}}))))}))})();
//# sourceMappingURL=popup.js.map