| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291 |
- // sidepanel/sidepanel.js — Side Panel logic
- const STATUS_ICONS = {
- pending: '',
- running: '',
- completed: '\u2713', // ✓
- failed: '\u2717', // ✗
- stopped: '\u25A0', // ■
- manual_completed: '跳',
- skipped: '跳',
- };
- const logArea = document.getElementById('log-area');
- const accountRunHistoryStrip = document.getElementById('account-run-history-strip');
- const accountRunHistoryMeta = document.getElementById('account-run-history-meta');
- const accountRunHistoryStats = document.getElementById('account-run-history-stats');
- const accountRunHistoryList = document.getElementById('account-run-history-list');
- const updateSection = document.getElementById('update-section');
- const extensionUpdateStatus = document.getElementById('extension-update-status');
- const extensionVersionMeta = document.getElementById('extension-version-meta');
- const btnReleaseLog = document.getElementById('btn-release-log');
- const updateCardVersion = document.getElementById('update-card-version');
- const updateCardSummary = document.getElementById('update-card-summary');
- const updateReleaseList = document.getElementById('update-release-list');
- const btnOpenRelease = document.getElementById('btn-open-release');
- const settingsCard = document.getElementById('settings-card');
- const displayOauthUrl = document.getElementById('display-oauth-url');
- const displayLocalhostUrl = document.getElementById('display-localhost-url');
- const displayStatus = document.getElementById('display-status');
- const statusBar = document.getElementById('status-bar');
- const inputEmail = document.getElementById('input-email');
- const inputPassword = document.getElementById('input-password');
- const btnToggleVpsUrl = document.getElementById('btn-toggle-vps-url');
- const btnToggleVpsPassword = document.getElementById('btn-toggle-vps-password');
- const btnFetchEmail = document.getElementById('btn-fetch-email');
- const btnTogglePassword = document.getElementById('btn-toggle-password');
- const btnSaveSettings = document.getElementById('btn-save-settings');
- const btnStop = document.getElementById('btn-stop');
- const btnReset = document.getElementById('btn-reset');
- const stepsProgress = document.getElementById('steps-progress');
- const btnAutoRun = document.getElementById('btn-auto-run');
- const btnAutoContinue = document.getElementById('btn-auto-continue');
- const autoContinueBar = document.getElementById('auto-continue-bar');
- const autoScheduleBar = document.getElementById('auto-schedule-bar');
- const autoScheduleTitle = document.getElementById('auto-schedule-title');
- const autoScheduleMeta = document.getElementById('auto-schedule-meta');
- const btnAutoRunNow = document.getElementById('btn-auto-run-now');
- const btnAutoCancelSchedule = document.getElementById('btn-auto-cancel-schedule');
- const btnClearLog = document.getElementById('btn-clear-log');
- const configMenuShell = document.getElementById('config-menu-shell');
- const btnConfigMenu = document.getElementById('btn-config-menu');
- const configMenu = document.getElementById('config-menu');
- const btnExportSettings = document.getElementById('btn-export-settings');
- const btnImportSettings = document.getElementById('btn-import-settings');
- const inputImportSettingsFile = document.getElementById('input-import-settings-file');
- const selectPanelMode = document.getElementById('select-panel-mode');
- const rowVpsUrl = document.getElementById('row-vps-url');
- const inputVpsUrl = document.getElementById('input-vps-url');
- const rowVpsPassword = document.getElementById('row-vps-password');
- const inputVpsPassword = document.getElementById('input-vps-password');
- const rowLocalCpaStep9Mode = document.getElementById('row-local-cpa-step9-mode');
- const localCpaStep9ModeButtons = Array.from(document.querySelectorAll('[data-local-cpa-step9-mode]'));
- const rowCpaCallbackMode = document.getElementById('row-cpa-callback-mode');
- const cpaCallbackModeButtons = Array.from(document.querySelectorAll('[data-cpa-callback-mode]'));
- const rowSub2ApiUrl = document.getElementById('row-sub2api-url');
- const inputSub2ApiUrl = document.getElementById('input-sub2api-url');
- const rowSub2ApiEmail = document.getElementById('row-sub2api-email');
- const inputSub2ApiEmail = document.getElementById('input-sub2api-email');
- const rowSub2ApiPassword = document.getElementById('row-sub2api-password');
- const inputSub2ApiPassword = document.getElementById('input-sub2api-password');
- const rowSub2ApiGroup = document.getElementById('row-sub2api-group');
- const inputSub2ApiGroup = document.getElementById('input-sub2api-group');
- const selectMailProvider = document.getElementById('select-mail-provider');
- const btnMailLogin = document.getElementById('btn-mail-login');
- const rowMail2925Mode = document.getElementById('row-mail-2925-mode');
- const mail2925ModeButtons = Array.from(document.querySelectorAll('[data-mail2925-mode]'));
- const rowEmailGenerator = document.getElementById('row-email-generator');
- const selectEmailGenerator = document.getElementById('select-email-generator');
- const rowTempEmailBaseUrl = document.getElementById('row-temp-email-base-url');
- const inputTempEmailBaseUrl = document.getElementById('input-temp-email-base-url');
- const rowTempEmailAdminAuth = document.getElementById('row-temp-email-admin-auth');
- const inputTempEmailAdminAuth = document.getElementById('input-temp-email-admin-auth');
- const rowTempEmailCustomAuth = document.getElementById('row-temp-email-custom-auth');
- const inputTempEmailCustomAuth = document.getElementById('input-temp-email-custom-auth');
- const rowTempEmailReceiveMailbox = document.getElementById('row-temp-email-receive-mailbox');
- const inputTempEmailReceiveMailbox = document.getElementById('input-temp-email-receive-mailbox');
- const rowTempEmailDomain = document.getElementById('row-temp-email-domain');
- const selectTempEmailDomain = document.getElementById('select-temp-email-domain');
- const inputTempEmailDomain = document.getElementById('input-temp-email-domain');
- const btnTempEmailDomainMode = document.getElementById('btn-temp-email-domain-mode');
- const hotmailSection = document.getElementById('hotmail-section');
- const luckmailSection = document.getElementById('luckmail-section');
- const icloudSection = document.getElementById('icloud-section');
- const icloudSummary = document.getElementById('icloud-summary');
- const icloudList = document.getElementById('icloud-list');
- const icloudLoginHelp = document.getElementById('icloud-login-help');
- const icloudLoginHelpTitle = document.getElementById('icloud-login-help-title');
- const icloudLoginHelpText = document.getElementById('icloud-login-help-text');
- const btnIcloudLoginDone = document.getElementById('btn-icloud-login-done');
- const btnIcloudRefresh = document.getElementById('btn-icloud-refresh');
- const btnIcloudDeleteUsed = document.getElementById('btn-icloud-delete-used');
- const selectIcloudHostPreference = document.getElementById('select-icloud-host-preference');
- const checkboxAutoDeleteIcloud = document.getElementById('checkbox-auto-delete-icloud');
- const inputIcloudSearch = document.getElementById('input-icloud-search');
- const selectIcloudFilter = document.getElementById('select-icloud-filter');
- const checkboxIcloudSelectAll = document.getElementById('checkbox-icloud-select-all');
- const icloudSelectionSummary = document.getElementById('icloud-selection-summary');
- const btnIcloudBulkUsed = document.getElementById('btn-icloud-bulk-used');
- const btnIcloudBulkUnused = document.getElementById('btn-icloud-bulk-unused');
- const btnIcloudBulkPreserve = document.getElementById('btn-icloud-bulk-preserve');
- const btnIcloudBulkUnpreserve = document.getElementById('btn-icloud-bulk-unpreserve');
- const btnIcloudBulkDelete = document.getElementById('btn-icloud-bulk-delete');
- const rowHotmailServiceMode = document.getElementById('row-hotmail-service-mode');
- const hotmailServiceModeButtons = Array.from(document.querySelectorAll('[data-hotmail-service-mode]'));
- const rowHotmailRemoteBaseUrl = document.getElementById('row-hotmail-remote-base-url');
- const inputHotmailRemoteBaseUrl = document.getElementById('input-hotmail-remote-base-url');
- const rowHotmailLocalBaseUrl = document.getElementById('row-hotmail-local-base-url');
- const inputHotmailLocalBaseUrl = document.getElementById('input-hotmail-local-base-url');
- const inputHotmailEmail = document.getElementById('input-hotmail-email');
- const inputHotmailClientId = document.getElementById('input-hotmail-client-id');
- const inputHotmailPassword = document.getElementById('input-hotmail-password');
- const inputHotmailRefreshToken = document.getElementById('input-hotmail-refresh-token');
- const inputHotmailImport = document.getElementById('input-hotmail-import');
- const btnAddHotmailAccount = document.getElementById('btn-add-hotmail-account');
- const btnImportHotmailAccounts = document.getElementById('btn-import-hotmail-accounts');
- const btnHotmailUsageGuide = document.getElementById('btn-hotmail-usage-guide');
- const btnClearUsedHotmailAccounts = document.getElementById('btn-clear-used-hotmail-accounts');
- const btnDeleteAllHotmailAccounts = document.getElementById('btn-delete-all-hotmail-accounts');
- const btnToggleHotmailList = document.getElementById('btn-toggle-hotmail-list');
- const hotmailListShell = document.getElementById('hotmail-list-shell');
- const hotmailAccountsList = document.getElementById('hotmail-accounts-list');
- const inputLuckmailApiKey = document.getElementById('input-luckmail-api-key');
- const inputLuckmailBaseUrl = document.getElementById('input-luckmail-base-url');
- const selectLuckmailEmailType = document.getElementById('select-luckmail-email-type');
- const inputLuckmailDomain = document.getElementById('input-luckmail-domain');
- const btnLuckmailRefresh = document.getElementById('btn-luckmail-refresh');
- const btnLuckmailDisableUsed = document.getElementById('btn-luckmail-disable-used');
- const luckmailSummary = document.getElementById('luckmail-summary');
- const inputLuckmailSearch = document.getElementById('input-luckmail-search');
- const selectLuckmailFilter = document.getElementById('select-luckmail-filter');
- const checkboxLuckmailSelectAll = document.getElementById('checkbox-luckmail-select-all');
- const luckmailSelectionSummary = document.getElementById('luckmail-selection-summary');
- const btnLuckmailBulkUsed = document.getElementById('btn-luckmail-bulk-used');
- const btnLuckmailBulkUnused = document.getElementById('btn-luckmail-bulk-unused');
- const btnLuckmailBulkPreserve = document.getElementById('btn-luckmail-bulk-preserve');
- const btnLuckmailBulkUnpreserve = document.getElementById('btn-luckmail-bulk-unpreserve');
- const btnLuckmailBulkDisable = document.getElementById('btn-luckmail-bulk-disable');
- const btnLuckmailBulkEnable = document.getElementById('btn-luckmail-bulk-enable');
- const luckmailList = document.getElementById('luckmail-list');
- const rowEmailPrefix = document.getElementById('row-email-prefix');
- const labelEmailPrefix = document.getElementById('label-email-prefix');
- const inputEmailPrefix = document.getElementById('input-email-prefix');
- const rowInbucketHost = document.getElementById('row-inbucket-host');
- const inputInbucketHost = document.getElementById('input-inbucket-host');
- const rowInbucketMailbox = document.getElementById('row-inbucket-mailbox');
- const inputInbucketMailbox = document.getElementById('input-inbucket-mailbox');
- const rowCfDomain = document.getElementById('row-cf-domain');
- const selectCfDomain = document.getElementById('select-cf-domain');
- const inputCfDomain = document.getElementById('input-cf-domain');
- const btnCfDomainMode = document.getElementById('btn-cf-domain-mode');
- const inputRunCount = document.getElementById('input-run-count');
- const inputAutoSkipFailures = document.getElementById('input-auto-skip-failures');
- const inputAutoSkipFailuresThreadIntervalMinutes = document.getElementById('input-auto-skip-failures-thread-interval-minutes');
- const inputAutoDelayEnabled = document.getElementById('input-auto-delay-enabled');
- const inputAutoDelayMinutes = document.getElementById('input-auto-delay-minutes');
- const inputAutoStepDelaySeconds = document.getElementById('input-auto-step-delay-seconds');
- const inputAccountRunHistoryTextEnabled = document.getElementById('input-account-run-history-text-enabled');
- const rowAccountRunHistoryHelperBaseUrl = document.getElementById('row-account-run-history-helper-base-url');
- const inputAccountRunHistoryHelperBaseUrl = document.getElementById('input-account-run-history-helper-base-url');
- const autoStartModal = document.getElementById('auto-start-modal');
- const autoStartTitle = autoStartModal?.querySelector('.modal-title');
- const autoStartMessage = document.getElementById('auto-start-message');
- const autoStartAlert = document.getElementById('auto-start-alert');
- const modalOptionRow = document.getElementById('modal-option-row');
- const modalOptionInput = document.getElementById('modal-option-input');
- const modalOptionText = document.getElementById('modal-option-text');
- const btnAutoStartClose = document.getElementById('btn-auto-start-close');
- const btnAutoStartCancel = document.getElementById('btn-auto-start-cancel');
- const btnAutoStartRestart = document.getElementById('btn-auto-start-restart');
- const btnAutoStartContinue = document.getElementById('btn-auto-start-continue');
- const autoHintText = document.querySelector('.auto-hint');
- const stepDefinitions = (window.MultiPageStepDefinitions?.getSteps?.() || []).sort((left, right) => left.order - right.order);
- const STEP_IDS = stepDefinitions.map((step) => Number(step.id)).filter(Number.isFinite);
- const STEP_DEFAULT_STATUSES = Object.fromEntries(STEP_IDS.map((stepId) => [stepId, 'pending']));
- const SKIPPABLE_STEPS = new Set(STEP_IDS);
- const stepsList = document.querySelector('.steps-list');
- const AUTO_DELAY_MIN_MINUTES = 1;
- const AUTO_DELAY_MAX_MINUTES = 1440;
- const AUTO_DELAY_DEFAULT_MINUTES = 30;
- const AUTO_FALLBACK_THREAD_INTERVAL_MIN_MINUTES = 0;
- const AUTO_FALLBACK_THREAD_INTERVAL_MAX_MINUTES = 1440;
- const AUTO_FALLBACK_THREAD_INTERVAL_DEFAULT_MINUTES = 0;
- const AUTO_RUN_MAX_RETRIES_PER_ROUND = 3;
- const AUTO_STEP_DELAY_MIN_SECONDS = 0;
- const AUTO_STEP_DELAY_MAX_SECONDS = 600;
- const DEFAULT_LOCAL_CPA_STEP9_MODE = 'submit';
- const DEFAULT_CPA_CALLBACK_MODE = 'step8';
- const MAIL_2925_MODE_PROVIDE = 'provide';
- const MAIL_2925_MODE_RECEIVE = 'receive';
- const DEFAULT_MAIL_2925_MODE = MAIL_2925_MODE_PROVIDE;
- const AUTO_SKIP_FAILURES_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-auto-skip-failures-prompt-dismissed';
- const AUTO_RUN_FALLBACK_RISK_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-auto-run-fallback-risk-prompt-dismissed';
- const AUTO_RUN_FALLBACK_RISK_WARNING_MIN_RUNS = 15;
- const AUTO_RUN_FALLBACK_RISK_RECOMMENDED_THREAD_INTERVAL_MINUTES = 5;
- const HOTMAIL_SERVICE_MODE_REMOTE = 'remote';
- const HOTMAIL_SERVICE_MODE_LOCAL = 'local';
- const ICLOUD_PROVIDER = 'icloud';
- const GMAIL_PROVIDER = 'gmail';
- const LUCKMAIL_PROVIDER = 'luckmail-api';
- const DEFAULT_LUCKMAIL_BASE_URL = 'https://mails.luckyous.com';
- const DEFAULT_LUCKMAIL_EMAIL_TYPE = 'ms_graph';
- const DISPLAY_TIMEZONE = 'Asia/Shanghai';
- const DEFAULT_ACCOUNT_RUN_HISTORY_HELPER_BASE_URL = 'http://127.0.0.1:17373';
- function getManagedAliasUtils() {
- return window.MultiPageManagedAliasUtils || null;
- }
- function isManagedAliasProvider(provider = selectMailProvider.value) {
- const utils = getManagedAliasUtils();
- if (utils?.isManagedAliasProvider) {
- return utils.isManagedAliasProvider(provider);
- }
- return [GMAIL_PROVIDER, '2925'].includes(String(provider || '').trim().toLowerCase());
- }
- function parseManagedAliasBaseEmail(rawValue, provider = selectMailProvider.value) {
- const utils = getManagedAliasUtils();
- if (utils?.parseManagedAliasBaseEmail) {
- return utils.parseManagedAliasBaseEmail(rawValue, provider);
- }
- return null;
- }
- function isManagedAliasEmail(value, baseEmail = '', provider = selectMailProvider.value) {
- const utils = getManagedAliasUtils();
- if (utils?.isManagedAliasEmail) {
- return utils.isManagedAliasEmail(value, provider, baseEmail);
- }
- return false;
- }
- function getManagedAliasProviderUiCopy(provider = selectMailProvider.value) {
- const utils = getManagedAliasUtils();
- if (utils?.getManagedAliasProviderUiCopy) {
- return utils.getManagedAliasProviderUiCopy(provider);
- }
- if (String(provider || '').trim().toLowerCase() === GMAIL_PROVIDER) {
- return {
- baseLabel: 'Gmail 原邮箱',
- basePlaceholder: '例如 yourname@gmail.com',
- buttonLabel: '生成',
- successVerb: '生成',
- label: 'Gmail +tag 邮箱',
- placeholder: '点击生成 Gmail +tag 邮箱,或手动填写完整邮箱',
- hint: '先填写 Gmail 原邮箱后点“生成”,也可以直接手动填写完整的 Gmail 邮箱。',
- };
- }
- if (String(provider || '').trim().toLowerCase() === '2925') {
- return {
- baseLabel: '2925 基邮箱',
- basePlaceholder: '例如 yourname@2925.com',
- buttonLabel: '生成',
- successVerb: '生成',
- label: '2925 邮箱',
- placeholder: '点击生成 2925 邮箱,或手动填写完整邮箱',
- hint: '先填写 2925 基邮箱后点“生成”,也可以直接手动填写完整的 2925 邮箱。',
- };
- }
- return null;
- }
- function getManagedAliasBaseEmailKey(provider = selectMailProvider.value) {
- const normalizedProvider = String(provider || '').trim().toLowerCase();
- if (normalizedProvider === GMAIL_PROVIDER) {
- return 'gmailBaseEmail';
- }
- if (normalizedProvider === '2925') {
- return 'mail2925BaseEmail';
- }
- return '';
- }
- function getManagedAliasBaseEmailForProvider(provider = selectMailProvider.value, state = latestState) {
- const key = getManagedAliasBaseEmailKey(provider);
- if (!key) {
- return '';
- }
- const providerValue = String(state?.[key] || '').trim();
- if (providerValue) {
- return providerValue;
- }
- const legacyEmailPrefix = String(state?.emailPrefix || '').trim();
- return parseManagedAliasBaseEmail(legacyEmailPrefix, provider) ? legacyEmailPrefix : '';
- }
- function buildManagedAliasBaseEmailPayload(state = latestState) {
- const payload = {
- gmailBaseEmail: String(state?.gmailBaseEmail || '').trim(),
- mail2925BaseEmail: String(state?.mail2925BaseEmail || '').trim(),
- emailPrefix: '',
- };
- const key = getManagedAliasBaseEmailKey();
- if (key) {
- payload[key] = inputEmailPrefix.value.trim();
- }
- return payload;
- }
- function syncManagedAliasBaseEmailDraftFromInput(provider = selectMailProvider.value) {
- const key = getManagedAliasBaseEmailKey(provider);
- if (!key) {
- return;
- }
- syncLatestState({ [key]: inputEmailPrefix.value.trim() });
- }
- function setManagedAliasBaseEmailInputForProvider(provider = selectMailProvider.value, state = latestState) {
- inputEmailPrefix.value = getManagedAliasBaseEmailForProvider(provider, state);
- }
- function getCurrentRegistrationEmailUiCopy() {
- if (isCustomMailProvider()) {
- return getCustomMailProviderUiCopy();
- }
- if (isManagedAliasProvider()) {
- return getManagedAliasProviderUiCopy();
- }
- return getEmailGeneratorUiCopy();
- }
- function isCurrentRegistrationEmailCompatible(email = inputEmail.value.trim(), provider = selectMailProvider.value, state = latestState) {
- if (!isManagedAliasProvider(provider) || !email) {
- return true;
- }
- const baseEmail = getManagedAliasBaseEmailForProvider(provider, state);
- return isManagedAliasEmail(email, baseEmail, provider);
- }
- function validateCurrentRegistrationEmail(email = inputEmail.value.trim(), options = {}) {
- const { showToastOnFailure = false } = options;
- if (isCurrentRegistrationEmailCompatible(email)) {
- return true;
- }
- if (showToastOnFailure) {
- const uiCopy = getManagedAliasProviderUiCopy();
- const baseEmail = getManagedAliasBaseEmailForProvider();
- showToast(
- baseEmail
- ? `当前邮箱服务为“${uiCopy?.label || '别名邮箱'}”,注册邮箱需与 ${uiCopy?.baseLabel || '基邮箱'} 对应。`
- : `当前邮箱服务为“${uiCopy?.label || '别名邮箱'}”,请直接填写完整邮箱,或先填写基邮箱后点击“生成”。`,
- 'warn'
- );
- }
- return false;
- }
- let latestState = null;
- let currentAutoRun = {
- autoRunning: false,
- phase: 'idle',
- currentRun: 0,
- totalRuns: 1,
- attemptRun: 0,
- scheduledAt: null,
- countdownAt: null,
- countdownTitle: '',
- countdownNote: '',
- };
- let settingsDirty = false;
- let settingsSaveInFlight = false;
- let settingsAutoSaveTimer = null;
- let cloudflareDomainEditMode = false;
- let cloudflareTempEmailDomainEditMode = false;
- let modalChoiceResolver = null;
- let currentModalActions = [];
- let modalResultBuilder = null;
- let scheduledCountdownTimer = null;
- let configMenuOpen = false;
- let configActionInFlight = false;
- let currentReleaseSnapshot = null;
- const EYE_OPEN_ICON = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12z"/><circle cx="12" cy="12" r="3"/></svg>';
- const EYE_CLOSED_ICON = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M17.94 17.94A10.94 10.94 0 0 1 12 19C5 19 1 12 1 12a21.77 21.77 0 0 1 5.06-6.94"/><path d="M9.9 4.24A10.94 10.94 0 0 1 12 5c7 0 11 7 11 7a21.86 21.86 0 0 1-2.16 3.19"/><path d="M1 1l22 22"/><path d="M14.12 14.12a3 3 0 1 1-4.24-4.24"/></svg>';
- const COPY_ICON = '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>';
- const parseHotmailImportText = window.HotmailUtils?.parseHotmailImportText;
- const normalizeHotmailServiceModeFromUtils = window.HotmailUtils?.normalizeHotmailServiceMode;
- const shouldClearHotmailCurrentSelection = window.HotmailUtils?.shouldClearHotmailCurrentSelection;
- const upsertHotmailAccountInList = window.HotmailUtils?.upsertHotmailAccountInList;
- const filterHotmailAccountsByUsage = window.HotmailUtils?.filterHotmailAccountsByUsage;
- const getHotmailBulkActionLabel = window.HotmailUtils?.getHotmailBulkActionLabel;
- const getHotmailListToggleLabel = window.HotmailUtils?.getHotmailListToggleLabel;
- const normalizeLuckmailTimestampValue = window.LuckMailUtils?.normalizeTimestamp
- || ((value) => {
- const timestamp = Date.parse(String(value || ''));
- return Number.isFinite(timestamp) ? timestamp : 0;
- });
- const sidepanelUpdateService = window.SidepanelUpdateService;
- const DEFAULT_LUCKMAIL_PRESERVE_TAG_NAME = window.LuckMailUtils?.DEFAULT_LUCKMAIL_PRESERVE_TAG_NAME || '保留';
- const normalizeIcloudHost = window.IcloudUtils?.normalizeIcloudHost
- || ((value) => {
- const normalized = String(value || '').trim().toLowerCase();
- return normalized === 'icloud.com' || normalized === 'icloud.com.cn' ? normalized : '';
- });
- const getIcloudLoginUrlForHost = window.IcloudUtils?.getIcloudLoginUrlForHost
- || ((host) => host === 'icloud.com.cn' ? 'https://www.icloud.com.cn/' : (host === 'icloud.com' ? 'https://www.icloud.com/' : ''));
- btnAutoCancelSchedule?.remove();
- const MAIL_PROVIDER_LOGIN_CONFIGS = {
- [ICLOUD_PROVIDER]: {
- label: 'iCloud 邮箱',
- buttonLabel: '登录',
- },
- [GMAIL_PROVIDER]: {
- label: 'Gmail 邮箱',
- url: 'https://mail.google.com/mail/u/0/#inbox',
- buttonLabel: '登录',
- },
- '163': {
- label: '163 邮箱',
- url: 'https://mail.163.com/',
- buttonLabel: '登录',
- },
- '163-vip': {
- label: '163 VIP 邮箱',
- url: 'https://webmail.vip.163.com/',
- buttonLabel: '登录',
- },
- qq: {
- label: 'QQ 邮箱',
- url: 'https://wx.mail.qq.com/',
- buttonLabel: '登录',
- },
- 'cloudflare-temp-email': {
- label: 'Cloudflare Temp Email GitHub',
- url: 'https://github.com/dreamhunter2333/cloudflare_temp_email',
- buttonLabel: 'GitHub',
- },
- '2925': {
- label: '2925 邮箱',
- url: 'https://2925.com/#/mailList',
- },
- };
- // ============================================================
- // Toast Notifications
- // ============================================================
- const toastContainer = document.getElementById('toast-container');
- const TOAST_ICONS = {
- error: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>',
- warn: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',
- success: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>',
- info: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>',
- };
- const LOG_LEVEL_LABELS = {
- info: '信息',
- ok: '成功',
- warn: '警告',
- error: '错误',
- };
- function usesGeneratedAliasMailProvider(provider, mail2925Mode = getSelectedMail2925Mode()) {
- return isManagedAliasProvider(provider);
- }
- function parseGmailBaseEmail(rawValue = '') {
- const value = String(rawValue || '').trim().toLowerCase();
- const match = value.match(/^([^@\s+]+)@((?:gmail|googlemail)\.com)$/i);
- if (!match) return null;
- return {
- localPart: match[1],
- domain: match[2].toLowerCase(),
- };
- }
- function isManagedGmailAlias(value, baseEmail) {
- const parsedBase = parseGmailBaseEmail(baseEmail);
- if (!parsedBase) return false;
- const match = String(value || '').trim().toLowerCase().match(/^([^@\s+]+)(?:\+[^@\s]+)?@((?:gmail|googlemail)\.com)$/i);
- if (!match) return false;
- return match[1] === parsedBase.localPart && match[2] === parsedBase.domain;
- }
- function showToast(message, type = 'error', duration = 4000) {
- const toast = document.createElement('div');
- toast.className = `toast toast-${type}`;
- toast.innerHTML = `${TOAST_ICONS[type] || ''}<span class="toast-msg">${escapeHtml(message)}</span><button class="toast-close">×</button>`;
- toast.querySelector('.toast-close').addEventListener('click', () => dismissToast(toast));
- toastContainer.appendChild(toast);
- if (duration > 0) {
- setTimeout(() => dismissToast(toast), duration);
- }
- }
- function dismissToast(toast) {
- if (!toast.parentNode) return;
- toast.classList.add('toast-exit');
- toast.addEventListener('animationend', () => toast.remove());
- }
- function resetActionModalOption() {
- if (!modalOptionRow || !modalOptionInput || !modalOptionText) {
- return;
- }
- modalOptionRow.hidden = true;
- modalOptionInput.checked = false;
- modalOptionInput.disabled = false;
- modalOptionText.textContent = '不再提示';
- }
- function resetActionModalAlert() {
- if (!autoStartAlert) {
- return;
- }
- autoStartAlert.hidden = true;
- autoStartAlert.textContent = '';
- autoStartAlert.className = 'modal-alert';
- }
- function resetActionModalButtons() {
- const buttons = [btnAutoStartCancel, btnAutoStartRestart, btnAutoStartContinue];
- buttons.forEach((button) => {
- if (!button) return;
- button.hidden = true;
- button.disabled = false;
- button.onclick = null;
- });
- currentModalActions = [];
- }
- function configureActionModalButton(button, action) {
- if (!button) return;
- if (!action) {
- button.hidden = true;
- button.onclick = null;
- return;
- }
- button.hidden = false;
- button.disabled = false;
- button.textContent = action.label;
- button.className = `btn ${action.variant || 'btn-outline'} btn-sm`;
- button.onclick = () => resolveModalChoice(action.id);
- }
- function configureActionModalOption(option) {
- if (!modalOptionRow || !modalOptionInput || !modalOptionText) {
- return;
- }
- if (!option) {
- resetActionModalOption();
- return;
- }
- modalOptionRow.hidden = false;
- modalOptionInput.checked = Boolean(option.checked);
- modalOptionInput.disabled = Boolean(option.disabled);
- modalOptionText.textContent = option.label || '不再提示';
- }
- function configureActionModalAlert(alert) {
- if (!autoStartAlert) {
- return;
- }
- if (!alert?.text) {
- resetActionModalAlert();
- return;
- }
- autoStartAlert.hidden = false;
- autoStartAlert.textContent = alert.text;
- autoStartAlert.className = `modal-alert${alert.tone === 'danger' ? ' is-danger' : ''}`;
- }
- function resolveModalChoice(choice) {
- const optionChecked = Boolean(modalOptionInput?.checked);
- const result = typeof modalResultBuilder === 'function'
- ? modalResultBuilder(choice, { optionChecked })
- : choice;
- if (modalChoiceResolver) {
- modalChoiceResolver(result);
- modalChoiceResolver = null;
- }
- modalResultBuilder = null;
- resetActionModalButtons();
- resetActionModalAlert();
- resetActionModalOption();
- if (autoStartModal) {
- autoStartModal.hidden = true;
- }
- }
- function openActionModal({ title, message, actions, option, alert, buildResult }) {
- if (!autoStartModal) {
- return Promise.resolve(null);
- }
- if (modalChoiceResolver) {
- resolveModalChoice(null);
- }
- resetActionModalButtons();
- autoStartTitle.textContent = title;
- autoStartMessage.textContent = message;
- currentModalActions = actions || [];
- modalResultBuilder = typeof buildResult === 'function' ? buildResult : null;
- const buttonSlots = currentModalActions.length <= 2
- ? [btnAutoStartCancel, btnAutoStartContinue]
- : [btnAutoStartCancel, btnAutoStartRestart, btnAutoStartContinue];
- buttonSlots.forEach((button, index) => {
- configureActionModalButton(button, currentModalActions[index]);
- });
- configureActionModalAlert(alert);
- configureActionModalOption(option);
- autoStartModal.hidden = false;
- return new Promise((resolve) => {
- modalChoiceResolver = resolve;
- });
- }
- function openAutoStartChoiceDialog(startStep, options = {}) {
- const runningStep = Number.isInteger(options.runningStep) ? options.runningStep : null;
- const continueMessage = runningStep
- ? `继续当前会先等待步骤 ${runningStep} 完成,再按最新进度自动执行。`
- : `继续当前会从步骤 ${startStep} 开始自动执行。`;
- return openActionModal({
- title: '启动自动',
- message: `检测到当前已有流程进度。${continueMessage}重新开始会清空当前流程进度并从步骤 1 新开一轮。`,
- actions: [
- { id: null, label: '取消', variant: 'btn-ghost' },
- { id: 'restart', label: '重新开始', variant: 'btn-outline' },
- { id: 'continue', label: '继续当前', variant: 'btn-primary' },
- ],
- });
- }
- async function openConfirmModal({ title, message, confirmLabel = '确认', confirmVariant = 'btn-primary', alert = null }) {
- const choice = await openActionModal({
- title,
- message,
- alert,
- actions: [
- { id: null, label: '取消', variant: 'btn-ghost' },
- { id: 'confirm', label: confirmLabel, variant: confirmVariant },
- ],
- });
- return choice === 'confirm';
- }
- async function openConfirmModalWithOption({
- title,
- message,
- confirmLabel = '确认',
- confirmVariant = 'btn-primary',
- alert = null,
- optionLabel = '不再提示',
- optionChecked = false,
- optionDisabled = false,
- }) {
- const result = await openActionModal({
- title,
- message,
- alert,
- actions: [
- { id: null, label: '取消', variant: 'btn-ghost' },
- { id: 'confirm', label: confirmLabel, variant: confirmVariant },
- ],
- option: {
- label: optionLabel,
- checked: optionChecked,
- disabled: optionDisabled,
- },
- buildResult: (choice, meta) => ({
- choice,
- optionChecked: Boolean(meta?.optionChecked),
- }),
- });
- return {
- confirmed: result?.choice === 'confirm',
- optionChecked: Boolean(result?.optionChecked),
- };
- }
- function isPromptDismissed(storageKey) {
- return localStorage.getItem(storageKey) === '1';
- }
- function setPromptDismissed(storageKey, dismissed) {
- if (dismissed) {
- localStorage.setItem(storageKey, '1');
- } else {
- localStorage.removeItem(storageKey);
- }
- }
- function isAutoSkipFailuresPromptDismissed() {
- return isPromptDismissed(AUTO_SKIP_FAILURES_PROMPT_DISMISSED_STORAGE_KEY);
- }
- function setAutoSkipFailuresPromptDismissed(dismissed) {
- setPromptDismissed(AUTO_SKIP_FAILURES_PROMPT_DISMISSED_STORAGE_KEY, dismissed);
- }
- function isAutoRunFallbackRiskPromptDismissed() {
- return isPromptDismissed(AUTO_RUN_FALLBACK_RISK_PROMPT_DISMISSED_STORAGE_KEY);
- }
- function setAutoRunFallbackRiskPromptDismissed(dismissed) {
- setPromptDismissed(AUTO_RUN_FALLBACK_RISK_PROMPT_DISMISSED_STORAGE_KEY, dismissed);
- }
- function shouldWarnAutoRunFallbackRisk(totalRuns, autoRunSkipFailures) {
- return totalRuns >= AUTO_RUN_FALLBACK_RISK_WARNING_MIN_RUNS;
- }
- async function openAutoSkipFailuresConfirmModal() {
- const result = await openConfirmModalWithOption({
- title: '自动重试说明',
- message: `开启后,自动模式在某一轮失败时,会先在当前轮自动重试;单轮最多重试 ${AUTO_RUN_MAX_RETRIES_PER_ROUND} 次,仍失败则放弃当前轮并继续下一轮。线程间隔只在开启自动重试且总轮数大于 1 时生效。`,
- confirmLabel: '确认开启',
- });
- return {
- confirmed: result.confirmed,
- dismissPrompt: result.optionChecked,
- };
- }
- async function openAutoRunFallbackRiskConfirmModal(totalRuns, fallbackThreadIntervalMinutes) {
- const intervalLabel = Number.isFinite(fallbackThreadIntervalMinutes)
- ? `${fallbackThreadIntervalMinutes} 分钟`
- : '未设置';
- const result = await openConfirmModalWithOption({
- title: '自动运行风险提醒',
- message: `当前设置为 ${totalRuns} 轮自动化,已开启自动重试,线程间隔为 ${intervalLabel}。轮数过多时,可能会因为 IP 短时间注册过多而集中失败。建议控制在 ${AUTO_RUN_FALLBACK_RISK_WARNING_MIN_RUNS} 轮以下,并将线程间隔设置在 ${AUTO_RUN_FALLBACK_RISK_RECOMMENDED_THREAD_INTERVAL_MINUTES} 分钟以上。是否继续?`,
- confirmLabel: '继续',
- });
- return {
- confirmed: result.confirmed,
- dismissPrompt: result.optionChecked,
- };
- }
- function updateConfigMenuControls() {
- const disabled = configActionInFlight || settingsSaveInFlight;
- const importLocked = disabled
- || currentAutoRun.autoRunning
- || Object.values(getStepStatuses()).some((status) => status === 'running');
- if (btnConfigMenu) {
- btnConfigMenu.disabled = disabled;
- btnConfigMenu.setAttribute('aria-expanded', String(configMenuOpen));
- }
- if (configMenu) {
- configMenu.hidden = !configMenuOpen;
- }
- if (btnExportSettings) {
- btnExportSettings.disabled = disabled;
- }
- if (btnImportSettings) {
- btnImportSettings.disabled = importLocked;
- }
- }
- function closeConfigMenu() {
- configMenuOpen = false;
- updateConfigMenuControls();
- }
- function openConfigMenu() {
- configMenuOpen = true;
- updateConfigMenuControls();
- }
- function toggleConfigMenu() {
- configMenuOpen ? closeConfigMenu() : openConfigMenu();
- }
- async function waitForSettingsSaveIdle() {
- while (settingsSaveInFlight) {
- await new Promise((resolve) => setTimeout(resolve, 50));
- }
- }
- async function flushPendingSettingsBeforeExport() {
- clearTimeout(settingsAutoSaveTimer);
- await waitForSettingsSaveIdle();
- if (settingsDirty) {
- await saveSettings({ silent: true });
- }
- }
- async function settlePendingSettingsBeforeImport() {
- clearTimeout(settingsAutoSaveTimer);
- await waitForSettingsSaveIdle();
- }
- function downloadTextFile(content, fileName, mimeType = 'application/json;charset=utf-8') {
- const blob = new Blob([content], { type: mimeType });
- const objectUrl = URL.createObjectURL(blob);
- const anchor = document.createElement('a');
- anchor.href = objectUrl;
- anchor.download = fileName;
- document.body.appendChild(anchor);
- anchor.click();
- anchor.remove();
- setTimeout(() => URL.revokeObjectURL(objectUrl), 0);
- }
- function isDoneStatus(status) {
- return status === 'completed' || status === 'manual_completed' || status === 'skipped';
- }
- function getStepStatuses(state = latestState) {
- return { ...STEP_DEFAULT_STATUSES, ...(state?.stepStatuses || {}) };
- }
- function getFirstUnfinishedStep(state = latestState) {
- const statuses = getStepStatuses(state);
- for (let step = 1; step <= 9; step++) {
- if (!isDoneStatus(statuses[step])) {
- return step;
- }
- }
- return null;
- }
- function getRunningSteps(state = latestState) {
- const statuses = getStepStatuses(state);
- return Object.entries(statuses)
- .filter(([, status]) => status === 'running')
- .map(([step]) => Number(step))
- .sort((a, b) => a - b);
- }
- function hasSavedProgress(state = latestState) {
- const statuses = getStepStatuses(state);
- return Object.values(statuses).some((status) => status !== 'pending');
- }
- function shouldOfferAutoModeChoice(state = latestState) {
- return hasSavedProgress(state) && getFirstUnfinishedStep(state) !== null;
- }
- function syncLatestState(nextState) {
- const mergedStepStatuses = nextState?.stepStatuses
- ? { ...STEP_DEFAULT_STATUSES, ...(latestState?.stepStatuses || {}), ...nextState.stepStatuses }
- : getStepStatuses(latestState);
- latestState = {
- ...(latestState || {}),
- ...(nextState || {}),
- stepStatuses: mergedStepStatuses,
- };
- renderAccountRunHistory(latestState);
- }
- function hasOwnStateValue(source, key) {
- return Object.prototype.hasOwnProperty.call(source, key);
- }
- function readAutoRunStateValue(source, keys, fallback) {
- for (const key of keys) {
- if (hasOwnStateValue(source, key)) {
- return source[key];
- }
- }
- return fallback;
- }
- function syncAutoRunState(source = {}) {
- const phase = source.autoRunPhase ?? source.phase ?? currentAutoRun.phase;
- const autoRunning = source.autoRunning !== undefined
- ? Boolean(source.autoRunning)
- : (source.autoRunPhase !== undefined || source.phase !== undefined
- ? ['scheduled', 'running', 'waiting_step', 'waiting_email', 'retrying', 'waiting_interval'].includes(phase)
- : currentAutoRun.autoRunning);
- currentAutoRun = {
- autoRunning,
- phase,
- currentRun: readAutoRunStateValue(source, ['autoRunCurrentRun', 'currentRun'], currentAutoRun.currentRun),
- totalRuns: readAutoRunStateValue(source, ['autoRunTotalRuns', 'totalRuns'], currentAutoRun.totalRuns),
- attemptRun: readAutoRunStateValue(source, ['autoRunAttemptRun', 'attemptRun'], currentAutoRun.attemptRun),
- scheduledAt: readAutoRunStateValue(source, ['scheduledAutoRunAt', 'scheduledAt'], currentAutoRun.scheduledAt),
- countdownAt: readAutoRunStateValue(source, ['autoRunCountdownAt', 'countdownAt'], currentAutoRun.countdownAt),
- countdownTitle: readAutoRunStateValue(source, ['autoRunCountdownTitle', 'countdownTitle'], currentAutoRun.countdownTitle),
- countdownNote: readAutoRunStateValue(source, ['autoRunCountdownNote', 'countdownNote'], currentAutoRun.countdownNote),
- };
- }
- function isAutoRunLockedPhase() {
- return currentAutoRun.phase === 'running'
- || currentAutoRun.phase === 'waiting_step'
- || currentAutoRun.phase === 'retrying'
- || currentAutoRun.phase === 'waiting_interval';
- }
- function isAutoRunPausedPhase() {
- return currentAutoRun.phase === 'waiting_email';
- }
- function isAutoRunWaitingStepPhase() {
- return currentAutoRun.phase === 'waiting_step';
- }
- function isAutoRunScheduledPhase() {
- return currentAutoRun.phase === 'scheduled';
- }
- function getAutoRunLabel(payload = currentAutoRun) {
- if ((payload.phase ?? currentAutoRun.phase) === 'scheduled') {
- return (payload.totalRuns || 1) > 1 ? ` (${payload.totalRuns}轮)` : '';
- }
- const attemptLabel = payload.attemptRun ? ` · 尝试${payload.attemptRun}` : '';
- if ((payload.totalRuns || 1) > 1) {
- return ` (${payload.currentRun}/${payload.totalRuns}${attemptLabel})`;
- }
- return attemptLabel ? ` (${attemptLabel.slice(3)})` : '';
- }
- function normalizeAutoDelayMinutes(value) {
- const numeric = Number(value);
- if (!Number.isFinite(numeric)) {
- return AUTO_DELAY_DEFAULT_MINUTES;
- }
- return Math.min(AUTO_DELAY_MAX_MINUTES, Math.max(AUTO_DELAY_MIN_MINUTES, Math.floor(numeric)));
- }
- function normalizeAutoRunThreadIntervalMinutes(value) {
- const rawValue = String(value ?? '').trim();
- if (!rawValue) {
- return AUTO_FALLBACK_THREAD_INTERVAL_DEFAULT_MINUTES;
- }
- const numeric = Number(rawValue);
- if (!Number.isFinite(numeric)) {
- return AUTO_FALLBACK_THREAD_INTERVAL_DEFAULT_MINUTES;
- }
- return Math.min(
- AUTO_FALLBACK_THREAD_INTERVAL_MAX_MINUTES,
- Math.max(AUTO_FALLBACK_THREAD_INTERVAL_MIN_MINUTES, Math.floor(numeric))
- );
- }
- function normalizeAutoStepDelaySeconds(value) {
- const rawValue = String(value ?? '').trim();
- if (!rawValue) {
- return null;
- }
- const numeric = Number(rawValue);
- if (!Number.isFinite(numeric)) {
- return null;
- }
- return Math.min(AUTO_STEP_DELAY_MAX_SECONDS, Math.max(AUTO_STEP_DELAY_MIN_SECONDS, Math.floor(numeric)));
- }
- function formatAutoStepDelayInputValue(value) {
- const normalized = normalizeAutoStepDelaySeconds(value);
- return normalized === null ? '' : String(normalized);
- }
- function getRunCountValue() {
- return Math.min(50, Math.max(1, parseInt(inputRunCount.value, 10) || 1));
- }
- function updateFallbackThreadIntervalInputState() {
- if (!inputAutoSkipFailuresThreadIntervalMinutes) {
- return;
- }
- inputAutoSkipFailuresThreadIntervalMinutes.disabled = Boolean(inputAutoSkipFailures.disabled);
- }
- function updateAutoDelayInputState() {
- const scheduled = isAutoRunScheduledPhase();
- inputAutoDelayEnabled.disabled = scheduled;
- inputAutoDelayMinutes.disabled = scheduled || !inputAutoDelayEnabled.checked;
- }
- function formatCountdown(remainingMs) {
- const totalSeconds = Math.max(0, Math.ceil(remainingMs / 1000));
- const hours = Math.floor(totalSeconds / 3600);
- const minutes = Math.floor((totalSeconds % 3600) / 60);
- const seconds = totalSeconds % 60;
- return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
- }
- function formatScheduleTime(timestamp) {
- return new Date(timestamp).toLocaleString('zh-CN', {
- hour12: false,
- timeZone: DISPLAY_TIMEZONE,
- month: '2-digit',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit',
- second: '2-digit',
- });
- }
- function stopScheduledCountdownTicker() {
- clearInterval(scheduledCountdownTimer);
- scheduledCountdownTimer = null;
- }
- function getActiveAutoRunCountdown() {
- if (isAutoRunScheduledPhase() && Number.isFinite(currentAutoRun.scheduledAt)) {
- return {
- at: currentAutoRun.scheduledAt,
- title: '已计划自动运行',
- note: `计划于 ${formatScheduleTime(currentAutoRun.scheduledAt)} 开始`,
- tone: 'scheduled',
- };
- }
- if (!Number.isFinite(currentAutoRun.countdownAt)) {
- return null;
- }
- return {
- at: currentAutoRun.countdownAt,
- title: currentAutoRun.countdownTitle || '等待中',
- note: currentAutoRun.countdownNote || '',
- tone: 'running',
- };
- }
- function renderScheduledAutoRunInfo() {
- if (!autoScheduleBar) {
- return;
- }
- const countdown = getActiveAutoRunCountdown();
- if (!countdown) {
- autoScheduleBar.style.display = 'none';
- return;
- }
- const remainingMs = countdown.at - Date.now();
- autoScheduleBar.style.display = 'flex';
- if (btnAutoRunNow) {
- btnAutoRunNow.hidden = false;
- btnAutoRunNow.textContent = currentAutoRun.phase === 'waiting_interval' ? '立即继续' : '立即开始';
- }
- if (btnAutoCancelSchedule) {
- btnAutoCancelSchedule.hidden = true;
- }
- autoScheduleTitle.textContent = countdown.title;
- autoScheduleMeta.textContent = remainingMs > 0
- ? `${countdown.note ? `${countdown.note},` : ''}剩余 ${formatCountdown(remainingMs)}`
- : '倒计时即将结束,正在准备继续...';
- return;
- }
- function syncScheduledCountdownTicker() {
- renderScheduledAutoRunInfo();
- if (getActiveAutoRunCountdown()) {
- if (scheduledCountdownTimer) {
- return;
- }
- scheduledCountdownTimer = setInterval(() => {
- renderScheduledAutoRunInfo();
- updateStatusDisplay(latestState);
- }, 1000);
- return;
- }
- stopScheduledCountdownTicker();
- return;
- }
- function setDefaultAutoRunButton() {
- btnAutoRun.disabled = false;
- inputRunCount.disabled = false;
- btnAutoRun.innerHTML = '<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><polygon points="5 3 19 12 5 21 5 3"/></svg> 自动';
- }
- function normalizeCloudflareDomainValue(value = '') {
- let normalized = String(value || '').trim().toLowerCase();
- if (!normalized) return '';
- normalized = normalized.replace(/^@+/, '');
- normalized = normalized.replace(/^https?:\/\//, '');
- normalized = normalized.replace(/\/.*$/, '');
- if (!/^[a-z0-9.-]+\.[a-z]{2,}$/.test(normalized)) {
- return '';
- }
- return normalized;
- }
- function normalizeCloudflareDomains(values = []) {
- const seen = new Set();
- const domains = [];
- for (const value of Array.isArray(values) ? values : []) {
- const normalized = normalizeCloudflareDomainValue(value);
- if (!normalized || seen.has(normalized)) continue;
- seen.add(normalized);
- domains.push(normalized);
- }
- return domains;
- }
- function normalizeCloudflareTempEmailBaseUrlValue(value = '') {
- const raw = String(value || '').trim();
- if (!raw) return '';
- const candidate = /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(raw) ? raw : `https://${raw}`;
- try {
- const parsed = new URL(candidate);
- parsed.hash = '';
- parsed.search = '';
- const pathname = parsed.pathname === '/' ? '' : parsed.pathname.replace(/\/+$/, '');
- return `${parsed.origin}${pathname}`;
- } catch {
- return '';
- }
- }
- function normalizeCloudflareTempEmailReceiveMailboxValue(value = '') {
- const normalized = String(value || '').trim().toLowerCase();
- if (!normalized) return '';
- return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalized) ? normalized : '';
- }
- function normalizeCloudflareTempEmailDomainValue(value = '') {
- return normalizeCloudflareDomainValue(value);
- }
- function normalizeCloudflareTempEmailDomains(values = []) {
- const seen = new Set();
- const domains = [];
- for (const value of Array.isArray(values) ? values : []) {
- const normalized = normalizeCloudflareTempEmailDomainValue(value);
- if (!normalized || seen.has(normalized)) continue;
- seen.add(normalized);
- domains.push(normalized);
- }
- return domains;
- }
- function getCloudflareDomainsFromState() {
- const domains = normalizeCloudflareDomains(latestState?.cloudflareDomains || []);
- const activeDomain = normalizeCloudflareDomainValue(latestState?.cloudflareDomain || '');
- if (activeDomain && !domains.includes(activeDomain)) {
- domains.unshift(activeDomain);
- }
- return { domains, activeDomain: activeDomain || domains[0] || '' };
- }
- function getCloudflareTempEmailDomainsFromState() {
- const domains = normalizeCloudflareTempEmailDomains(latestState?.cloudflareTempEmailDomains || []);
- const activeDomain = normalizeCloudflareTempEmailDomainValue(latestState?.cloudflareTempEmailDomain || '');
- if (activeDomain && !domains.includes(activeDomain)) {
- domains.unshift(activeDomain);
- }
- return { domains, activeDomain: activeDomain || domains[0] || '' };
- }
- function renderCloudflareDomainOptions(preferredDomain = '') {
- const preferred = normalizeCloudflareDomainValue(preferredDomain);
- const { domains, activeDomain } = getCloudflareDomainsFromState();
- const selected = preferred || activeDomain;
- selectCfDomain.innerHTML = '';
- if (domains.length === 0) {
- const option = document.createElement('option');
- option.value = '';
- option.textContent = '请先添加域名';
- selectCfDomain.appendChild(option);
- selectCfDomain.disabled = true;
- selectCfDomain.value = '';
- return;
- }
- for (const domain of domains) {
- const option = document.createElement('option');
- option.value = domain;
- option.textContent = domain;
- selectCfDomain.appendChild(option);
- }
- selectCfDomain.disabled = false;
- selectCfDomain.value = domains.includes(selected) ? selected : domains[0];
- }
- function renderCloudflareTempEmailDomainOptions(preferredDomain = '') {
- const preferred = normalizeCloudflareTempEmailDomainValue(preferredDomain);
- const { domains, activeDomain } = getCloudflareTempEmailDomainsFromState();
- const selected = preferred || activeDomain;
- selectTempEmailDomain.innerHTML = '';
- if (domains.length === 0) {
- const option = document.createElement('option');
- option.value = '';
- option.textContent = '请先添加域名';
- selectTempEmailDomain.appendChild(option);
- selectTempEmailDomain.disabled = true;
- selectTempEmailDomain.value = '';
- return;
- }
- for (const domain of domains) {
- const option = document.createElement('option');
- option.value = domain;
- option.textContent = domain;
- selectTempEmailDomain.appendChild(option);
- }
- selectTempEmailDomain.disabled = false;
- selectTempEmailDomain.value = domains.includes(selected) ? selected : domains[0];
- }
- function setCloudflareDomainEditMode(editing, options = {}) {
- const { clearInput = false } = options;
- cloudflareDomainEditMode = Boolean(editing);
- selectCfDomain.style.display = cloudflareDomainEditMode ? 'none' : '';
- inputCfDomain.style.display = cloudflareDomainEditMode ? '' : 'none';
- btnCfDomainMode.textContent = cloudflareDomainEditMode ? '保存' : '添加';
- if (cloudflareDomainEditMode) {
- if (clearInput) {
- inputCfDomain.value = '';
- }
- inputCfDomain.focus();
- } else if (clearInput) {
- inputCfDomain.value = '';
- }
- }
- function setCloudflareTempEmailDomainEditMode(editing, options = {}) {
- const { clearInput = false } = options;
- cloudflareTempEmailDomainEditMode = Boolean(editing);
- selectTempEmailDomain.style.display = cloudflareTempEmailDomainEditMode ? 'none' : '';
- inputTempEmailDomain.style.display = cloudflareTempEmailDomainEditMode ? '' : 'none';
- btnTempEmailDomainMode.textContent = cloudflareTempEmailDomainEditMode ? '保存' : '添加';
- if (cloudflareTempEmailDomainEditMode) {
- if (clearInput) {
- inputTempEmailDomain.value = '';
- }
- inputTempEmailDomain.focus();
- } else if (clearInput) {
- inputTempEmailDomain.value = '';
- }
- }
- function collectSettingsPayload() {
- const { domains, activeDomain } = getCloudflareDomainsFromState();
- const selectedCloudflareDomain = normalizeCloudflareDomainValue(
- !cloudflareDomainEditMode ? selectCfDomain.value : activeDomain
- ) || activeDomain;
- const { domains: tempEmailDomains, activeDomain: tempEmailActiveDomain } = getCloudflareTempEmailDomainsFromState();
- const selectedCloudflareTempEmailDomain = normalizeCloudflareTempEmailDomainValue(
- !cloudflareTempEmailDomainEditMode ? selectTempEmailDomain.value : tempEmailActiveDomain
- ) || tempEmailActiveDomain;
- return {
- panelMode: selectPanelMode.value,
- vpsUrl: inputVpsUrl.value.trim(),
- vpsPassword: inputVpsPassword.value,
- localCpaStep9Mode: getSelectedLocalCpaStep9Mode(),
- cpaCallbackMode: getSelectedCpaCallbackMode(),
- sub2apiUrl: inputSub2ApiUrl.value.trim(),
- sub2apiEmail: inputSub2ApiEmail.value.trim(),
- sub2apiPassword: inputSub2ApiPassword.value,
- sub2apiGroupName: inputSub2ApiGroup.value.trim(),
- customPassword: inputPassword.value,
- mailProvider: selectMailProvider.value,
- mail2925Mode: getSelectedMail2925Mode(),
- emailGenerator: selectEmailGenerator.value,
- autoDeleteUsedIcloudAlias: checkboxAutoDeleteIcloud?.checked,
- icloudHostPreference: selectIcloudHostPreference?.value || 'auto',
- accountRunHistoryTextEnabled: Boolean(inputAccountRunHistoryTextEnabled?.checked),
- accountRunHistoryHelperBaseUrl: normalizeAccountRunHistoryHelperBaseUrlValue(inputAccountRunHistoryHelperBaseUrl?.value),
- ...buildManagedAliasBaseEmailPayload(),
- inbucketHost: inputInbucketHost.value.trim(),
- inbucketMailbox: inputInbucketMailbox.value.trim(),
- hotmailServiceMode: getSelectedHotmailServiceMode(),
- hotmailRemoteBaseUrl: inputHotmailRemoteBaseUrl.value.trim(),
- hotmailLocalBaseUrl: inputHotmailLocalBaseUrl.value.trim(),
- luckmailApiKey: inputLuckmailApiKey.value,
- luckmailBaseUrl: normalizeLuckmailBaseUrl(inputLuckmailBaseUrl.value),
- luckmailEmailType: normalizeLuckmailEmailType(selectLuckmailEmailType.value),
- luckmailDomain: inputLuckmailDomain.value.trim(),
- cloudflareDomain: selectedCloudflareDomain,
- cloudflareDomains: domains,
- cloudflareTempEmailBaseUrl: normalizeCloudflareTempEmailBaseUrlValue(inputTempEmailBaseUrl.value),
- cloudflareTempEmailAdminAuth: inputTempEmailAdminAuth.value,
- cloudflareTempEmailCustomAuth: inputTempEmailCustomAuth.value,
- cloudflareTempEmailReceiveMailbox: normalizeCloudflareTempEmailReceiveMailboxValue(inputTempEmailReceiveMailbox.value),
- cloudflareTempEmailDomain: selectedCloudflareTempEmailDomain,
- cloudflareTempEmailDomains: tempEmailDomains,
- autoRunSkipFailures: inputAutoSkipFailures.checked,
- autoRunFallbackThreadIntervalMinutes: normalizeAutoRunThreadIntervalMinutes(inputAutoSkipFailuresThreadIntervalMinutes.value),
- autoRunDelayEnabled: inputAutoDelayEnabled.checked,
- autoRunDelayMinutes: normalizeAutoDelayMinutes(inputAutoDelayMinutes.value),
- autoStepDelaySeconds: normalizeAutoStepDelaySeconds(inputAutoStepDelaySeconds.value),
- };
- }
- function normalizeLocalCpaStep9Mode(value = '') {
- return String(value || '').trim().toLowerCase() === 'bypass'
- ? 'bypass'
- : DEFAULT_LOCAL_CPA_STEP9_MODE;
- }
- function normalizeCpaCallbackMode(value = '') {
- return String(value || '').trim().toLowerCase() === 'step6'
- ? 'step6'
- : DEFAULT_CPA_CALLBACK_MODE;
- }
- function normalizeMail2925Mode(value = '') {
- return String(value || '').trim().toLowerCase() === MAIL_2925_MODE_RECEIVE
- ? MAIL_2925_MODE_RECEIVE
- : DEFAULT_MAIL_2925_MODE;
- }
- function normalizeHotmailServiceMode(value = '') {
- if (typeof normalizeHotmailServiceModeFromUtils === 'function') {
- return normalizeHotmailServiceModeFromUtils(value);
- }
- return String(value || '').trim().toLowerCase() === HOTMAIL_SERVICE_MODE_REMOTE
- ? HOTMAIL_SERVICE_MODE_REMOTE
- : HOTMAIL_SERVICE_MODE_LOCAL;
- }
- function normalizeAccountRunHistoryHelperBaseUrlValue(value = '') {
- const trimmed = String(value || '').trim();
- if (!trimmed) {
- return DEFAULT_ACCOUNT_RUN_HISTORY_HELPER_BASE_URL;
- }
- try {
- const parsed = new URL(trimmed);
- if (!['http:', 'https:'].includes(parsed.protocol)) {
- return DEFAULT_ACCOUNT_RUN_HISTORY_HELPER_BASE_URL;
- }
- if (parsed.pathname === '/append-account-log') {
- parsed.pathname = '';
- parsed.search = '';
- parsed.hash = '';
- }
- return parsed.toString().replace(/\/$/, '');
- } catch {
- return DEFAULT_ACCOUNT_RUN_HISTORY_HELPER_BASE_URL;
- }
- }
- function getSelectedLocalCpaStep9Mode() {
- const activeButton = localCpaStep9ModeButtons.find((button) => button.classList.contains('is-active'));
- return normalizeLocalCpaStep9Mode(activeButton?.dataset.localCpaStep9Mode);
- }
- function setLocalCpaStep9Mode(mode) {
- const resolvedMode = normalizeLocalCpaStep9Mode(mode);
- localCpaStep9ModeButtons.forEach((button) => {
- const active = button.dataset.localCpaStep9Mode === resolvedMode;
- button.classList.toggle('is-active', active);
- button.setAttribute('aria-pressed', String(active));
- });
- }
- function getSelectedCpaCallbackMode() {
- const activeButton = cpaCallbackModeButtons.find((button) => button.classList.contains('is-active'));
- return normalizeCpaCallbackMode(activeButton?.dataset.cpaCallbackMode);
- }
- function setCpaCallbackMode(mode) {
- const resolvedMode = normalizeCpaCallbackMode(mode);
- cpaCallbackModeButtons.forEach((button) => {
- const active = button.dataset.cpaCallbackMode === resolvedMode;
- button.classList.toggle('is-active', active);
- button.setAttribute('aria-pressed', String(active));
- });
- }
- function getSelectedMail2925Mode() {
- const activeButton = mail2925ModeButtons.find((button) => button.classList.contains('is-active'));
- return normalizeMail2925Mode(activeButton?.dataset.mail2925Mode);
- }
- function setMail2925Mode(mode) {
- const resolvedMode = normalizeMail2925Mode(mode);
- mail2925ModeButtons.forEach((button) => {
- const active = button.dataset.mail2925Mode === resolvedMode;
- button.classList.toggle('is-active', active);
- button.setAttribute('aria-pressed', String(active));
- });
- }
- function getSelectedHotmailServiceMode() {
- const activeButton = hotmailServiceModeButtons.find((button) => button.classList.contains('is-active'));
- return normalizeHotmailServiceMode(activeButton?.dataset.hotmailServiceMode);
- }
- function setHotmailServiceMode(mode) {
- const resolvedMode = normalizeHotmailServiceMode(mode);
- hotmailServiceModeButtons.forEach((button) => {
- const active = button.dataset.hotmailServiceMode === resolvedMode;
- button.disabled = false;
- button.setAttribute('aria-disabled', 'false');
- button.classList.toggle('is-active', active);
- button.setAttribute('aria-pressed', String(active));
- });
- }
- function updateAccountRunHistorySettingsUI() {
- if (!rowAccountRunHistoryHelperBaseUrl || !inputAccountRunHistoryTextEnabled) {
- return;
- }
- rowAccountRunHistoryHelperBaseUrl.style.display = inputAccountRunHistoryTextEnabled.checked ? '' : 'none';
- }
- function setSettingsCardLocked(locked) {
- if (!settingsCard) {
- return;
- }
- settingsCard.classList.toggle('is-locked', locked);
- settingsCard.toggleAttribute('inert', locked);
- }
- async function setRuntimeEmailState(email) {
- const normalizedEmail = String(email || '').trim() || null;
- const response = await chrome.runtime.sendMessage({
- type: 'SET_EMAIL_STATE',
- source: 'sidepanel',
- payload: { email: normalizedEmail },
- });
- if (response?.error) {
- throw new Error(response.error);
- }
- return normalizedEmail;
- }
- async function clearRegistrationEmail(options = {}) {
- const { silent = false } = options;
- if (!inputEmail.value.trim() && !latestState?.email) {
- return;
- }
- inputEmail.value = '';
- syncLatestState({ email: null });
- try {
- await setRuntimeEmailState(null);
- } catch (err) {
- if (!silent) {
- showToast(`清空邮箱失败:${err.message}`, 'error');
- }
- throw err;
- }
- }
- function markSettingsDirty(isDirty = true) {
- settingsDirty = isDirty;
- updateSaveButtonState();
- }
- function updateSaveButtonState() {
- btnSaveSettings.disabled = settingsSaveInFlight || !settingsDirty;
- updateConfigMenuControls();
- btnSaveSettings.textContent = settingsSaveInFlight ? '保存中' : '保存';
- }
- function scheduleSettingsAutoSave() {
- clearTimeout(settingsAutoSaveTimer);
- settingsAutoSaveTimer = setTimeout(() => {
- saveSettings({ silent: true }).catch(() => { });
- }, 500);
- }
- async function saveSettings(options = {}) {
- const { silent = false } = options;
- clearTimeout(settingsAutoSaveTimer);
- if (!settingsDirty && !settingsSaveInFlight && silent) {
- return;
- }
- const payload = collectSettingsPayload();
- settingsSaveInFlight = true;
- updateSaveButtonState();
- try {
- const response = await chrome.runtime.sendMessage({
- type: 'SAVE_SETTING',
- source: 'sidepanel',
- payload,
- });
- if (response?.error) {
- throw new Error(response.error);
- }
- if (response?.state) {
- applySettingsState(response.state);
- } else {
- syncLatestState(payload);
- markSettingsDirty(false);
- updatePanelModeUI();
- updateMailProviderUI();
- updateButtonStates();
- }
- if (!silent) {
- showToast('配置已保存', 'success', 1800);
- }
- } catch (err) {
- markSettingsDirty(true);
- if (!silent) {
- showToast(`保存失败:${err.message}`, 'error');
- }
- throw err;
- } finally {
- settingsSaveInFlight = false;
- updateSaveButtonState();
- }
- }
- function applyAutoRunStatus(payload = currentAutoRun) {
- syncAutoRunState(payload);
- const runLabel = getAutoRunLabel(currentAutoRun);
- const locked = isAutoRunLockedPhase();
- const paused = isAutoRunPausedPhase();
- const scheduled = isAutoRunScheduledPhase();
- const settingsCardLocked = scheduled || locked;
- setSettingsCardLocked(settingsCardLocked);
- inputRunCount.disabled = currentAutoRun.autoRunning;
- btnAutoRun.disabled = currentAutoRun.autoRunning;
- btnFetchEmail.disabled = locked
- || isCustomMailProvider();
- inputEmail.disabled = locked;
- inputAutoSkipFailures.disabled = scheduled;
- if (currentAutoRun.totalRuns > 0) {
- inputRunCount.value = String(currentAutoRun.totalRuns);
- }
- switch (currentAutoRun.phase) {
- case 'scheduled':
- autoContinueBar.style.display = 'none';
- btnAutoRun.innerHTML = `已计划${runLabel}`;
- break;
- case 'waiting_step':
- autoContinueBar.style.display = 'none';
- btnAutoRun.innerHTML = `等待中${runLabel}`;
- break;
- case 'waiting_email':
- autoContinueBar.style.display = 'flex';
- btnAutoRun.innerHTML = `已暂停${runLabel}`;
- break;
- case 'running':
- autoContinueBar.style.display = 'none';
- btnAutoRun.innerHTML = `运行中${runLabel}`;
- break;
- case 'retrying':
- autoContinueBar.style.display = 'none';
- btnAutoRun.innerHTML = `重试中${runLabel}`;
- break;
- case 'waiting_interval':
- autoContinueBar.style.display = 'none';
- btnAutoRun.innerHTML = `等待中${runLabel}`;
- break;
- default:
- autoContinueBar.style.display = 'none';
- setDefaultAutoRunButton();
- inputEmail.disabled = false;
- if (!locked) {
- btnFetchEmail.disabled = isCustomMailProvider();
- }
- break;
- }
- updateAutoDelayInputState();
- updateFallbackThreadIntervalInputState();
- syncScheduledCountdownTicker();
- updateStopButtonState(scheduled || paused || locked || Object.values(getStepStatuses()).some(status => status === 'running'));
- updateConfigMenuControls();
- }
- function initializeManualStepActions() {
- document.querySelectorAll('.step-row').forEach((row) => {
- const step = Number(row.dataset.step);
- const statusEl = row.querySelector('.step-status');
- if (!statusEl) return;
- const actions = document.createElement('div');
- actions.className = 'step-actions';
- const manualBtn = document.createElement('button');
- manualBtn.type = 'button';
- manualBtn.className = 'step-manual-btn';
- manualBtn.dataset.step = String(step);
- manualBtn.title = '跳过此步';
- manualBtn.setAttribute('aria-label', `跳过步骤 ${step}`);
- manualBtn.innerHTML = '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="13 17 18 12 13 7"/><polyline points="6 17 11 12 6 7"/></svg>';
- manualBtn.addEventListener('click', async (event) => {
- event.stopPropagation();
- try {
- await handleSkipStep(step);
- } catch (err) {
- showToast(err.message, 'error');
- }
- });
- statusEl.parentNode.replaceChild(actions, statusEl);
- actions.appendChild(manualBtn);
- actions.appendChild(statusEl);
- });
- }
- function renderStepsList() {
- if (!stepsList) return;
- stepsList.innerHTML = stepDefinitions.map((step) => `
- <div class="step-row" data-step="${step.id}" data-step-key="${escapeHtml(step.key)}">
- <div class="step-indicator" data-step="${step.id}"><span class="step-num">${step.id}</span></div>
- <button class="step-btn" data-step="${step.id}" data-step-key="${escapeHtml(step.key)}">${escapeHtml(step.title)}</button>
- <span class="step-status" data-step="${step.id}"></span>
- </div>
- `).join('');
- if (stepsProgress) {
- stepsProgress.textContent = `0 / ${STEP_IDS.length}`;
- }
- }
- // ============================================================
- // State Restore on load
- // ============================================================
- function applySettingsState(state) {
- syncLatestState(state);
- syncAutoRunState(state);
- inputEmail.value = state?.email || '';
- syncPasswordField(state || {});
- inputVpsUrl.value = state?.vpsUrl || '';
- inputVpsPassword.value = state?.vpsPassword || '';
- setLocalCpaStep9Mode(state?.localCpaStep9Mode);
- setCpaCallbackMode(state?.cpaCallbackMode);
- selectPanelMode.value = state?.panelMode || 'cpa';
- inputSub2ApiUrl.value = state?.sub2apiUrl || '';
- inputSub2ApiEmail.value = state?.sub2apiEmail || '';
- inputSub2ApiPassword.value = state?.sub2apiPassword || '';
- inputSub2ApiGroup.value = state?.sub2apiGroupName || '';
- const restoredMailProvider = isCustomMailProvider(state?.mailProvider)
- || [ICLOUD_PROVIDER, 'hotmail-api', GMAIL_PROVIDER, 'luckmail-api', '163', '163-vip', 'qq', 'inbucket', '2925', 'cloudflare-temp-email'].includes(String(state?.mailProvider || '').trim())
- ? String(state?.mailProvider || '163').trim()
- : (String(state?.emailGenerator || '').trim().toLowerCase() === 'custom'
- || String(state?.emailGenerator || '').trim().toLowerCase() === 'manual'
- ? 'custom'
- : '163');
- selectMailProvider.value = restoredMailProvider;
- setMail2925Mode(state?.mail2925Mode);
- {
- const restoredEmailGenerator = String(state?.emailGenerator || '').trim().toLowerCase();
- if (restoredEmailGenerator === 'icloud') {
- selectEmailGenerator.value = 'icloud';
- } else if (restoredEmailGenerator === 'cloudflare') {
- selectEmailGenerator.value = 'cloudflare';
- } else if (restoredEmailGenerator === 'cloudflare-temp-email') {
- selectEmailGenerator.value = 'cloudflare-temp-email';
- } else {
- selectEmailGenerator.value = 'duck';
- }
- }
- if (selectIcloudHostPreference) {
- selectIcloudHostPreference.value = String(state?.icloudHostPreference || '').trim().toLowerCase() === 'icloud.com'
- ? 'icloud.com'
- : (String(state?.icloudHostPreference || '').trim().toLowerCase() === 'icloud.com.cn' ? 'icloud.com.cn' : 'auto');
- }
- if (checkboxAutoDeleteIcloud) {
- checkboxAutoDeleteIcloud.checked = Boolean(state?.autoDeleteUsedIcloudAlias);
- }
- if (inputAccountRunHistoryTextEnabled) {
- inputAccountRunHistoryTextEnabled.checked = Boolean(state?.accountRunHistoryTextEnabled);
- }
- if (inputAccountRunHistoryHelperBaseUrl) {
- inputAccountRunHistoryHelperBaseUrl.value = normalizeAccountRunHistoryHelperBaseUrlValue(state?.accountRunHistoryHelperBaseUrl);
- }
- setManagedAliasBaseEmailInputForProvider(restoredMailProvider, state);
- inputInbucketHost.value = state?.inbucketHost || '';
- inputInbucketMailbox.value = state?.inbucketMailbox || '';
- setHotmailServiceMode(state?.hotmailServiceMode);
- inputHotmailRemoteBaseUrl.value = state?.hotmailRemoteBaseUrl || '';
- inputHotmailLocalBaseUrl.value = state?.hotmailLocalBaseUrl || '';
- inputLuckmailApiKey.value = state?.luckmailApiKey || '';
- inputLuckmailBaseUrl.value = normalizeLuckmailBaseUrl(state?.luckmailBaseUrl);
- selectLuckmailEmailType.value = normalizeLuckmailEmailType(state?.luckmailEmailType);
- inputLuckmailDomain.value = state?.luckmailDomain || '';
- inputTempEmailBaseUrl.value = state?.cloudflareTempEmailBaseUrl || '';
- inputTempEmailAdminAuth.value = state?.cloudflareTempEmailAdminAuth || '';
- inputTempEmailCustomAuth.value = state?.cloudflareTempEmailCustomAuth || '';
- inputTempEmailReceiveMailbox.value = state?.cloudflareTempEmailReceiveMailbox || '';
- renderCloudflareDomainOptions(state?.cloudflareDomain || '');
- setCloudflareDomainEditMode(false, { clearInput: true });
- renderCloudflareTempEmailDomainOptions(state?.cloudflareTempEmailDomain || '');
- setCloudflareTempEmailDomainEditMode(false, { clearInput: true });
- inputAutoSkipFailures.checked = Boolean(state?.autoRunSkipFailures);
- inputAutoSkipFailuresThreadIntervalMinutes.value = String(normalizeAutoRunThreadIntervalMinutes(state?.autoRunFallbackThreadIntervalMinutes));
- inputAutoDelayEnabled.checked = Boolean(state?.autoRunDelayEnabled);
- inputAutoDelayMinutes.value = String(normalizeAutoDelayMinutes(state?.autoRunDelayMinutes));
- inputAutoStepDelaySeconds.value = formatAutoStepDelayInputValue(state?.autoStepDelaySeconds);
- if (state?.autoRunTotalRuns) {
- inputRunCount.value = String(state.autoRunTotalRuns);
- }
- applyAutoRunStatus(state);
- markSettingsDirty(false);
- updateAutoDelayInputState();
- updateFallbackThreadIntervalInputState();
- updateAccountRunHistorySettingsUI();
- updatePanelModeUI();
- updateMailProviderUI();
- if (isLuckmailProvider(state?.mailProvider)) {
- queueLuckmailPurchaseRefresh();
- }
- updateButtonStates();
- }
- async function restoreState() {
- try {
- const state = await chrome.runtime.sendMessage({ type: 'GET_STATE', source: 'sidepanel' });
- applySettingsState(state);
- if (getSelectedEmailGenerator() === 'icloud' && icloudSection?.style.display !== 'none') {
- refreshIcloudAliases({ silent: true }).catch(() => { });
- }
- if (state.oauthUrl) {
- displayOauthUrl.textContent = state.oauthUrl;
- displayOauthUrl.classList.add('has-value');
- }
- if (state.localhostUrl) {
- displayLocalhostUrl.textContent = state.localhostUrl;
- displayLocalhostUrl.classList.add('has-value');
- }
- if (state.stepStatuses) {
- for (const [step, status] of Object.entries(state.stepStatuses)) {
- updateStepUI(Number(step), status);
- }
- }
- if (state.logs) {
- for (const entry of state.logs) {
- appendLog(entry);
- }
- }
- updateStatusDisplay(latestState);
- updateProgressCounter();
- } catch (err) {
- console.error('Failed to restore state:', err);
- }
- }
- function openExternalUrl(url) {
- const targetUrl = String(url || '').trim();
- if (!targetUrl) {
- return;
- }
- if (chrome?.tabs?.create) {
- chrome.tabs.create({ url: targetUrl, active: true }).catch(() => {
- window.open(targetUrl, '_blank', 'noopener');
- });
- return;
- }
- window.open(targetUrl, '_blank', 'noopener');
- }
- function createUpdateNoteList(notes = []) {
- if (!Array.isArray(notes) || notes.length === 0) {
- const empty = document.createElement('p');
- empty.className = 'update-release-empty';
- empty.textContent = '该版本未提供可解析的更新说明,请查看完整更新日志。';
- return empty;
- }
- const list = document.createElement('ul');
- list.className = 'update-release-notes';
- notes.forEach((note) => {
- const item = document.createElement('li');
- item.textContent = note;
- list.appendChild(item);
- });
- return list;
- }
- function renderUpdateReleaseList(releases = []) {
- if (!updateReleaseList) {
- return;
- }
- updateReleaseList.innerHTML = '';
- releases.forEach((release) => {
- const item = document.createElement('article');
- item.className = 'update-release-item';
- const head = document.createElement('div');
- head.className = 'update-release-head';
- const titleRow = document.createElement('div');
- titleRow.className = 'update-release-title-row';
- const version = document.createElement('span');
- version.className = 'update-release-version';
- version.textContent = `v${release.version}`;
- titleRow.appendChild(version);
- if (release.title) {
- const name = document.createElement('span');
- name.className = 'update-release-name';
- name.textContent = release.title;
- titleRow.appendChild(name);
- }
- head.appendChild(titleRow);
- const publishedAt = sidepanelUpdateService?.formatReleaseDate?.(release.publishedAt) || '';
- if (publishedAt) {
- const date = document.createElement('span');
- date.className = 'update-release-date';
- date.textContent = publishedAt;
- head.appendChild(date);
- }
- item.appendChild(head);
- item.appendChild(createUpdateNoteList(release.notes));
- updateReleaseList.appendChild(item);
- });
- }
- function resetUpdateCard() {
- if (updateSection) {
- updateSection.hidden = true;
- }
- if (updateCardVersion) {
- updateCardVersion.textContent = '';
- }
- if (updateCardSummary) {
- updateCardSummary.textContent = '';
- }
- if (updateReleaseList) {
- updateReleaseList.innerHTML = '';
- }
- if (btnOpenRelease) {
- btnOpenRelease.hidden = true;
- btnOpenRelease.onclick = null;
- }
- }
- function renderReleaseSnapshot(snapshot) {
- currentReleaseSnapshot = snapshot;
- if (!extensionUpdateStatus || !extensionVersionMeta) {
- return;
- }
- extensionUpdateStatus.classList.remove('is-update-available', 'is-check-failed', 'is-version-label');
- const localVersionText = snapshot?.localVersion ? `v${snapshot.localVersion}` : '';
- const logUrl = snapshot?.logUrl || snapshot?.releasesPageUrl || sidepanelUpdateService?.releasesPageUrl || '';
- if (btnReleaseLog) {
- btnReleaseLog.onclick = () => openExternalUrl(logUrl);
- btnReleaseLog.hidden = true;
- }
- extensionVersionMeta.hidden = true;
- extensionVersionMeta.textContent = '';
- switch (snapshot?.status) {
- case 'update-available': {
- extensionUpdateStatus.textContent = '有更新';
- extensionUpdateStatus.classList.add('is-update-available');
- if (btnReleaseLog) {
- btnReleaseLog.hidden = false;
- }
- if (updateSection) {
- updateSection.hidden = false;
- }
- if (updateCardVersion) {
- updateCardVersion.textContent = `最新版本 v${snapshot.latestVersion}`;
- }
- if (updateCardSummary) {
- const updateCount = Array.isArray(snapshot.newerReleases) ? snapshot.newerReleases.length : 0;
- updateCardSummary.textContent = updateCount > 1
- ? `当前 ${localVersionText},共有 ${updateCount} 个新版本可更新。`
- : `当前 ${localVersionText},可更新到 v${snapshot.latestVersion}。`;
- }
- renderUpdateReleaseList(snapshot.newerReleases || []);
- if (btnOpenRelease) {
- btnOpenRelease.hidden = false;
- btnOpenRelease.textContent = '前往更新';
- btnOpenRelease.onclick = () => openExternalUrl(logUrl);
- }
- break;
- }
- case 'latest': {
- extensionUpdateStatus.textContent = localVersionText || 'v0.0.0';
- extensionUpdateStatus.classList.add('is-version-label');
- resetUpdateCard();
- break;
- }
- case 'empty': {
- extensionUpdateStatus.textContent = localVersionText || 'v0.0.0';
- extensionUpdateStatus.classList.add('is-version-label');
- resetUpdateCard();
- break;
- }
- case 'error':
- default: {
- extensionUpdateStatus.textContent = localVersionText || 'v0.0.0';
- extensionUpdateStatus.classList.add('is-version-label', 'is-check-failed');
- extensionVersionMeta.textContent = snapshot?.errorMessage || 'GitHub Releases 检查失败';
- extensionVersionMeta.hidden = false;
- resetUpdateCard();
- break;
- }
- }
- }
- async function initializeReleaseInfo() {
- const fallbackReleaseUrl = sidepanelUpdateService?.releasesPageUrl || 'https://github.com/QLHazyCoder/codex-oauth-automation-extension/releases';
- if (btnReleaseLog) {
- btnReleaseLog.onclick = () => openExternalUrl(currentReleaseSnapshot?.logUrl || fallbackReleaseUrl);
- }
- if (!extensionUpdateStatus || !extensionVersionMeta) {
- return;
- }
- const localVersion = sidepanelUpdateService?.stripVersionPrefix?.(chrome.runtime.getManifest()?.version || '') || '';
- extensionUpdateStatus.textContent = localVersion ? `v${localVersion}` : 'v0.0.0';
- extensionUpdateStatus.classList.remove('is-update-available', 'is-check-failed');
- extensionUpdateStatus.classList.add('is-version-label');
- extensionVersionMeta.hidden = true;
- extensionVersionMeta.textContent = '';
- if (btnReleaseLog) {
- btnReleaseLog.hidden = true;
- }
- resetUpdateCard();
- if (!sidepanelUpdateService) {
- extensionVersionMeta.textContent = '更新检查服务不可用';
- extensionVersionMeta.hidden = false;
- return;
- }
- const snapshot = await sidepanelUpdateService.getReleaseSnapshot();
- renderReleaseSnapshot(snapshot);
- }
- function syncPasswordField(state) {
- inputPassword.value = state.customPassword || state.password || '';
- }
- function isCustomMailProvider(provider = selectMailProvider.value) {
- return String(provider || '').trim().toLowerCase() === 'custom';
- }
- function isLuckmailProvider(provider = selectMailProvider.value) {
- return String(provider || '').trim().toLowerCase() === LUCKMAIL_PROVIDER;
- }
- function isIcloudMailProvider(provider = selectMailProvider.value) {
- return String(provider || '').trim().toLowerCase() === ICLOUD_PROVIDER;
- }
- function normalizeLuckmailBaseUrl(value = '') {
- const trimmed = String(value || '').trim();
- if (!trimmed) {
- return DEFAULT_LUCKMAIL_BASE_URL;
- }
- try {
- const parsed = new URL(trimmed);
- if (!['http:', 'https:'].includes(parsed.protocol)) {
- return DEFAULT_LUCKMAIL_BASE_URL;
- }
- parsed.pathname = parsed.pathname.replace(/\/+$/, '');
- parsed.search = '';
- parsed.hash = '';
- return parsed.toString().replace(/\/$/, '');
- } catch {
- return DEFAULT_LUCKMAIL_BASE_URL;
- }
- }
- function normalizeLuckmailEmailType(value = '') {
- const normalized = String(value || '').trim().toLowerCase();
- return ['self_built', 'ms_imap', 'ms_graph', 'google_variant'].includes(normalized)
- ? normalized
- : DEFAULT_LUCKMAIL_EMAIL_TYPE;
- }
- function getSelectedEmailGenerator() {
- const generator = String(selectEmailGenerator.value || '').trim().toLowerCase();
- if (generator === 'custom' || generator === 'manual') {
- return 'custom';
- }
- if (generator === 'icloud') {
- return 'icloud';
- }
- if (generator === 'cloudflare') return 'cloudflare';
- if (generator === 'cloudflare-temp-email') return 'cloudflare-temp-email';
- return 'duck';
- }
- function getEmailGeneratorUiCopy() {
- if (getSelectedEmailGenerator() === 'custom') {
- return getCustomMailProviderUiCopy();
- }
- if (getSelectedEmailGenerator() === 'icloud') {
- return {
- buttonLabel: '获取',
- placeholder: '点击获取 iCloud 隐私邮箱,或手动粘贴邮箱',
- successVerb: '获取',
- label: 'iCloud 隐私邮箱',
- };
- }
- if (getSelectedEmailGenerator() === 'cloudflare') {
- return {
- buttonLabel: '生成',
- placeholder: '点击生成 Cloudflare 邮箱,或手动粘贴邮箱',
- successVerb: '生成',
- label: 'Cloudflare 邮箱',
- };
- }
- if (getSelectedEmailGenerator() === 'cloudflare-temp-email') {
- return {
- buttonLabel: '生成 Temp',
- placeholder: '点击生成 Cloudflare Temp Email,或手动粘贴邮箱',
- successVerb: '生成',
- label: 'Cloudflare Temp Email',
- };
- }
- return {
- buttonLabel: '获取',
- placeholder: '点击获取 DuckDuckGo 邮箱,或手动粘贴邮箱',
- successVerb: '获取',
- label: 'Duck 邮箱',
- };
- }
- function getCustomMailProviderUiCopy() {
- return {
- buttonLabel: '自定义邮箱',
- placeholder: '请填写本轮要使用的注册邮箱',
- successVerb: '使用',
- label: '自定义邮箱',
- };
- }
- function getCustomVerificationPromptCopy(step) {
- const verificationLabel = step === 4 ? '注册验证码' : '登录验证码';
- return {
- title: `手动处理${verificationLabel}`,
- message: `当前邮箱服务为“自定义邮箱”。请先在页面中手动输入${verificationLabel},并确认已经进入下一页面后,再点击确认。`,
- alert: {
- text: `点击确认后会跳过步骤 ${step}。`,
- tone: 'danger',
- },
- };
- }
- function getHotmailAccounts(state = latestState) {
- return Array.isArray(state?.hotmailAccounts) ? state.hotmailAccounts : [];
- }
- function getCurrentHotmailAccount(state = latestState) {
- const currentId = state?.currentHotmailAccountId;
- return getHotmailAccounts(state).find((account) => account.id === currentId) || null;
- }
- function getCurrentHotmailEmail(state = latestState) {
- return String(getCurrentHotmailAccount(state)?.email || '').trim();
- }
- function getCurrentLuckmailPurchase(state = latestState) {
- return state?.currentLuckmailPurchase || null;
- }
- function getCurrentLuckmailEmail(state = latestState) {
- return String(getCurrentLuckmailPurchase(state)?.email_address || '').trim();
- }
- function getLuckmailUsedPurchases(state = latestState) {
- const rawValue = state?.luckmailUsedPurchases;
- if (!rawValue || typeof rawValue !== 'object' || Array.isArray(rawValue)) {
- return {};
- }
- return Object.entries(rawValue).reduce((result, [key, value]) => {
- const numeric = Number(key);
- if (!Number.isFinite(numeric) || numeric <= 0) {
- return result;
- }
- result[String(Math.floor(numeric))] = Boolean(value);
- return result;
- }, {});
- }
- function normalizeLuckmailProjectName(value = '') {
- return String(value || '').trim().toLowerCase();
- }
- function getLuckmailPreserveTagName(state = latestState) {
- return String(state?.luckmailPreserveTagName || '').trim() || DEFAULT_LUCKMAIL_PRESERVE_TAG_NAME;
- }
- function formatLuckmailDateTime(value) {
- const timestamp = normalizeLuckmailTimestampValue(value);
- if (!timestamp) {
- return String(value || '').trim() || '未知';
- }
- return new Date(timestamp).toLocaleString('zh-CN', {
- hour12: false,
- timeZone: DISPLAY_TIMEZONE,
- });
- }
- function getMailProviderLoginConfig(provider = selectMailProvider.value) {
- return MAIL_PROVIDER_LOGIN_CONFIGS[String(provider || '').trim()] || null;
- }
- function getSelectedIcloudHostPreference() {
- return normalizeIcloudHost(selectIcloudHostPreference?.value || latestState?.icloudHostPreference || '')
- || normalizeIcloudHost(latestState?.preferredIcloudHost)
- || 'icloud.com';
- }
- function getMailProviderLoginUrl(provider = selectMailProvider.value) {
- const config = getMailProviderLoginConfig(provider);
- if (String(provider || '').trim() === ICLOUD_PROVIDER) {
- return getIcloudLoginUrlForHost(getSelectedIcloudHostPreference());
- }
- const url = String(config?.url || '').trim();
- return url ? url : '';
- }
- function isCurrentEmailManagedByHotmail(state = latestState) {
- const hotmailEmail = getCurrentHotmailEmail(state);
- if (!hotmailEmail) {
- return false;
- }
- const inputEmailValue = String(inputEmail.value || '').trim();
- const stateEmailValue = String(state?.email || '').trim();
- return inputEmailValue === hotmailEmail || stateEmailValue === hotmailEmail;
- }
- function isCurrentEmailManagedByLuckmail(state = latestState) {
- const luckmailEmail = getCurrentLuckmailEmail(state);
- if (!luckmailEmail) {
- return false;
- }
- const inputEmailValue = String(inputEmail.value || '').trim();
- const stateEmailValue = String(state?.email || '').trim();
- return inputEmailValue === luckmailEmail || stateEmailValue === luckmailEmail;
- }
- function isCurrentEmailManagedByGeneratedAlias(
- provider = latestState?.mailProvider,
- state = latestState,
- mail2925Mode = latestState?.mail2925Mode
- ) {
- const normalizedProvider = String(provider || '').trim();
- if (!usesGeneratedAliasMailProvider(normalizedProvider, mail2925Mode)) {
- return false;
- }
- const inputEmailValue = String(inputEmail.value || '').trim().toLowerCase();
- const stateEmailValue = String(state?.email || '').trim().toLowerCase();
- const baseEmail = getManagedAliasBaseEmailForProvider(normalizedProvider, state);
- return isManagedAliasEmail(inputEmailValue, baseEmail, normalizedProvider)
- || isManagedAliasEmail(stateEmailValue, baseEmail, normalizedProvider);
- }
- async function maybeClearGeneratedAliasAfterEmailPrefixChange() {
- const provider = selectMailProvider.value;
- if (!usesGeneratedAliasMailProvider(provider, latestState?.mail2925Mode)) {
- return;
- }
- const previousPrefix = getManagedAliasBaseEmailForProvider(provider, latestState);
- const nextPrefix = inputEmailPrefix.value.trim();
- if (previousPrefix === nextPrefix) {
- return;
- }
- if (!previousPrefix) {
- return;
- }
- if (!isCurrentEmailManagedByGeneratedAlias(provider, latestState, latestState?.mail2925Mode)) {
- return;
- }
- await clearRegistrationEmail({ silent: true });
- }
- function updateMailLoginButtonState() {
- if (!btnMailLogin) {
- return;
- }
- const config = getMailProviderLoginConfig();
- const loginUrl = getMailProviderLoginUrl();
- btnMailLogin.disabled = !loginUrl;
- btnMailLogin.textContent = config?.buttonLabel || '登录';
- btnMailLogin.title = loginUrl ? `打开 ${config.label} 登录页` : '当前邮箱服务没有可跳转的登录页';
- }
- function updateMailProviderUI() {
- const use2925 = selectMailProvider.value === '2925';
- const useGmail = selectMailProvider.value === GMAIL_PROVIDER;
- const mail2925Mode = getSelectedMail2925Mode();
- const useGeneratedAlias = usesGeneratedAliasMailProvider(selectMailProvider.value, mail2925Mode);
- const useInbucket = selectMailProvider.value === 'inbucket';
- const useHotmail = selectMailProvider.value === 'hotmail-api';
- const useLuckmail = isLuckmailProvider();
- const useCustomEmail = isCustomMailProvider();
- const useIcloudProvider = isIcloudMailProvider();
- const useEmailGenerator = !useHotmail && !useLuckmail && !useGeneratedAlias && !useCustomEmail;
- const useCloudflareTempEmailProvider = selectMailProvider.value === 'cloudflare-temp-email';
- const aliasUiCopy = useGeneratedAlias ? getManagedAliasProviderUiCopy(selectMailProvider.value) : null;
- const uiCopy = getCurrentRegistrationEmailUiCopy();
- updateMailLoginButtonState();
- if (rowMail2925Mode) {
- rowMail2925Mode.style.display = 'none';
- }
- rowEmailPrefix.style.display = useGeneratedAlias ? '' : 'none';
- const hotmailServiceMode = getSelectedHotmailServiceMode();
- rowInbucketHost.style.display = useInbucket ? '' : 'none';
- rowInbucketMailbox.style.display = useInbucket ? '' : 'none';
- const selectedGenerator = getSelectedEmailGenerator();
- const useCloudflare = selectedGenerator === 'cloudflare';
- const useIcloud = selectedGenerator === 'icloud';
- const useCloudflareTempEmailGenerator = selectedGenerator === 'cloudflare-temp-email';
- const showCloudflareDomain = useEmailGenerator && useCloudflare;
- const showCloudflareTempEmailSettings = useCloudflareTempEmailProvider || (useEmailGenerator && useCloudflareTempEmailGenerator);
- const showCloudflareTempEmailReceiveMailbox = useCloudflareTempEmailProvider && !useCloudflareTempEmailGenerator;
- const showCloudflareTempEmailDomain = useEmailGenerator && useCloudflareTempEmailGenerator;
- if (rowEmailGenerator) {
- rowEmailGenerator.style.display = useEmailGenerator ? '' : 'none';
- }
- if (icloudSection) {
- const showIcloudSection = (useEmailGenerator && useIcloud) || useIcloudProvider;
- icloudSection.style.display = showIcloudSection ? '' : 'none';
- if (showIcloudSection) {
- queueIcloudAliasRefresh();
- }
- if (!showIcloudSection) {
- hideIcloudLoginHelp();
- }
- }
- rowCfDomain.style.display = showCloudflareDomain ? '' : 'none';
- const { domains } = getCloudflareDomainsFromState();
- if (showCloudflareDomain) {
- setCloudflareDomainEditMode(cloudflareDomainEditMode || domains.length === 0, { clearInput: false });
- } else {
- setCloudflareDomainEditMode(false, { clearInput: false });
- }
- rowTempEmailBaseUrl.style.display = showCloudflareTempEmailSettings ? '' : 'none';
- rowTempEmailAdminAuth.style.display = showCloudflareTempEmailSettings ? '' : 'none';
- rowTempEmailCustomAuth.style.display = showCloudflareTempEmailSettings ? '' : 'none';
- rowTempEmailReceiveMailbox.style.display = showCloudflareTempEmailReceiveMailbox ? '' : 'none';
- rowTempEmailDomain.style.display = showCloudflareTempEmailDomain ? '' : 'none';
- const { domains: tempEmailDomains } = getCloudflareTempEmailDomainsFromState();
- if (showCloudflareTempEmailDomain) {
- setCloudflareTempEmailDomainEditMode(cloudflareTempEmailDomainEditMode || tempEmailDomains.length === 0, { clearInput: false });
- } else {
- setCloudflareTempEmailDomainEditMode(false, { clearInput: false });
- }
- if (hotmailSection) {
- hotmailSection.style.display = useHotmail ? '' : 'none';
- }
- if (luckmailSection) {
- luckmailSection.style.display = useLuckmail ? '' : 'none';
- }
- labelEmailPrefix.textContent = '邮箱前缀';
- inputEmailPrefix.placeholder = '例如 abc';
- selectEmailGenerator.disabled = useHotmail || useLuckmail || useGeneratedAlias || useCustomEmail;
- if (useGmail) {
- labelEmailPrefix.textContent = 'Gmail 原邮箱';
- inputEmailPrefix.placeholder = '例如 yourname@gmail.com';
- }
- labelEmailPrefix.textContent = aliasUiCopy?.baseLabel || labelEmailPrefix.textContent;
- inputEmailPrefix.placeholder = aliasUiCopy?.basePlaceholder || inputEmailPrefix.placeholder;
- if (rowHotmailServiceMode) {
- rowHotmailServiceMode.style.display = useHotmail ? '' : 'none';
- }
- if (rowHotmailRemoteBaseUrl) {
- rowHotmailRemoteBaseUrl.style.display = useHotmail && hotmailServiceMode === HOTMAIL_SERVICE_MODE_REMOTE ? '' : 'none';
- }
- if (rowHotmailLocalBaseUrl) {
- rowHotmailLocalBaseUrl.style.display = useHotmail && hotmailServiceMode === HOTMAIL_SERVICE_MODE_LOCAL ? '' : 'none';
- }
- btnFetchEmail.hidden = useHotmail || useLuckmail || useCustomEmail;
- inputEmail.readOnly = useHotmail || useLuckmail;
- inputEmail.placeholder = useHotmail
- ? '由 Hotmail 账号池自动分配'
- : (useLuckmail
- ? '步骤 3 自动购买 LuckMail 邮箱并回填'
- : (useGeneratedAlias ? '步骤 3 自动生成 2925 邮箱并回填' : uiCopy.placeholder));
- if (useGmail && useGeneratedAlias) {
- inputEmail.placeholder = '步骤 3 自动生成 Gmail +tag 邮箱并回填';
- }
- if (!useHotmail && !useLuckmail) {
- inputEmail.placeholder = uiCopy.placeholder;
- }
- btnFetchEmail.disabled = useLuckmail || useCustomEmail || isAutoRunLockedPhase();
- if (!btnFetchEmail.disabled) {
- btnFetchEmail.textContent = uiCopy.buttonLabel;
- }
- if (autoHintText) {
- autoHintText.textContent = useHotmail
- ? '请先校验并选择一个 Hotmail 账号'
- : (useLuckmail
- ? '步骤 3 会自动购买 LuckMail 邮箱并用于收码'
- : (useGeneratedAlias
- ? '步骤 3 会自动生成邮箱,无需手动获取'
- : (useCustomEmail ? '请先填写自定义注册邮箱,成功一轮后会自动清空' : `先自动获取${uiCopy.label},或手动粘贴邮箱后再继续`)));
- }
- if (autoHintText && useGmail && useGeneratedAlias) {
- autoHintText.textContent = '请先填写 Gmail 原邮箱,步骤 3 会自动生成 Gmail +tag 地址';
- }
- if (autoHintText && useGeneratedAlias && aliasUiCopy?.hint) {
- autoHintText.textContent = aliasUiCopy.hint;
- }
- if (autoHintText && showCloudflareTempEmailReceiveMailbox) {
- autoHintText.textContent = '若注册邮箱会转发到 Cloudflare Temp Email,请在“邮件接收”中填写实际接收转发邮件的邮箱。';
- }
- if (useHotmail) {
- inputEmail.value = getCurrentHotmailEmail();
- } else if (useLuckmail) {
- inputEmail.value = getCurrentLuckmailEmail();
- }
- renderHotmailAccounts();
- if (useLuckmail) {
- renderLuckmailPurchases();
- }
- }
- async function saveCloudflareDomainSettings(domains, activeDomain, options = {}) {
- const { silent = false } = options;
- const normalizedDomains = normalizeCloudflareDomains(domains);
- const normalizedActiveDomain = normalizeCloudflareDomainValue(activeDomain) || normalizedDomains[0] || '';
- const payload = {
- cloudflareDomain: normalizedActiveDomain,
- cloudflareDomains: normalizedDomains,
- };
- const response = await chrome.runtime.sendMessage({
- type: 'SAVE_SETTING',
- source: 'sidepanel',
- payload,
- });
- if (response?.error) {
- throw new Error(response.error);
- }
- syncLatestState({
- ...payload,
- });
- renderCloudflareDomainOptions(normalizedActiveDomain);
- setCloudflareDomainEditMode(false, { clearInput: true });
- markSettingsDirty(false);
- updateMailProviderUI();
- if (!silent) {
- showToast('Cloudflare 域名已保存', 'success', 1800);
- }
- }
- async function saveCloudflareTempEmailDomainSettings(domains, activeDomain, options = {}) {
- const { silent = false } = options;
- const normalizedDomains = normalizeCloudflareTempEmailDomains(domains);
- const normalizedActiveDomain = normalizeCloudflareTempEmailDomainValue(activeDomain) || normalizedDomains[0] || '';
- const payload = {
- cloudflareTempEmailDomain: normalizedActiveDomain,
- cloudflareTempEmailDomains: normalizedDomains,
- };
- const response = await chrome.runtime.sendMessage({
- type: 'SAVE_SETTING',
- source: 'sidepanel',
- payload,
- });
- if (response?.error) {
- throw new Error(response.error);
- }
- syncLatestState({
- ...payload,
- });
- renderCloudflareTempEmailDomainOptions(normalizedActiveDomain);
- setCloudflareTempEmailDomainEditMode(false, { clearInput: true });
- markSettingsDirty(false);
- updateMailProviderUI();
- if (!silent) {
- showToast('Cloudflare Temp Email 域名已保存', 'success', 1800);
- }
- }
- function updatePanelModeUI() {
- const useSub2Api = selectPanelMode.value === 'sub2api';
- rowVpsUrl.style.display = useSub2Api ? 'none' : '';
- rowVpsPassword.style.display = useSub2Api ? 'none' : '';
- rowLocalCpaStep9Mode.style.display = useSub2Api ? 'none' : '';
- rowCpaCallbackMode.style.display = useSub2Api ? 'none' : '';
- rowSub2ApiUrl.style.display = useSub2Api ? '' : 'none';
- rowSub2ApiEmail.style.display = useSub2Api ? '' : 'none';
- rowSub2ApiPassword.style.display = useSub2Api ? '' : 'none';
- rowSub2ApiGroup.style.display = useSub2Api ? '' : 'none';
- const step9Btn = document.querySelector('.step-btn[data-step-key="platform-verify"]');
- if (step9Btn) {
- step9Btn.textContent = useSub2Api ? 'SUB2API 回调验证' : 'CPA 回调验证';
- }
- }
- // ============================================================
- // UI Updates
- // ============================================================
- function updateStepUI(step, status) {
- const statusEl = document.querySelector(`.step-status[data-step="${step}"]`);
- const row = document.querySelector(`.step-row[data-step="${step}"]`);
- syncLatestState({
- stepStatuses: {
- ...getStepStatuses(),
- [step]: status,
- },
- });
- if (statusEl) statusEl.textContent = STATUS_ICONS[status] || '';
- if (row) {
- row.className = `step-row ${status}`;
- }
- updateButtonStates();
- updateProgressCounter();
- updateConfigMenuControls();
- }
- function updateProgressCounter() {
- const completed = Object.values(getStepStatuses()).filter(isDoneStatus).length;
- stepsProgress.textContent = `${completed} / ${STEP_IDS.length}`;
- }
- function updateButtonStates() {
- const statuses = getStepStatuses();
- const anyRunning = Object.values(statuses).some(s => s === 'running');
- const autoLocked = isAutoRunLockedPhase();
- const autoScheduled = isAutoRunScheduledPhase();
- for (const step of STEP_IDS) {
- const btn = document.querySelector(`.step-btn[data-step="${step}"]`);
- if (!btn) continue;
- if (anyRunning || autoLocked || autoScheduled) {
- btn.disabled = true;
- } else if (step === 1) {
- btn.disabled = false;
- } else {
- const currentIndex = STEP_IDS.indexOf(step);
- const prevStep = currentIndex > 0 ? STEP_IDS[currentIndex - 1] : null;
- const prevStatus = prevStep === null ? 'completed' : statuses[prevStep];
- const currentStatus = statuses[step];
- btn.disabled = !(isDoneStatus(prevStatus) || currentStatus === 'failed' || isDoneStatus(currentStatus) || currentStatus === 'stopped');
- }
- }
- document.querySelectorAll('.step-manual-btn').forEach((btn) => {
- const step = Number(btn.dataset.step);
- const currentStatus = statuses[step];
- const currentIndex = STEP_IDS.indexOf(step);
- const prevStep = currentIndex > 0 ? STEP_IDS[currentIndex - 1] : null;
- const prevStatus = prevStep === null ? 'completed' : statuses[prevStep];
- if (!SKIPPABLE_STEPS.has(step) || anyRunning || autoLocked || autoScheduled || currentStatus === 'running' || isDoneStatus(currentStatus)) {
- btn.style.display = 'none';
- btn.disabled = true;
- btn.title = '当前不可跳过';
- return;
- }
- if (prevStep !== null && !isDoneStatus(prevStatus)) {
- btn.style.display = 'none';
- btn.disabled = true;
- btn.title = `请先完成步骤 ${prevStep}`;
- return;
- }
- btn.style.display = '';
- btn.disabled = false;
- btn.title = `跳过步骤 ${step}`;
- });
- btnReset.disabled = anyRunning || autoScheduled || isAutoRunPausedPhase() || autoLocked;
- const disableIcloudControls = anyRunning || autoScheduled || autoLocked;
- if (btnIcloudRefresh) btnIcloudRefresh.disabled = disableIcloudControls;
- if (btnIcloudDeleteUsed) btnIcloudDeleteUsed.disabled = disableIcloudControls || !hasDeletableUsedIcloudAliases();
- if (selectIcloudHostPreference) selectIcloudHostPreference.disabled = disableIcloudControls;
- if (checkboxAutoDeleteIcloud) checkboxAutoDeleteIcloud.disabled = disableIcloudControls;
- updateStopButtonState(anyRunning || autoScheduled || isAutoRunPausedPhase() || autoLocked);
- }
- function updateStopButtonState(active) {
- btnStop.disabled = !active;
- }
- function updateStatusDisplay(state) {
- if (!state || !state.stepStatuses) return;
- statusBar.className = 'status-bar';
- const countdown = getActiveAutoRunCountdown();
- if (countdown) {
- const remainingMs = countdown.at - Date.now();
- displayStatus.textContent = remainingMs > 0
- ? `${countdown.title},剩余 ${formatCountdown(remainingMs)}`
- : `${countdown.title},即将结束...`;
- statusBar.classList.add(countdown.tone === 'scheduled' ? 'scheduled' : 'running');
- return;
- }
- if (isAutoRunScheduledPhase()) {
- const remainingMs = Number.isFinite(currentAutoRun.scheduledAt)
- ? currentAutoRun.scheduledAt - Date.now()
- : 0;
- displayStatus.textContent = remainingMs > 0
- ? `自动计划中,剩余 ${formatCountdown(remainingMs)}`
- : '倒计时即将结束,正在准备启动...';
- statusBar.classList.add('scheduled');
- return;
- }
- if (isAutoRunPausedPhase()) {
- displayStatus.textContent = `自动已暂停${getAutoRunLabel()},等待邮箱后继续`;
- statusBar.classList.add('paused');
- return;
- }
- if (isAutoRunWaitingStepPhase()) {
- const runningSteps = getRunningSteps(state);
- displayStatus.textContent = runningSteps.length
- ? `自动等待步骤 ${runningSteps.join(', ')} 完成后继续${getAutoRunLabel()}`
- : `自动正在按最新进度准备继续${getAutoRunLabel()}`;
- statusBar.classList.add('running');
- return;
- }
- const running = Object.entries(state.stepStatuses).find(([, s]) => s === 'running');
- if (running) {
- displayStatus.textContent = `步骤 ${running[0]} 运行中...`;
- statusBar.classList.add('running');
- return;
- }
- if (isAutoRunLockedPhase()) {
- displayStatus.textContent = `${currentAutoRun.phase === 'retrying' ? '自动重试中' : '自动运行中'}${getAutoRunLabel()}`;
- statusBar.classList.add('running');
- return;
- }
- const failed = Object.entries(state.stepStatuses).find(([, s]) => s === 'failed');
- if (failed) {
- displayStatus.textContent = `步骤 ${failed[0]} 失败`;
- statusBar.classList.add('failed');
- return;
- }
- const stopped = Object.entries(state.stepStatuses).find(([, s]) => s === 'stopped');
- if (stopped) {
- displayStatus.textContent = `步骤 ${stopped[0]} 已停止`;
- statusBar.classList.add('stopped');
- return;
- }
- const lastCompleted = Object.entries(state.stepStatuses)
- .filter(([, s]) => isDoneStatus(s))
- .map(([k]) => Number(k))
- .sort((a, b) => b - a)[0];
- if (lastCompleted === 9) {
- displayStatus.textContent = (state.stepStatuses[9] === 'manual_completed' || state.stepStatuses[9] === 'skipped') ? '全部步骤已跳过/完成' : '全部步骤已完成';
- statusBar.classList.add('completed');
- } else if (lastCompleted) {
- displayStatus.textContent = (state.stepStatuses[lastCompleted] === 'manual_completed' || state.stepStatuses[lastCompleted] === 'skipped')
- ? `步骤 ${lastCompleted} 已跳过`
- : `步骤 ${lastCompleted} 已完成`;
- } else {
- displayStatus.textContent = '就绪';
- }
- }
- function appendLog(entry) {
- const time = new Date(entry.timestamp).toLocaleTimeString('zh-CN', {
- hour12: false,
- timeZone: DISPLAY_TIMEZONE,
- });
- const levelLabel = LOG_LEVEL_LABELS[entry.level] || entry.level;
- const line = document.createElement('div');
- line.className = `log-line log-${entry.level}`;
- const stepMatch = entry.message.match(/(?:Step\s+(\d+)|步骤\s*(\d+))/);
- const stepNum = stepMatch ? (stepMatch[1] || stepMatch[2]) : null;
- let html = `<span class="log-time">${time}</span> `;
- html += `<span class="log-level log-level-${entry.level}">${levelLabel}</span> `;
- if (stepNum) {
- html += `<span class="log-step-tag step-${stepNum}">步${stepNum}</span>`;
- }
- html += `<span class="log-msg">${escapeHtml(entry.message)}</span>`;
- line.innerHTML = html;
- logArea.appendChild(line);
- logArea.scrollTop = logArea.scrollHeight;
- }
- function getAccountRunHistory(state = latestState) {
- return Array.isArray(state?.accountRunHistory)
- ? state.accountRunHistory.filter((item) => item && typeof item === 'object')
- : [];
- }
- function parseAccountRunStatus(status = '') {
- const normalized = String(status || '').trim().toLowerCase();
- const stepMatch = normalized.match(/^step(\d+)_(failed|stopped)$/);
- if (stepMatch) {
- return {
- kind: stepMatch[2] === 'failed' ? 'failed' : 'stopped',
- label: `步${stepMatch[1]}${stepMatch[2] === 'failed' ? '失败' : '停止'}`,
- };
- }
- if (normalized === 'success') {
- return { kind: 'success', label: '成功' };
- }
- if (normalized === 'failed') {
- return { kind: 'failed', label: '失败' };
- }
- if (normalized === 'stopped') {
- return { kind: 'stopped', label: '已停止' };
- }
- return {
- kind: 'unknown',
- label: normalized || '记录',
- };
- }
- function summarizeAccountRunHistory(records = []) {
- return records.reduce((summary, record) => {
- summary.total += 1;
- const { kind } = parseAccountRunStatus(record?.status);
- if (kind === 'success') {
- summary.success += 1;
- } else if (kind === 'failed') {
- summary.failed += 1;
- } else if (kind === 'stopped') {
- summary.stopped += 1;
- } else {
- summary.other += 1;
- }
- return summary;
- }, {
- total: 0,
- success: 0,
- failed: 0,
- stopped: 0,
- other: 0,
- });
- }
- function formatAccountRunHistoryTime(recordedAt) {
- const date = new Date(recordedAt);
- if (Number.isNaN(date.getTime())) {
- return '--:--';
- }
- const now = new Date();
- const sameYear = date.getFullYear() === now.getFullYear();
- const sameDay = date.toDateString() === now.toDateString();
- if (sameDay) {
- return date.toLocaleTimeString('zh-CN', {
- hour12: false,
- hour: '2-digit',
- minute: '2-digit',
- timeZone: DISPLAY_TIMEZONE,
- });
- }
- return date.toLocaleString('zh-CN', {
- hour12: false,
- month: '2-digit',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit',
- ...(sameYear ? {} : { year: '2-digit' }),
- timeZone: DISPLAY_TIMEZONE,
- }).replace(/\//g, '-');
- }
- function buildAccountRunHistoryDetailText(record = {}) {
- const reason = String(record.reason || '').trim();
- if (reason) {
- return reason;
- }
- const { kind } = parseAccountRunStatus(record.status);
- if (kind === 'success') {
- return '流程已完成并写入本地记录';
- }
- if (kind === 'stopped') {
- return '流程被手动停止,已保留当前账号快照';
- }
- if (kind === 'failed') {
- return '流程执行失败,已保留当前账号快照';
- }
- return '账号运行记录已保存';
- }
- function createAccountRunHistoryStat(label, value, className = '') {
- const item = document.createElement('span');
- item.className = `account-run-history-stat${className ? ` ${className}` : ''}`;
- item.innerHTML = `<strong>${escapeHtml(String(value))}</strong>${escapeHtml(label)}`;
- return item;
- }
- function renderAccountRunHistory(state = latestState) {
- if (!accountRunHistoryStrip || !accountRunHistoryStats || !accountRunHistoryList || !accountRunHistoryMeta) {
- return;
- }
- const records = getAccountRunHistory(state);
- if (!records.length) {
- accountRunHistoryStrip.hidden = true;
- accountRunHistoryStats.innerHTML = '';
- accountRunHistoryList.innerHTML = '';
- accountRunHistoryMeta.textContent = '最近运行记录';
- return;
- }
- const summary = summarizeAccountRunHistory(records);
- const recentRecords = records.slice(-2).reverse();
- const latestRecord = records[records.length - 1] || null;
- accountRunHistoryStrip.hidden = false;
- accountRunHistoryMeta.textContent = latestRecord
- ? `共 ${summary.total} 条,最近更新于 ${formatAccountRunHistoryTime(latestRecord.recordedAt)}`
- : `共 ${summary.total} 条`;
- accountRunHistoryStats.innerHTML = '';
- accountRunHistoryStats.appendChild(createAccountRunHistoryStat('总', summary.total));
- if (summary.success > 0) {
- accountRunHistoryStats.appendChild(createAccountRunHistoryStat('成', summary.success, 'is-success'));
- }
- if (summary.failed > 0) {
- accountRunHistoryStats.appendChild(createAccountRunHistoryStat('失', summary.failed, 'is-failed'));
- }
- if (summary.stopped > 0) {
- accountRunHistoryStats.appendChild(createAccountRunHistoryStat('停', summary.stopped, 'is-stopped'));
- }
- accountRunHistoryList.innerHTML = '';
- recentRecords.forEach((record) => {
- const statusMeta = parseAccountRunStatus(record.status);
- const item = document.createElement('div');
- item.className = `account-run-history-item is-${statusMeta.kind}`;
- item.title = [
- record.email || '',
- statusMeta.label,
- record.reason || '',
- ].filter(Boolean).join('\n');
- const main = document.createElement('div');
- main.className = 'account-run-history-item-main';
- const email = document.createElement('div');
- email.className = 'account-run-history-item-email mono';
- email.textContent = String(record.email || '').trim() || '(空邮箱)';
- const detail = document.createElement('div');
- detail.className = 'account-run-history-item-detail';
- detail.textContent = buildAccountRunHistoryDetailText(record);
- const side = document.createElement('div');
- side.className = 'account-run-history-item-side';
- const status = document.createElement('span');
- status.className = 'account-run-history-item-status';
- status.textContent = statusMeta.label;
- const time = document.createElement('span');
- time.className = 'account-run-history-item-time mono';
- time.textContent = formatAccountRunHistoryTime(record.recordedAt);
- main.append(email, detail);
- side.append(status, time);
- item.append(main, side);
- accountRunHistoryList.appendChild(item);
- });
- }
- function escapeHtml(text) {
- const div = document.createElement('div');
- div.textContent = text;
- return div.innerHTML;
- }
- async function fetchGeneratedEmail(options = {}) {
- const { showFailureToast = true } = options;
- const uiCopy = getCurrentRegistrationEmailUiCopy();
- if (isCustomMailProvider()) {
- throw new Error('当前邮箱服务为自定义邮箱,请直接填写注册邮箱。');
- }
- const defaultLabel = uiCopy.buttonLabel;
- btnFetchEmail.disabled = true;
- btnFetchEmail.textContent = '...';
- try {
- const response = await chrome.runtime.sendMessage({
- type: 'FETCH_GENERATED_EMAIL',
- source: 'sidepanel',
- payload: {
- generateNew: true,
- generator: selectEmailGenerator.value,
- mailProvider: selectMailProvider.value,
- ...buildManagedAliasBaseEmailPayload(),
- },
- });
- if (response?.error) {
- throw new Error(response.error);
- }
- if (!response?.email) {
- throw new Error('未返回可用邮箱。');
- }
- inputEmail.value = response.email;
- if (getSelectedEmailGenerator() === 'icloud') {
- queueIcloudAliasRefresh();
- }
- showToast(`已${uiCopy.successVerb} ${uiCopy.label}:${response.email}`, 'success', 2500);
- return response.email;
- } catch (err) {
- if (showFailureToast) {
- showToast(`${uiCopy.label}${uiCopy.successVerb}失败:${err.message}`, 'error');
- }
- throw err;
- } finally {
- btnFetchEmail.disabled = false;
- btnFetchEmail.textContent = defaultLabel;
- }
- }
- function syncToggleButtonLabel(button, input, labels) {
- if (!button || !input) return;
- const isHidden = input.type === 'password';
- button.innerHTML = isHidden ? EYE_OPEN_ICON : EYE_CLOSED_ICON;
- button.setAttribute('aria-label', isHidden ? labels.show : labels.hide);
- button.title = isHidden ? labels.show : labels.hide;
- }
- async function copyTextToClipboard(text) {
- const value = String(text || '').trim();
- if (!value) {
- throw new Error('没有可复制的内容。');
- }
- if (!navigator.clipboard?.writeText) {
- throw new Error('当前环境不支持剪贴板复制。');
- }
- await navigator.clipboard.writeText(value);
- }
- const hotmailManager = window.SidepanelHotmailManager?.createHotmailManager({
- state: {
- getLatestState: () => latestState,
- syncLatestState,
- },
- dom: {
- btnAddHotmailAccount,
- btnClearUsedHotmailAccounts,
- btnDeleteAllHotmailAccounts,
- btnHotmailUsageGuide,
- btnImportHotmailAccounts,
- btnToggleHotmailList,
- hotmailAccountsList,
- hotmailListShell,
- inputEmail,
- inputHotmailClientId,
- inputHotmailEmail,
- inputHotmailImport,
- inputHotmailPassword,
- inputHotmailRefreshToken,
- selectMailProvider,
- },
- helpers: {
- copyTextToClipboard,
- escapeHtml,
- getCurrentHotmailEmail,
- getHotmailAccounts,
- openConfirmModal,
- showToast,
- },
- runtime: {
- sendMessage: (message) => chrome.runtime.sendMessage(message),
- },
- constants: {
- copyIcon: COPY_ICON,
- displayTimeZone: DISPLAY_TIMEZONE,
- expandedStorageKey: 'multipage-hotmail-list-expanded',
- },
- hotmailUtils: {
- filterHotmailAccountsByUsage,
- getHotmailBulkActionLabel,
- getHotmailListToggleLabel,
- parseHotmailImportText,
- shouldClearHotmailCurrentSelection,
- upsertHotmailAccountInList,
- },
- });
- const initHotmailListExpandedState = hotmailManager?.initHotmailListExpandedState
- || (() => { });
- const renderHotmailAccounts = hotmailManager?.renderHotmailAccounts
- || (() => { });
- const bindHotmailEvents = hotmailManager?.bindHotmailEvents
- || (() => { });
- bindHotmailEvents();
- const icloudManager = window.SidepanelIcloudManager?.createIcloudManager({
- dom: {
- btnIcloudBulkDelete,
- btnIcloudBulkPreserve,
- btnIcloudBulkUnpreserve,
- btnIcloudBulkUnused,
- btnIcloudBulkUsed,
- btnIcloudDeleteUsed,
- btnIcloudLoginDone,
- btnIcloudRefresh,
- checkboxIcloudSelectAll,
- icloudList,
- icloudLoginHelp,
- icloudLoginHelpText,
- icloudLoginHelpTitle,
- icloudSection,
- icloudSelectionSummary,
- icloudSummary,
- inputIcloudSearch,
- selectIcloudFilter,
- },
- helpers: {
- copyTextToClipboard,
- escapeHtml,
- openConfirmModal,
- showToast,
- },
- runtime: {
- sendMessage: (message) => chrome.runtime.sendMessage(message),
- },
- });
- const hideIcloudLoginHelp = icloudManager?.hideIcloudLoginHelp
- || (() => { });
- const hasDeletableUsedIcloudAliases = icloudManager?.hasDeletableUsedAliases
- || (() => false);
- const queueIcloudAliasRefresh = icloudManager?.queueIcloudAliasRefresh
- || (() => { });
- const refreshIcloudAliases = icloudManager?.refreshIcloudAliases
- || (async () => { });
- const renderIcloudAliases = icloudManager?.renderIcloudAliases
- || (() => { });
- const resetIcloudManager = icloudManager?.reset
- || (() => { });
- const showIcloudLoginHelp = icloudManager?.showIcloudLoginHelp
- || (() => { });
- const updateIcloudBulkUI = icloudManager?.updateIcloudBulkUI
- || (() => { });
- const bindIcloudEvents = icloudManager?.bindIcloudEvents
- || (() => { });
- bindIcloudEvents();
- const luckmailManager = window.SidepanelLuckmailManager?.createLuckmailManager({
- dom: {
- btnLuckmailBulkDisable,
- btnLuckmailBulkEnable,
- btnLuckmailBulkPreserve,
- btnLuckmailBulkUnpreserve,
- btnLuckmailBulkUnused,
- btnLuckmailBulkUsed,
- btnLuckmailDisableUsed,
- btnLuckmailRefresh,
- checkboxLuckmailSelectAll,
- inputEmail,
- inputLuckmailSearch,
- luckmailList,
- luckmailSection,
- luckmailSelectionSummary,
- luckmailSummary,
- selectLuckmailFilter,
- },
- helpers: {
- copyTextToClipboard,
- escapeHtml,
- formatLuckmailDateTime,
- getLuckmailPreserveTagName,
- normalizeLuckmailProjectName,
- openConfirmModal,
- showToast,
- },
- runtime: {
- sendMessage: (message) => chrome.runtime.sendMessage(message),
- },
- constants: {
- copyIcon: COPY_ICON,
- },
- });
- const queueLuckmailPurchaseRefresh = luckmailManager?.queueLuckmailPurchaseRefresh
- || (() => { });
- const refreshLuckmailPurchases = luckmailManager?.refreshLuckmailPurchases
- || (async () => { });
- const renderLuckmailPurchases = luckmailManager?.renderLuckmailPurchases
- || (() => { });
- const resetLuckmailManager = luckmailManager?.reset
- || (() => { });
- const bindLuckmailEvents = luckmailManager?.bindLuckmailEvents
- || (() => { });
- bindLuckmailEvents();
- renderStepsList();
- async function exportSettingsFile() {
- closeConfigMenu();
- configActionInFlight = true;
- updateConfigMenuControls();
- try {
- await flushPendingSettingsBeforeExport();
- const response = await chrome.runtime.sendMessage({
- type: 'EXPORT_SETTINGS',
- source: 'sidepanel',
- payload: {},
- });
- if (response?.error) {
- throw new Error(response.error);
- }
- if (!response?.fileContent || !response?.fileName) {
- throw new Error('\u672a\u751f\u6210\u53ef\u4e0b\u8f7d\u7684\u914d\u7f6e\u6587\u4ef6\u3002');
- }
- downloadTextFile(response.fileContent, response.fileName);
- showToast('\u914d\u7f6e\u5df2\u5bfc\u51fa\uff1a' + response.fileName, 'success', 2200);
- } catch (err) {
- showToast('\u5bfc\u51fa\u914d\u7f6e\u5931\u8d25\uff1a' + err.message, 'error');
- } finally {
- configActionInFlight = false;
- updateConfigMenuControls();
- }
- }
- async function importSettingsFromFile(file) {
- if (!file) return;
- configActionInFlight = true;
- closeConfigMenu();
- updateConfigMenuControls();
- try {
- await settlePendingSettingsBeforeImport();
- const rawText = await file.text();
- let parsedConfig = null;
- try {
- parsedConfig = JSON.parse(rawText);
- } catch {
- throw new Error('\u914d\u7f6e\u6587\u4ef6\u4e0d\u662f\u6709\u6548\u7684 JSON\u3002');
- }
- const confirmed = await openConfirmModal({
- title: '\u5bfc\u5165\u914d\u7f6e',
- message: '\u786e\u8ba4\u5bfc\u5165\u914d\u7f6e\u6587\u4ef6 "' + file.name + '" \u5417\uff1f\u5bfc\u5165\u540e\u4f1a\u8986\u76d6\u5f53\u524d\u914d\u7f6e\u3002',
- confirmLabel: '\u786e\u8ba4\u8986\u76d6\u5bfc\u5165',
- confirmVariant: 'btn-danger',
- });
- if (!confirmed) {
- return;
- }
- const response = await chrome.runtime.sendMessage({
- type: 'IMPORT_SETTINGS',
- source: 'sidepanel',
- payload: {
- config: parsedConfig,
- },
- });
- if (response?.error) {
- throw new Error(response.error);
- }
- if (!response?.state) {
- throw new Error('\u5bfc\u5165\u540e\u672a\u8fd4\u56de\u6700\u65b0\u914d\u7f6e\u72b6\u6001\u3002');
- }
- applySettingsState(response.state);
- updateStatusDisplay(latestState);
- showToast('\u914d\u7f6e\u5df2\u5bfc\u5165\uff0c\u5f53\u524d\u914d\u7f6e\u5df2\u8986\u76d6\u3002', 'success', 2200);
- } catch (err) {
- showToast('\u5bfc\u5165\u914d\u7f6e\u5931\u8d25\uff1a' + err.message, 'error');
- } finally {
- configActionInFlight = false;
- updateConfigMenuControls();
- if (inputImportSettingsFile) {
- inputImportSettingsFile.value = '';
- }
- }
- }
- function syncPasswordToggleLabel() {
- syncToggleButtonLabel(btnTogglePassword, inputPassword, {
- show: '显示密码',
- hide: '隐藏密码',
- });
- }
- function syncVpsUrlToggleLabel() {
- syncToggleButtonLabel(btnToggleVpsUrl, inputVpsUrl, {
- show: '显示 CPA 地址',
- hide: '隐藏 CPA 地址',
- });
- }
- function syncVpsPasswordToggleLabel() {
- syncToggleButtonLabel(btnToggleVpsPassword, inputVpsPassword, {
- show: '显示管理密钥',
- hide: '隐藏管理密钥',
- });
- }
- async function maybeTakeoverAutoRun(actionLabel) {
- if (!isAutoRunPausedPhase()) {
- return true;
- }
- const confirmed = await openConfirmModal({
- title: '接管自动',
- message: `当前自动流程已暂停。若继续${actionLabel},将停止自动流程并切换为手动控制。是否继续?`,
- confirmLabel: '确认接管',
- confirmVariant: 'btn-primary',
- });
- if (!confirmed) {
- return false;
- }
- await chrome.runtime.sendMessage({ type: 'TAKEOVER_AUTO_RUN', source: 'sidepanel', payload: {} });
- return true;
- }
- async function handleSkipStep(step) {
- if (isAutoRunPausedPhase()) {
- const takeoverResponse = await chrome.runtime.sendMessage({
- type: 'TAKEOVER_AUTO_RUN',
- source: 'sidepanel',
- payload: {},
- });
- if (takeoverResponse?.error) {
- throw new Error(takeoverResponse.error);
- }
- }
- const response = await chrome.runtime.sendMessage({
- type: 'SKIP_STEP',
- source: 'sidepanel',
- payload: { step },
- });
- if (response?.error) {
- throw new Error(response.error);
- }
- showToast(`步骤 ${step} 已跳过`, 'success', 2200);
- }
- // ============================================================
- // Button Handlers
- // ============================================================
- stepsList?.addEventListener('click', async (event) => {
- const btn = event.target.closest('.step-btn');
- if (!btn) {
- return;
- }
- try {
- const step = Number(btn.dataset.step);
- if (!(await maybeTakeoverAutoRun(`执行步骤 ${step}`))) {
- return;
- }
- if (step === 3) {
- if (inputPassword.value !== (latestState?.customPassword || '')) {
- await chrome.runtime.sendMessage({
- type: 'SAVE_SETTING',
- source: 'sidepanel',
- payload: { customPassword: inputPassword.value },
- });
- syncLatestState({ customPassword: inputPassword.value });
- }
- let email = inputEmail.value.trim();
- if (selectMailProvider.value === 'hotmail-api' || isLuckmailProvider()) {
- const response = await chrome.runtime.sendMessage({ type: 'EXECUTE_STEP', source: 'sidepanel', payload: { step } });
- if (response?.error) {
- throw new Error(response.error);
- }
- } else if (false && usesGeneratedAliasMailProvider(selectMailProvider.value)) {
- const emailPrefix = inputEmailPrefix.value.trim();
- if (!emailPrefix) {
- showToast(selectMailProvider.value === GMAIL_PROVIDER ? '请先填写 Gmail 原邮箱。' : '请先填写 2925 邮箱前缀。', 'warn');
- return;
- }
- const response = await chrome.runtime.sendMessage({ type: 'EXECUTE_STEP', source: 'sidepanel', payload: { step, emailPrefix } });
- if (response?.error) {
- throw new Error(response.error);
- }
- } else {
- let email = inputEmail.value.trim();
- if (!email) {
- if (isCustomMailProvider()) {
- showToast('当前邮箱服务为自定义邮箱,请先填写注册邮箱后再执行第 3 步。', 'warn');
- return;
- }
- try {
- email = await fetchGeneratedEmail({ showFailureToast: false });
- } catch (err) {
- showToast(`自动获取失败:${err.message},请手动粘贴邮箱后重试。`, 'warn');
- return;
- }
- }
- if (!validateCurrentRegistrationEmail(email, { showToastOnFailure: true })) {
- return;
- }
- const response = await chrome.runtime.sendMessage({ type: 'EXECUTE_STEP', source: 'sidepanel', payload: { step, email } });
- if (response?.error) {
- throw new Error(response.error);
- }
- }
- } else {
- const response = await chrome.runtime.sendMessage({ type: 'EXECUTE_STEP', source: 'sidepanel', payload: { step } });
- if (response?.error) {
- throw new Error(response.error);
- }
- }
- } catch (err) {
- showToast(err.message, 'error');
- }
- });
- btnFetchEmail.addEventListener('click', async () => {
- if (selectMailProvider.value === 'hotmail-api' || isLuckmailProvider() || isCustomMailProvider()) {
- return;
- }
- await fetchGeneratedEmail().catch(() => { });
- });
- btnTogglePassword.addEventListener('click', () => {
- inputPassword.type = inputPassword.type === 'password' ? 'text' : 'password';
- syncPasswordToggleLabel();
- });
- btnToggleVpsUrl.addEventListener('click', () => {
- inputVpsUrl.type = inputVpsUrl.type === 'password' ? 'text' : 'password';
- syncVpsUrlToggleLabel();
- });
- btnToggleVpsPassword.addEventListener('click', () => {
- inputVpsPassword.type = inputVpsPassword.type === 'password' ? 'text' : 'password';
- syncVpsPasswordToggleLabel();
- });
- btnMailLogin?.addEventListener('click', async () => {
- const config = getMailProviderLoginConfig();
- const loginUrl = getMailProviderLoginUrl();
- if (!config || !loginUrl) {
- return;
- }
- try {
- await chrome.tabs.create({ url: loginUrl, active: true });
- } catch (err) {
- showToast(`打开${config.label}失败:${err.message}`, 'error');
- }
- });
- localCpaStep9ModeButtons.forEach((button) => {
- button.addEventListener('click', () => {
- const nextMode = button.dataset.localCpaStep9Mode;
- if (getSelectedLocalCpaStep9Mode() === normalizeLocalCpaStep9Mode(nextMode)) {
- return;
- }
- setLocalCpaStep9Mode(nextMode);
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- });
- cpaCallbackModeButtons.forEach((button) => {
- button.addEventListener('click', () => {
- const nextMode = button.dataset.cpaCallbackMode;
- if (getSelectedCpaCallbackMode() === normalizeCpaCallbackMode(nextMode)) {
- return;
- }
- setCpaCallbackMode(nextMode);
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- });
- hotmailServiceModeButtons.forEach((button) => {
- button.addEventListener('click', () => {
- if (button.disabled) {
- return;
- }
- const nextMode = button.dataset.hotmailServiceMode;
- if (getSelectedHotmailServiceMode() === normalizeHotmailServiceMode(nextMode)) {
- return;
- }
- setHotmailServiceMode(nextMode);
- updateMailProviderUI();
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- });
- btnSaveSettings.addEventListener('click', async () => {
- if (!settingsDirty) {
- showToast('配置已是最新', 'info', 1400);
- return;
- }
- await saveSettings({ silent: false }).catch(() => { });
- });
- btnStop.addEventListener('click', async () => {
- btnStop.disabled = true;
- await chrome.runtime.sendMessage({ type: 'STOP_FLOW', source: 'sidepanel', payload: {} });
- showToast(isAutoRunScheduledPhase() ? '正在取消倒计时计划...' : '正在停止当前流程...', 'warn', 2000);
- });
- btnConfigMenu?.addEventListener('click', (event) => {
- event.stopPropagation();
- toggleConfigMenu();
- });
- configMenu?.addEventListener('click', (event) => {
- event.stopPropagation();
- });
- btnExportSettings?.addEventListener('click', async () => {
- if (configActionInFlight || settingsSaveInFlight) {
- return;
- }
- await exportSettingsFile();
- });
- btnImportSettings?.addEventListener('click', async () => {
- if (configActionInFlight || settingsSaveInFlight) {
- return;
- }
- closeConfigMenu();
- if (inputImportSettingsFile) {
- inputImportSettingsFile.value = '';
- inputImportSettingsFile.click();
- }
- });
- inputImportSettingsFile?.addEventListener('change', async () => {
- const file = inputImportSettingsFile.files?.[0] || null;
- await importSettingsFromFile(file);
- });
- autoStartModal?.addEventListener('click', (event) => {
- if (event.target === autoStartModal) {
- resolveModalChoice(null);
- }
- });
- btnAutoStartClose?.addEventListener('click', () => resolveModalChoice(null));
- // Auto Run
- btnAutoRun.addEventListener('click', async () => {
- try {
- const totalRuns = getRunCountValue();
- let mode = 'restart';
- const autoRunSkipFailures = inputAutoSkipFailures.checked;
- const fallbackThreadIntervalMinutes = normalizeAutoRunThreadIntervalMinutes(
- inputAutoSkipFailuresThreadIntervalMinutes.value
- );
- inputAutoSkipFailuresThreadIntervalMinutes.value = String(fallbackThreadIntervalMinutes);
- if (shouldOfferAutoModeChoice()) {
- const startStep = getFirstUnfinishedStep();
- const runningStep = getRunningSteps()[0] ?? null;
- const choice = await openAutoStartChoiceDialog(startStep, { runningStep });
- if (!choice) {
- return;
- }
- mode = choice;
- }
- if (shouldWarnAutoRunFallbackRisk(totalRuns, autoRunSkipFailures)
- && !isAutoRunFallbackRiskPromptDismissed()) {
- const result = await openAutoRunFallbackRiskConfirmModal(totalRuns, fallbackThreadIntervalMinutes);
- if (!result.confirmed) {
- return;
- }
- if (result.dismissPrompt) {
- setAutoRunFallbackRiskPromptDismissed(true);
- }
- }
- btnAutoRun.disabled = true;
- inputRunCount.disabled = true;
- const delayEnabled = inputAutoDelayEnabled.checked;
- const delayMinutes = normalizeAutoDelayMinutes(inputAutoDelayMinutes.value);
- inputAutoDelayMinutes.value = String(delayMinutes);
- btnAutoRun.innerHTML = delayEnabled
- ? '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg> 计划中...'
- : '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg> 运行中...';
- const response = await chrome.runtime.sendMessage({
- type: delayEnabled ? 'SCHEDULE_AUTO_RUN' : 'AUTO_RUN',
- source: 'sidepanel',
- payload: {
- totalRuns,
- delayMinutes,
- autoRunSkipFailures,
- mode,
- },
- });
- if (response?.error) {
- throw new Error(response.error);
- }
- } catch (err) {
- setDefaultAutoRunButton();
- inputRunCount.disabled = false;
- showToast(err.message, 'error');
- }
- });
- btnAutoContinue.addEventListener('click', async () => {
- const email = inputEmail.value.trim();
- if (!email) {
- showToast(
- isCustomMailProvider() ? '请先填写自定义注册邮箱。' : '请先获取或粘贴邮箱。',
- 'warn'
- );
- return;
- }
- autoContinueBar.style.display = 'none';
- await chrome.runtime.sendMessage({ type: 'RESUME_AUTO_RUN', source: 'sidepanel', payload: { email } });
- });
- btnAutoRunNow?.addEventListener('click', async () => {
- try {
- btnAutoRunNow.disabled = true;
- const waitingInterval = currentAutoRun.phase === 'waiting_interval';
- await chrome.runtime.sendMessage({
- type: waitingInterval ? 'SKIP_AUTO_RUN_COUNTDOWN' : 'START_SCHEDULED_AUTO_RUN_NOW',
- source: 'sidepanel',
- payload: {},
- });
- if (waitingInterval) {
- showToast('已跳过当前倒计时,自动流程将立即继续。', 'info', 1800);
- }
- } catch (err) {
- showToast(err.message, 'error');
- } finally {
- btnAutoRunNow.disabled = false;
- }
- });
- btnAutoCancelSchedule?.addEventListener('click', async () => {
- try {
- btnAutoCancelSchedule.disabled = true;
- await chrome.runtime.sendMessage({ type: 'CANCEL_SCHEDULED_AUTO_RUN', source: 'sidepanel', payload: {} });
- showToast('已取消倒计时计划。', 'info', 1800);
- } catch (err) {
- showToast(err.message, 'error');
- } finally {
- btnAutoCancelSchedule.disabled = false;
- }
- });
- // Reset
- btnReset.addEventListener('click', async () => {
- const confirmed = await openConfirmModal({
- title: '重置流程',
- message: '确认重置全部步骤和数据吗?',
- confirmLabel: '确认重置',
- confirmVariant: 'btn-danger',
- });
- if (!confirmed) {
- return;
- }
- await chrome.runtime.sendMessage({ type: 'RESET', source: 'sidepanel' });
- syncLatestState({
- stepStatuses: STEP_DEFAULT_STATUSES,
- currentHotmailAccountId: null,
- currentLuckmailPurchase: null,
- currentLuckmailMailCursor: null,
- email: null,
- });
- syncAutoRunState({
- autoRunning: false,
- autoRunPhase: 'idle',
- autoRunCurrentRun: 0,
- autoRunTotalRuns: 1,
- autoRunAttemptRun: 0,
- scheduledAutoRunAt: null,
- autoRunCountdownAt: null,
- autoRunCountdownTitle: '',
- autoRunCountdownNote: '',
- });
- displayOauthUrl.textContent = '等待中...';
- displayOauthUrl.classList.remove('has-value');
- displayLocalhostUrl.textContent = '等待中...';
- displayLocalhostUrl.classList.remove('has-value');
- inputEmail.value = '';
- displayStatus.textContent = '就绪';
- statusBar.className = 'status-bar';
- logArea.innerHTML = '';
- resetIcloudManager();
- document.querySelectorAll('.step-row').forEach(row => row.className = 'step-row');
- document.querySelectorAll('.step-status').forEach(el => el.textContent = '');
- setDefaultAutoRunButton();
- applyAutoRunStatus(currentAutoRun);
- markSettingsDirty(false);
- updateStopButtonState(false);
- updateButtonStates();
- updateProgressCounter();
- renderHotmailAccounts();
- resetLuckmailManager();
- if (isLuckmailProvider()) {
- queueLuckmailPurchaseRefresh();
- }
- });
- // Clear log
- btnClearLog.addEventListener('click', () => {
- logArea.innerHTML = '';
- });
- // Save settings on change
- inputEmail.addEventListener('change', async () => {
- if (selectMailProvider.value === 'hotmail-api' || isLuckmailProvider()) {
- return;
- }
- const email = inputEmail.value.trim();
- inputEmail.value = email;
- try {
- if (email) {
- if (!validateCurrentRegistrationEmail(email, { showToastOnFailure: true })) {
- return;
- }
- const response = await chrome.runtime.sendMessage({ type: 'SAVE_EMAIL', source: 'sidepanel', payload: { email } });
- if (response?.error) {
- throw new Error(response.error);
- }
- } else {
- await setRuntimeEmailState(null);
- }
- } catch (err) {
- showToast(err.message, 'error');
- }
- });
- inputEmail.addEventListener('input', updateButtonStates);
- inputVpsUrl.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputVpsUrl.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- inputVpsPassword.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputVpsPassword.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- [inputHotmailRemoteBaseUrl, inputHotmailLocalBaseUrl].forEach((input) => {
- input?.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- input?.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- });
- [inputLuckmailApiKey, inputLuckmailBaseUrl, inputLuckmailDomain].forEach((input) => {
- input?.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- input?.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- });
- selectLuckmailEmailType?.addEventListener('change', () => {
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- inputPassword.addEventListener('input', () => {
- markSettingsDirty(true);
- updateButtonStates();
- scheduleSettingsAutoSave();
- });
- inputPassword.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- selectMailProvider.addEventListener('change', async () => {
- const previousProvider = latestState?.mailProvider || '';
- const previousMail2925Mode = latestState?.mail2925Mode;
- const nextProvider = selectMailProvider.value;
- syncManagedAliasBaseEmailDraftFromInput(previousProvider);
- setManagedAliasBaseEmailInputForProvider(nextProvider, latestState);
- updateMailProviderUI();
- const leavingHotmail = previousProvider === 'hotmail-api'
- && nextProvider !== 'hotmail-api'
- && isCurrentEmailManagedByHotmail();
- const leavingLuckmail = previousProvider === LUCKMAIL_PROVIDER
- && nextProvider !== LUCKMAIL_PROVIDER
- && isCurrentEmailManagedByLuckmail();
- const leavingGeneratedAlias = (
- previousProvider !== nextProvider
- || (previousProvider === '2925' && normalizeMail2925Mode(previousMail2925Mode) !== getSelectedMail2925Mode())
- ) && usesGeneratedAliasMailProvider(previousProvider, previousMail2925Mode)
- && isCurrentEmailManagedByGeneratedAlias(previousProvider, latestState, previousMail2925Mode);
- if (leavingHotmail || leavingLuckmail || leavingGeneratedAlias) {
- await clearRegistrationEmail({ silent: true }).catch(() => { });
- }
- if (nextProvider === LUCKMAIL_PROVIDER) {
- queueLuckmailPurchaseRefresh();
- }
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- mail2925ModeButtons.forEach((button) => {
- button.addEventListener('click', async () => {
- const nextMode = normalizeMail2925Mode(button.dataset.mail2925Mode);
- const previousMode = normalizeMail2925Mode(latestState?.mail2925Mode);
- if (nextMode === getSelectedMail2925Mode()) {
- return;
- }
- setMail2925Mode(nextMode);
- updateMailProviderUI();
- const leavingGeneratedAlias = selectMailProvider.value === '2925'
- && previousMode === MAIL_2925_MODE_PROVIDE
- && nextMode !== MAIL_2925_MODE_PROVIDE
- && isCurrentEmailManagedByGeneratedAlias('2925', latestState, previousMode);
- if (leavingGeneratedAlias) {
- await clearRegistrationEmail({ silent: true }).catch(() => { });
- }
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- });
- selectEmailGenerator.addEventListener('change', () => {
- updateMailProviderUI();
- clearRegistrationEmail({ silent: true }).catch(() => { });
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- selectIcloudHostPreference?.addEventListener('change', () => {
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- if (getSelectedEmailGenerator() === 'icloud') {
- queueIcloudAliasRefresh();
- }
- });
- checkboxAutoDeleteIcloud?.addEventListener('change', () => {
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- selectPanelMode.addEventListener('change', () => {
- updatePanelModeUI();
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- selectCfDomain.addEventListener('change', () => {
- if (selectCfDomain.disabled) {
- return;
- }
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- selectTempEmailDomain.addEventListener('change', () => {
- if (selectTempEmailDomain.disabled) {
- return;
- }
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- btnCfDomainMode.addEventListener('click', async () => {
- try {
- if (!cloudflareDomainEditMode) {
- setCloudflareDomainEditMode(true, { clearInput: true });
- return;
- }
- const newDomain = normalizeCloudflareDomainValue(inputCfDomain.value);
- if (!newDomain) {
- showToast('请输入有效的 Cloudflare 域名。', 'warn');
- inputCfDomain.focus();
- return;
- }
- const { domains } = getCloudflareDomainsFromState();
- await saveCloudflareDomainSettings([...domains, newDomain], newDomain);
- } catch (err) {
- showToast(err.message, 'error');
- }
- });
- btnTempEmailDomainMode.addEventListener('click', async () => {
- try {
- if (!cloudflareTempEmailDomainEditMode) {
- setCloudflareTempEmailDomainEditMode(true, { clearInput: true });
- return;
- }
- const newDomain = normalizeCloudflareTempEmailDomainValue(inputTempEmailDomain.value);
- if (!newDomain) {
- showToast('请输入有效的 Cloudflare Temp Email 域名。', 'warn');
- inputTempEmailDomain.focus();
- return;
- }
- const { domains } = getCloudflareTempEmailDomainsFromState();
- await saveCloudflareTempEmailDomainSettings([...domains, newDomain], newDomain);
- } catch (err) {
- showToast(err.message, 'error');
- }
- });
- inputCfDomain.addEventListener('keydown', (event) => {
- if (event.key === 'Enter') {
- event.preventDefault();
- btnCfDomainMode.click();
- }
- });
- inputTempEmailDomain.addEventListener('keydown', (event) => {
- if (event.key === 'Enter') {
- event.preventDefault();
- btnTempEmailDomainMode.click();
- }
- });
- inputSub2ApiUrl.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputSub2ApiUrl.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- inputSub2ApiEmail.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputSub2ApiEmail.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- inputSub2ApiPassword.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputSub2ApiPassword.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- inputSub2ApiGroup.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputSub2ApiGroup.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- inputEmailPrefix.addEventListener('input', () => {
- maybeClearGeneratedAliasAfterEmailPrefixChange().catch(() => { });
- syncManagedAliasBaseEmailDraftFromInput();
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputEmailPrefix.addEventListener('blur', () => {
- maybeClearGeneratedAliasAfterEmailPrefixChange().catch(() => {});
- syncManagedAliasBaseEmailDraftFromInput();
- saveSettings({ silent: true }).catch(() => {});
- });
- inputInbucketMailbox.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputInbucketMailbox.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- inputInbucketHost.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputInbucketHost.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- inputRunCount.addEventListener('input', () => {
- updateFallbackThreadIntervalInputState();
- });
- inputRunCount.addEventListener('blur', () => {
- inputRunCount.value = String(getRunCountValue());
- updateFallbackThreadIntervalInputState();
- });
- inputAutoSkipFailures.addEventListener('change', async () => {
- if (inputAutoSkipFailures.checked && !isAutoSkipFailuresPromptDismissed()) {
- const result = await openAutoSkipFailuresConfirmModal();
- if (!result.confirmed) {
- inputAutoSkipFailures.checked = false;
- updateFallbackThreadIntervalInputState();
- return;
- }
- if (result.dismissPrompt) {
- setAutoSkipFailuresPromptDismissed(true);
- }
- }
- updateFallbackThreadIntervalInputState();
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- inputTempEmailBaseUrl.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputTempEmailBaseUrl.addEventListener('blur', () => {
- inputTempEmailBaseUrl.value = normalizeCloudflareTempEmailBaseUrlValue(inputTempEmailBaseUrl.value);
- saveSettings({ silent: true }).catch(() => { });
- });
- inputTempEmailAdminAuth.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputTempEmailAdminAuth.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- inputTempEmailCustomAuth.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputTempEmailCustomAuth.addEventListener('blur', () => {
- saveSettings({ silent: true }).catch(() => { });
- });
- inputTempEmailReceiveMailbox.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputTempEmailReceiveMailbox.addEventListener('blur', () => {
- inputTempEmailReceiveMailbox.value = normalizeCloudflareTempEmailReceiveMailboxValue(inputTempEmailReceiveMailbox.value);
- saveSettings({ silent: true }).catch(() => { });
- });
- inputAutoSkipFailuresThreadIntervalMinutes.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputAutoSkipFailuresThreadIntervalMinutes.addEventListener('blur', () => {
- inputAutoSkipFailuresThreadIntervalMinutes.value = String(
- normalizeAutoRunThreadIntervalMinutes(inputAutoSkipFailuresThreadIntervalMinutes.value)
- );
- saveSettings({ silent: true }).catch(() => { });
- });
- inputAutoDelayEnabled.addEventListener('change', () => {
- updateAutoDelayInputState();
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- inputAutoDelayMinutes.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputAutoDelayMinutes.addEventListener('blur', () => {
- inputAutoDelayMinutes.value = String(normalizeAutoDelayMinutes(inputAutoDelayMinutes.value));
- saveSettings({ silent: true }).catch(() => { });
- });
- inputAccountRunHistoryTextEnabled?.addEventListener('change', () => {
- updateAccountRunHistorySettingsUI();
- markSettingsDirty(true);
- saveSettings({ silent: true }).catch(() => { });
- });
- inputAccountRunHistoryHelperBaseUrl?.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputAccountRunHistoryHelperBaseUrl?.addEventListener('blur', () => {
- inputAccountRunHistoryHelperBaseUrl.value = normalizeAccountRunHistoryHelperBaseUrlValue(inputAccountRunHistoryHelperBaseUrl.value);
- saveSettings({ silent: true }).catch(() => { });
- });
- function syncAutoStepDelayInputs() {
- inputAutoStepDelaySeconds.value = formatAutoStepDelayInputValue(inputAutoStepDelaySeconds.value);
- }
- inputAutoStepDelaySeconds.addEventListener('input', () => {
- markSettingsDirty(true);
- scheduleSettingsAutoSave();
- });
- inputAutoStepDelaySeconds.addEventListener('blur', () => {
- syncAutoStepDelayInputs();
- saveSettings({ silent: true }).catch(() => { });
- });
- // ============================================================
- // Listen for Background broadcasts
- // ============================================================
- chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
- switch (message.type) {
- case 'REQUEST_CUSTOM_VERIFICATION_BYPASS_CONFIRMATION': {
- (async () => {
- const step = Number(message.payload?.step);
- const promptCopy = getCustomVerificationPromptCopy(step);
- const confirmed = await openConfirmModal({
- title: promptCopy.title,
- message: promptCopy.message,
- confirmLabel: '确认跳过',
- confirmVariant: 'btn-danger',
- alert: promptCopy.alert,
- });
- sendResponse({ confirmed });
- })().catch((err) => {
- sendResponse({ error: err.message });
- });
- return true;
- }
- case 'LOG_ENTRY':
- appendLog(message.payload);
- if (message.payload.level === 'error') {
- showToast(message.payload.message, 'error');
- }
- break;
- case 'STEP_STATUS_CHANGED': {
- const { step, status } = message.payload;
- updateStepUI(step, status);
- chrome.runtime.sendMessage({ type: 'GET_STATE', source: 'sidepanel' }).then(state => {
- syncLatestState(state);
- syncAutoRunState(state);
- updateStatusDisplay(latestState);
- updateButtonStates();
- if (status === 'completed' || status === 'manual_completed' || status === 'skipped') {
- syncPasswordField(state);
- if (state.oauthUrl) {
- displayOauthUrl.textContent = state.oauthUrl;
- displayOauthUrl.classList.add('has-value');
- }
- if (state.localhostUrl) {
- displayLocalhostUrl.textContent = state.localhostUrl;
- displayLocalhostUrl.classList.add('has-value');
- }
- }
- }
- ).catch(() => { });
- break;
- }
- case 'AUTO_RUN_RESET': {
- // Full UI reset for next run
- syncLatestState({
- oauthUrl: null,
- localhostUrl: null,
- email: null,
- password: null,
- stepStatuses: STEP_DEFAULT_STATUSES,
- logs: [],
- scheduledAutoRunAt: null,
- autoRunCountdownAt: null,
- autoRunCountdownTitle: '',
- autoRunCountdownNote: '',
- });
- displayOauthUrl.textContent = '等待中...';
- displayOauthUrl.classList.remove('has-value');
- displayLocalhostUrl.textContent = '等待中...';
- displayLocalhostUrl.classList.remove('has-value');
- inputEmail.value = '';
- displayStatus.textContent = '就绪';
- statusBar.className = 'status-bar';
- logArea.innerHTML = '';
- resetIcloudManager();
- resetLuckmailManager();
- document.querySelectorAll('.step-row').forEach(row => row.className = 'step-row');
- document.querySelectorAll('.step-status').forEach(el => el.textContent = '');
- syncAutoRunState({
- autoRunning: false,
- autoRunPhase: 'idle',
- autoRunCurrentRun: 0,
- autoRunTotalRuns: 1,
- autoRunAttemptRun: 0,
- scheduledAutoRunAt: null,
- autoRunCountdownAt: null,
- autoRunCountdownTitle: '',
- autoRunCountdownNote: '',
- });
- applyAutoRunStatus(currentAutoRun);
- updateProgressCounter();
- updateButtonStates();
- renderHotmailAccounts();
- if (isLuckmailProvider()) {
- queueLuckmailPurchaseRefresh();
- }
- break;
- }
- case 'DATA_UPDATED': {
- syncLatestState(message.payload);
- if (message.payload.email !== undefined) {
- inputEmail.value = message.payload.email || '';
- }
- if (message.payload.password !== undefined) {
- inputPassword.value = message.payload.password || '';
- }
- if (message.payload.localCpaStep9Mode !== undefined) {
- setLocalCpaStep9Mode(message.payload.localCpaStep9Mode);
- }
- if (message.payload.cpaCallbackMode !== undefined) {
- setCpaCallbackMode(message.payload.cpaCallbackMode);
- }
- if (message.payload.oauthUrl !== undefined) {
- displayOauthUrl.textContent = message.payload.oauthUrl || '等待中...';
- displayOauthUrl.classList.toggle('has-value', Boolean(message.payload.oauthUrl));
- }
- if (message.payload.localhostUrl !== undefined) {
- displayLocalhostUrl.textContent = message.payload.localhostUrl || '等待中...';
- displayLocalhostUrl.classList.toggle('has-value', Boolean(message.payload.localhostUrl));
- }
- if (message.payload.cloudflareTempEmailBaseUrl !== undefined) {
- inputTempEmailBaseUrl.value = message.payload.cloudflareTempEmailBaseUrl || '';
- }
- if (message.payload.cloudflareTempEmailAdminAuth !== undefined) {
- inputTempEmailAdminAuth.value = message.payload.cloudflareTempEmailAdminAuth || '';
- }
- if (message.payload.cloudflareTempEmailCustomAuth !== undefined) {
- inputTempEmailCustomAuth.value = message.payload.cloudflareTempEmailCustomAuth || '';
- }
- if (message.payload.cloudflareTempEmailReceiveMailbox !== undefined) {
- inputTempEmailReceiveMailbox.value = message.payload.cloudflareTempEmailReceiveMailbox || '';
- }
- if (message.payload.cloudflareTempEmailDomain !== undefined || message.payload.cloudflareTempEmailDomains !== undefined) {
- renderCloudflareTempEmailDomainOptions(message.payload.cloudflareTempEmailDomain || latestState?.cloudflareTempEmailDomain || '');
- }
- if (message.payload.currentHotmailAccountId !== undefined || message.payload.hotmailAccounts !== undefined) {
- renderHotmailAccounts();
- if (selectMailProvider.value === 'hotmail-api') {
- inputEmail.value = getCurrentHotmailEmail();
- }
- }
- if (message.payload.luckmailApiKey !== undefined) {
- inputLuckmailApiKey.value = message.payload.luckmailApiKey || '';
- }
- if (message.payload.luckmailBaseUrl !== undefined) {
- inputLuckmailBaseUrl.value = normalizeLuckmailBaseUrl(message.payload.luckmailBaseUrl);
- }
- if (message.payload.luckmailEmailType !== undefined) {
- selectLuckmailEmailType.value = normalizeLuckmailEmailType(message.payload.luckmailEmailType);
- }
- if (message.payload.luckmailDomain !== undefined) {
- inputLuckmailDomain.value = message.payload.luckmailDomain || '';
- }
- if (message.payload.luckmailUsedPurchases !== undefined && isLuckmailProvider()) {
- queueLuckmailPurchaseRefresh();
- }
- if (message.payload.currentLuckmailPurchase !== undefined && isLuckmailProvider()) {
- inputEmail.value = getCurrentLuckmailEmail();
- queueLuckmailPurchaseRefresh();
- }
- if (message.payload.autoDeleteUsedIcloudAlias !== undefined && checkboxAutoDeleteIcloud) {
- checkboxAutoDeleteIcloud.checked = Boolean(message.payload.autoDeleteUsedIcloudAlias);
- }
- if (message.payload.accountRunHistoryTextEnabled !== undefined && inputAccountRunHistoryTextEnabled) {
- inputAccountRunHistoryTextEnabled.checked = Boolean(message.payload.accountRunHistoryTextEnabled);
- updateAccountRunHistorySettingsUI();
- }
- if (message.payload.accountRunHistoryHelperBaseUrl !== undefined && inputAccountRunHistoryHelperBaseUrl) {
- inputAccountRunHistoryHelperBaseUrl.value = normalizeAccountRunHistoryHelperBaseUrlValue(message.payload.accountRunHistoryHelperBaseUrl);
- }
- if (message.payload.icloudHostPreference !== undefined && selectIcloudHostPreference) {
- const hostPreference = String(message.payload.icloudHostPreference || '').trim().toLowerCase();
- selectIcloudHostPreference.value = hostPreference === 'icloud.com'
- ? 'icloud.com'
- : (hostPreference === 'icloud.com.cn' ? 'icloud.com.cn' : 'auto');
- }
- if (message.payload.autoRunSkipFailures !== undefined) {
- inputAutoSkipFailures.checked = Boolean(message.payload.autoRunSkipFailures);
- updateFallbackThreadIntervalInputState();
- }
- if (message.payload.autoRunDelayEnabled !== undefined) {
- inputAutoDelayEnabled.checked = Boolean(message.payload.autoRunDelayEnabled);
- updateAutoDelayInputState();
- }
- if (message.payload.autoRunDelayMinutes !== undefined) {
- inputAutoDelayMinutes.value = String(normalizeAutoDelayMinutes(message.payload.autoRunDelayMinutes));
- }
- if (message.payload.autoRunFallbackThreadIntervalMinutes !== undefined) {
- inputAutoSkipFailuresThreadIntervalMinutes.value = String(
- normalizeAutoRunThreadIntervalMinutes(message.payload.autoRunFallbackThreadIntervalMinutes)
- );
- updateFallbackThreadIntervalInputState();
- }
- if (message.payload.autoStepDelaySeconds !== undefined) {
- inputAutoStepDelaySeconds.value = formatAutoStepDelayInputValue(message.payload.autoStepDelaySeconds);
- }
- break;
- }
- case 'ICLOUD_LOGIN_REQUIRED': {
- const loginMessage = '需要登录 iCloud,我已经为你打开登录页。';
- showToast(loginMessage, 'warn', 5000);
- if (icloudSummary) {
- icloudSummary.textContent = loginMessage;
- }
- showIcloudLoginHelp(message.payload || {});
- break;
- }
- case 'ICLOUD_ALIASES_CHANGED': {
- queueIcloudAliasRefresh();
- break;
- }
- case 'AUTO_RUN_STATUS': {
- syncLatestState({
- autoRunning: ['scheduled', 'running', 'waiting_step', 'waiting_email', 'retrying', 'waiting_interval'].includes(message.payload.phase),
- autoRunPhase: message.payload.phase,
- autoRunCurrentRun: message.payload.currentRun,
- autoRunTotalRuns: message.payload.totalRuns,
- autoRunAttemptRun: message.payload.attemptRun,
- scheduledAutoRunAt: message.payload.scheduledAt ?? null,
- autoRunCountdownAt: message.payload.countdownAt ?? null,
- autoRunCountdownTitle: message.payload.countdownTitle ?? '',
- autoRunCountdownNote: message.payload.countdownNote ?? '',
- });
- applyAutoRunStatus(message.payload);
- updateStatusDisplay(latestState);
- updateButtonStates();
- break;
- }
- }
- });
- // ============================================================
- // Theme Toggle
- // ============================================================
- const btnTheme = document.getElementById('btn-theme');
- function setTheme(theme) {
- document.documentElement.setAttribute('data-theme', theme);
- localStorage.setItem('multipage-theme', theme);
- }
- function initTheme() {
- const saved = localStorage.getItem('multipage-theme');
- if (saved) {
- setTheme(saved);
- } else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
- setTheme('dark');
- }
- }
- btnTheme.addEventListener('click', () => {
- const current = document.documentElement.getAttribute('data-theme');
- setTheme(current === 'dark' ? 'light' : 'dark');
- });
- document.addEventListener('click', (event) => {
- if (!configMenuOpen) {
- return;
- }
- if (configMenuShell?.contains(event.target)) {
- return;
- }
- closeConfigMenu();
- });
- document.addEventListener('keydown', (event) => {
- if (event.key === 'Escape' && configMenuOpen) {
- closeConfigMenu();
- }
- });
- // ============================================================
- // Init
- // ============================================================
- initializeManualStepActions();
- initTheme();
- initHotmailListExpandedState();
- updateSaveButtonState();
- updateConfigMenuControls();
- setLocalCpaStep9Mode(DEFAULT_LOCAL_CPA_STEP9_MODE);
- setCpaCallbackMode(DEFAULT_CPA_CALLBACK_MODE);
- setMail2925Mode(DEFAULT_MAIL_2925_MODE);
- initializeReleaseInfo().catch((err) => {
- console.error('Failed to initialize release info:', err);
- });
- restoreState().then(() => {
- syncPasswordToggleLabel();
- syncVpsUrlToggleLabel();
- syncVpsPasswordToggleLabel();
- updatePanelModeUI();
- updateButtonStates();
- updateStatusDisplay(latestState);
- });
|