diff --git a/package-lock.json b/package-lock.json index 908d25c..6da8816 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "primorina", - "version": "1.13", + "version": "1.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "primorina", - "version": "1.13", + "version": "1.6", "license": "AGPL-3.0-or-later", "devDependencies": { "@types/google-apps-script": "^1.0.37" diff --git a/package.json b/package.json index f83ed27..fed6403 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "primorina", - "version": "1.21", + "version": "1.6", "description": "log primogems", "main": "index.js", "devDependencies": { diff --git a/src/config.ts b/src/config.ts index 6fabc8c..b80863a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,6 @@ // for license and source, visit https://github.com/3096/primorina -const SCRIPT_VERSION = "1.21"; +const SCRIPT_VERSION = "1.6"; const SHEET_SOURCE_ID = '1p-SkTsyzoxuKHqqvCJSUCaFBUmxd5uEEvCtb7bAqfDk'; const SHEET_SOURCE_SUPPORTED_LOCALE = "en_GB"; @@ -31,7 +31,13 @@ const SHEET_NAME_ARTIFACT_MONTHLY_REPORT = "Artifact Monthly Report"; const SHEET_NAME_WEAPON_LOG = "Weapon Log"; const SHEET_NAME_WEAPON_YEARLY_REPORT = "Weapon Yearly Report"; const SHEET_NAME_WEAPON_MONTHLY_REPORT = "Weapon Monthly Report"; +const SHEET_NAME_MASTERLESS_LOG = "Masterless Log"; +const SHEET_NAME_MASTERLESS_YEARLY_REPORT = "Masterless Yearly Report"; +const SHEET_NAME_MASTERLESS_MONTHLY_REPORT = "Masterless Monthly Report"; +const SHEET_NAME_STARGLITTER_LOG = "Starglitter Log"; +const SHEET_NAME_STARDUST_LOG = "Stardust Log"; const SHEET_NAME_KEY_ITEMS = "Key Items"; +const SHEET_NAME_REASON_MAP = "Reason Map"; const MONTHLY_SHEET_NAME = [ SHEET_NAME_PRIMOGEM_MONTHLY_REPORT, @@ -39,7 +45,8 @@ const MONTHLY_SHEET_NAME = [ SHEET_NAME_RESIN_MONTHLY_REPORT, SHEET_NAME_ARTIFACT_MONTHLY_REPORT, SHEET_NAME_WEAPON_MONTHLY_REPORT, - SHEET_NAME_MORA_MONTHLY_REPORT + SHEET_NAME_MORA_MONTHLY_REPORT, + SHEET_NAME_MASTERLESS_MONTHLY_REPORT ]; const NAME_OF_LOG_HISTORIES = [ @@ -47,7 +54,9 @@ const NAME_OF_LOG_HISTORIES = [ SHEET_NAME_CRYSTAL_LOG, SHEET_NAME_RESIN_LOG, SHEET_NAME_ARTIFACT_LOG, - SHEET_NAME_WEAPON_LOG + SHEET_NAME_WEAPON_LOG, + SHEET_NAME_STARGLITTER_LOG, + SHEET_NAME_STARDUST_LOG ]; const NAME_OF_LOG_HISTORIES_HOYOLAB = [ @@ -59,54 +68,143 @@ const LOG_CACHE_PREFIX = "CACHED"; // sheet info interface ILogSheetInfo { sheetName: string, - apiPaths: { [serverDivide in ServerDivide]: string } + endpointType: string, + apiPaths: { [serverDivide in ServerDivide]: string }, + header: { [headerName in HeaderName]: string } } const PRIMOGEM_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_PRIMOGEM_LOG, + endpointType: "feedback", apiPaths: { - cn: "/ysulog/api/getPrimogemLog", - os: "/ysulog/api/getPrimogemLog", + cn: "/common/hk4e_self_help_query/User/GetPrimogemLog", + os: "/common/hk4e_self_help_query/User/GetPrimogemLog", + }, + header: { + id: "id", + datetime: "datetime", + total: "add_num", + quantity: "quantity", + reasonId: "reason_id", + reasonDetail: "reason" } } const CRYSTAL_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_CRYSTAL_LOG, + endpointType: "feedback", apiPaths: { - cn: "/ysulog/api/getCrystalLog", - os: "/ysulog/api/getCrystalLog", + cn: "/common/hk4e_self_help_query/User/GetCrystalLog", + os: "/common/hk4e_self_help_query/User/GetCrystalLog", + }, + header: { + id: "id", + datetime: "datetime", + total: "add_num", + reasonId: "reason_id", + reasonDetail: "reason" } } const RESIN_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_RESIN_LOG, + endpointType: "feedback", apiPaths: { - cn: "/ysulog/api/getResinLog", - os: "/ysulog/api/getResinLog", + cn: "/common/hk4e_self_help_query/User/GetResinLog", + os: "/common/hk4e_self_help_query/User/GetResinLog", + }, + header: { + id: "id", + datetime: "datetime", + total: "add_num", + reasonId: "reason_id", + reasonDetail: "reason" } } const ARTIFACT_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_ARTIFACT_LOG, + endpointType: "feedback", apiPaths: { - cn: "/ysulog/api/getArtifactLog", - os: "/ysulog/api/getArtifactLog", + cn: "/common/hk4e_self_help_query/User/GetArtifactLog", + os: "/common/hk4e_self_help_query/User/GetArtifactLog", + }, + header: { + id: "id", + datetime: "datetime", + total: "add_num", + reasonId: "reason_id", + reasonDetail: "reason", + itemName: "name", + itemLevel: "level", + itemRarity: "quality" } } const MORA_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_MORA_LOG, + endpointType: "diary", apiPaths: { cn: "/event/ys_ledger/monthDetail", - os: "/event/ysledgeros/month_detail", + os: "/event/ysledgeros/month_detail" + }, + header: { + id: "id", + datetime: "time", + total: "num", + reasonId: "action_id", + reasonDetail: "action" } } const WEAPON_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_WEAPON_LOG, + endpointType: "feedback", apiPaths: { - cn: "/ysulog/api/getWeaponLog", - os: "/ysulog/api/getWeaponLog", + cn: "/common/hk4e_self_help_query/User/GetWeaponLog", + os: "/common/hk4e_self_help_query/User/GetWeaponLog", + }, + header: { + id: "id", + datetime: "datetime", + total: "add_num", + reasonId: "reason_id", + reasonDetail: "reason", + itemName: "name", + itemLevel: "level", + itemRarity: "quality" + } +} + +const MASTERLESS_STARGLITTER_SHEET_INFO: ILogSheetInfo = { + sheetName: SHEET_NAME_STARGLITTER_LOG, + endpointType: "feedback", + apiPaths: { + cn: "/common/hk4e_self_help_query/User/GetStarglitter", + os: "/common/hk4e_self_help_query/User/GetStarglitter", + }, + header: { + id: "id", + datetime: "datetime", + quantity: "quantity", + reasonDetail: "sub_action_name", + battlePathType: "battle_path_type" + } +} + +const MASTERLESS_STARDUST_SHEET_INFO: ILogSheetInfo = { + sheetName: SHEET_NAME_STARDUST_LOG, + endpointType: "feedback", + apiPaths: { + cn: "/common/hk4e_self_help_query/User/GetStardustLog", + os: "/common/hk4e_self_help_query/User/GetStardustLog", + }, + header: { + id: "id", + datetime: "datetime", + quantity: "quantity", + reasonDetail: "sub_action_name", + battlePathType: "battle_path_type" } } @@ -117,12 +215,14 @@ const USER_PREFERENCE_MONTHLY_REPORT = "Monthly Report"; const USER_PREFERENCE_YEARLY_REPORT = "Yearly Report"; // User Preferences const userPreferences = { - "Primogem Log": { "Monthly Report": "B35", "Yearly Report": "B36"}, - "Crystal Log": { "Monthly Report": "B38", "Yearly Report": "B39"}, - "Resin Log": { "Monthly Report": "B41", "Yearly Report": "B42"}, - "Mora Log": { "Monthly Report": "B44", "Yearly Report": "B45"}, - "Artifact Log": { "Monthly Report": "B47", "Yearly Report": "B48"}, - "Weapon Log": { "Monthly Report": "B50", "Yearly Report": "B51"} + "Primogem Log": { "Monthly Report": "B35", "Yearly Report": "B36", "Log Max Columns": 5}, + "Crystal Log": { "Monthly Report": "B38", "Yearly Report": "B39", "Log Max Columns": 5}, + "Resin Log": { "Monthly Report": "B41", "Yearly Report": "B42", "Log Max Columns": 5}, + "Mora Log": { "Monthly Report": "B44", "Yearly Report": "B45", "Log Max Columns": 5}, + "Artifact Log": { "Monthly Report": "B47", "Yearly Report": "B48", "Log Max Columns": 8}, + "Weapon Log": { "Monthly Report": "B50", "Yearly Report": "B51", "Log Max Columns": 8}, + "Starglitter Log": { "Monthly Report": "B53", "Yearly Report": "B54", "Log Max Columns": 5}, + "Stardust Log": { "Monthly Report": "B53", "Yearly Report": "B54", "Log Max Columns": 5} } // Remove when using the 'Available' sheet from source, this is for backwards compatibility for v1.0 less. Artifact is done via 'Available' sheet from source const userPreferencesForReport = { @@ -149,7 +249,9 @@ const languageSettingsForImport = { "Korean": { "code": "ko", "full_code": "ko-kr", "4_star": " (★4)", "5_star": " (★5)" }, "Portuguese": { "code": "pt", "full_code": "pt-pt", "4_star": " (4★)", "5_star": " (5★)" }, "Thai": { "code": "th", "full_code": "th-th", "4_star": " (4 ดาว)", "5_star": " (5 ดาว)" }, - "Russian": { "code": "ru", "full_code": "ru-ru", "4_star": " (4★)", "5_star": " (5★)" } + "Russian": { "code": "ru", "full_code": "ru-ru", "4_star": " (4★)", "5_star": " (5★)" }, + "Italian": { "code": "it", "full_code": "it-it", "4_star": " (4 ★)", "5_star": " (5 ★)" }, + "Turkish": { "code": "tr", "full_code": "tr-tr", "4_star": " (4 Yıldızlı)", "5_star": " (5 Yıldızlı)" } }; // region diff --git a/src/genshinApi.ts b/src/genshinApi.ts index 5dc8e65..f6b5b8e 100644 --- a/src/genshinApi.ts +++ b/src/genshinApi.ts @@ -7,13 +7,21 @@ type LocaleCode = "ja-jp" | "vi-vn" | "ko-kr" | "pt-pt" | "th-th" | "ru-ru"; const API_DOMAINS_BY_SERVER_DIVIDE = { - cn: "hk4e-api.mihoyo.com", - os: "hk4e-api-os.hoyoverse.com", + feedback: { + cn: "public-operation-hk4e.mihoyo.com", + os: "public-operation-hk4e-sg.hoyoverse.com", + }, + diary: { + cn: "hk4e-api.mihoyo.com", + os: "sg-hk4e-api.hoyolab.com", + } } const KNOWN_DOMAIN_LIST = [ { domain: "user.mihoyo.com", serverDivide: "cn" }, { domain: "account.mihoyo.com", serverDivide: "os" }, + { domain: "cs.hoyoverse.com", serverDivide: "os" }, + { domain: "gs.hoyoverse.com", serverDivide: "os" }, { domain: "account.hoyoverse.com", serverDivide: "os" }, { domain: "webstatic.mihoyo.com", serverDivide: "cn" }, @@ -76,8 +84,12 @@ interface ImServiceLogEntry { id: string, uid: string, time: string, + datetime: string, add_num: string, reason: string, + quantity: number, + sub_action_name: string, + battle_path_type: string } interface ImServiceLogData { @@ -99,11 +111,19 @@ interface ImServiceApiResponse { // ledger interface LedgerCookieCn extends Cookies { - account_id: string, cookie_token: string + account_id: string, + cookie_token: string, + bind_uid: string, + bind_region: string, + ltuid_v2: string, + ltoken_v2: string, + ltmid_v2: string, } interface LedgerCookieOs extends Cookies { - ltoken: string, ltuid: string + ltuid_v2: string, + ltoken_v2: string, + ltmid_v2: string, } interface LedgerParams extends Params { @@ -210,24 +230,24 @@ function getApiRequest(endpoint: string, params: Params, cookies: Cookies = null return request; } -function getReasonMap(config = getConfig()) { - const LANG_MAP_URL = `https://mi18n-os.mihoyo.com/webstatic/admin/mi18n/hk4e_global/m02251421001311/m02251421001311-${config.languageCode}.json`; +function getReasonMap(config = getConfig()): Map { + const LANG_MAP_URL = `https://webstatic.hoyoverse.com/admin/mi18n/hk4e_global/m02251421001311/m02251421001311-${config.languageCode}.json`; const REASON_PREFIX = "selfinquiry_general_reason_"; const langMap = JSON.parse(UrlFetchApp.fetch(LANG_MAP_URL).getContentText()); - const result = new Map(); + const result = new Map(); for (const key in langMap) { if (!key.includes(REASON_PREFIX)) continue; const reasonId = parseInt(key.substring(REASON_PREFIX.length)); - result.set(reasonId, langMap[key]); + result.set(langMap[key], reasonId); } return result; } function getApiEndpoint(logSheetInfo: ILogSheetInfo, serverDivide: ServerDivide) { - return "https://" + API_DOMAINS_BY_SERVER_DIVIDE[serverDivide] + logSheetInfo.apiPaths[serverDivide]; + return "https://" + API_DOMAINS_BY_SERVER_DIVIDE[logSheetInfo.endpointType][serverDivide] + logSheetInfo.apiPaths[serverDivide]; } function getServerDivideFromUrl(url: string) { diff --git a/src/import.ts b/src/import.ts index cbc0396..1b8d7d1 100644 --- a/src/import.ts +++ b/src/import.ts @@ -77,13 +77,73 @@ function warnLogsNotMatched(logSheetInfo: ILogSheetInfo, settingsSheet: GoogleAp return true; } +function findReasonId(reasonDetailName :string, entry: ImServiceLogEntry, reasonMap) { + let findKey = entry[reasonDetailName]; + let foundIdFromMap = 0; + + // Find mapping first from document, very useful in overriding miHoYo random reason change + if (localReasonMap == null) { + getPopulateReasonMap(); + } + foundIdFromMap = localReasonMap[findKey]; + + if (foundIdFromMap == null) { + // Find from miHoYo + foundIdFromMap = reasonMap.get(findKey); + } + if (foundIdFromMap == null) { + // Unable to find within document or miHoYo + foundIdFromMap = 0; + } + return foundIdFromMap; +} + +var localReasonMap; + +function getPopulateReasonMap() { + let reasonMapSheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME_REASON_MAP); + localReasonMap = []; + let reasonMapData; + if (reasonMapSheet) { + reasonMapData = reasonMapSheet.getDataRange().getValues(); + } else { + reasonMapSheet = loadReasonMapSheet(); + if (reasonMapSheet) { + reasonMapData = reasonMapSheet.getDataRange().getValues(); + } + } + if (reasonMapData) { + reasonMapData.forEach(function (row, index) { + if (index > 0) { + localReasonMap[row[1]] = row[0]; + } + }); + } + return reasonMapSheet; +} + function writeImServiceLogToSheet(logSheetInfo: ILogSheetInfo) { const config = getConfig(); const settingsSheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME_SETTINGS); const logSheet = SpreadsheetApp.getActive().getSheetByName(logSheetInfo.sheetName); - const curValues = logSheet.getDataRange().getValues(); - const logHeaderRow = curValues[0]; - const previousLogCount = curValues.length - 1; + let curValues = logSheet.getDataRange().getValues(); + let logHeaderRow = curValues[0]; + try { + // Test if headers are correct before proceeding + let checkColumns = [logSheetInfo.header.id, logSheetInfo.header.datetime, logSheetInfo.header.ReasonId, logSheetInfo.header.reasonDetail]; + + if (logSheetInfo.sheetName == SHEET_NAME_ARTIFACT_LOG || logSheetInfo.sheetName == SHEET_NAME_WEAPON_LOG) { + checkColumns.push(logSheetInfo.header.itemRarity, logSheetInfo.header.itemLevel,logSheetInfo.header.itemRarity); + } + getRowProperties(logHeaderRow, curValues[0], checkColumns); + } catch (err) { + addFormulaByLogName(logSheetInfo.sheetName); + // Reload only the header row + var logSourceNumberOfColumnWithFormulas = logSheet.getLastColumn(); + logHeaderRow = logSheet.getRange(1, 1, 1, logSourceNumberOfColumnWithFormulas).getValues()[0]; + }; + + let previousLogCount = curValues.length - 1; const reasonMap = getReasonMap(config); let authKey: string, serverDivide: ServerDivide; @@ -99,7 +159,7 @@ function writeImServiceLogToSheet(logSheetInfo: ILogSheetInfo) { let lastLogId: string = null; let lastLogDate: number = null; if (previousLogCount) { - const [lastLogIdStr, lastLogDateStr] = getRowProperties(logHeaderRow, curValues[1], ["id", "time"]); + const [lastLogIdStr, lastLogDateStr] = getRowProperties(logHeaderRow, curValues[1], [logSheetInfo.header.id, logSheetInfo.header.datetime]); lastLogId = lastLogIdStr; lastLogDate = Date.parse(lastLogDateStr); } @@ -122,7 +182,8 @@ function writeImServiceLogToSheet(logSheetInfo: ILogSheetInfo) { const stoppingMatched = addEntriesToRows(entries, logHeaderRow, newRows, lastLogDate, (entry: ImServiceLogEntry) => entry.id === lastLogId, { - "detail": (entry: ImServiceLogEntry) => reasonMap.get(parseInt(entry.reason)) + [logSheetInfo.header.total]: (entry: ImServiceLogEntry) => parseInt(entry.add_num), // Conversion needed due to GetCrystalLog outputting string, example '+300' + [logSheetInfo.header.reasonId]: (entry: ImServiceLogEntry) => findReasonId(logSheetInfo.header.reasonDetail, entry, reasonMap)// There is no reason id, must cross match reason details } ); if (stoppingMatched) { @@ -149,8 +210,26 @@ function writeImServiceLogToSheet(logSheetInfo: ILogSheetInfo) { // if import takes too long, cache results before Google kills the run const importStartTime = Date.now(); + function writeLedgerLogToSheet(logSheetInfo: ILogSheetInfo) { - const COMPARING_PROPS = ["time", "num", "action_id"]; + const COMPARING_PROPS = [logSheetInfo.header.datetime, logSheetInfo.header.total, logSheetInfo.header.reasonId]; + + const logSheet = SpreadsheetApp.getActive().getSheetByName(logSheetInfo.sheetName); + + let curValues = logSheet.getDataRange().getValues(); + let logHeaderRow = curValues[0]; + + try { + // Test if headers are correct before proceeding + let checkColumns = [logSheetInfo.header.id, logSheetInfo.header.datetime, logSheetInfo.header.reasonId, logSheetInfo.header.reasonDetail]; + getRowProperties(logHeaderRow, curValues[0], checkColumns); + } catch (err) { + addFormulaByLogName(logSheetInfo.sheetName); + // Reload only the header row + var logSourceNumberOfColumnWithFormulas = logSheet.getLastColumn(); + logHeaderRow = logSheet.getRange(1, 1, 1, logSourceNumberOfColumnWithFormulas).getValues()[0]; + }; + const isSameRowValue = (row0: string[], row1: string[], row0Proc = null, row1Proc = null) => { const props0 = getRowProperties(logHeaderRow, row0, COMPARING_PROPS, row0Proc); const props1 = getRowProperties(logHeaderRow, row1, COMPARING_PROPS, row1Proc); @@ -159,18 +238,26 @@ function writeLedgerLogToSheet(logSheetInfo: ILogSheetInfo) { const config = getConfig(); const settingsSheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME_SETTINGS); - const logSheet = SpreadsheetApp.getActive().getSheetByName(logSheetInfo.sheetName); - let curValues = logSheet.getDataRange().getValues(); - const logHeaderRow = curValues[0]; const previousLogCount = curValues.length - 1; const serverDivide = REGION_INFO[config.regionCode].serverDivide; let cookies: Cookies; serverDivideSpecificOp(serverDivide, { - cn: () => { (cookies as LedgerCookieCn) = { cookie_token: ltokenInput, account_id: ltuidInput }; }, - os: () => { (cookies as LedgerCookieOs) = { ltoken: ltokenInput, ltuid: ltuidInput }; } + cn: () => { (cookies as LedgerCookieCn) = { + cookie_token: ltokenInput, + account_id: ltuidInput, + ltmid_v2: ltmidInput, + bind_uid: guidInput}; + }, + os: () => { (cookies as LedgerCookieOs) = { + ltoken_v2: ltokenInput, + ltuid_v2: ltuidInput, + ltmid_v2: ltmidInput, + ltoken: ltokenInput, + ltuid: ltuidInput + }} }); const curYear = getServerTimeAsUtcNow(config.regionCode).getUTCFullYear(); @@ -181,7 +268,8 @@ function writeLedgerLogToSheet(logSheetInfo: ILogSheetInfo) { if (serverDivide === "os") { params.lang = config.languageCode; } - + params.uid = guidInput; + params.page_size = 100; const endpoint = getApiEndpoint(logSheetInfo, serverDivide); const apiResponseMonthsAvailable = (requestApiResponse(endpoint, params, cookies) as LedgerApiResponse).data.optional_month; @@ -198,7 +286,7 @@ function writeLedgerLogToSheet(logSheetInfo: ILogSheetInfo) { let trimToRowIdx = 1; if (trimToRowIdx < curValues.length) { const rowIsInAvailableLogRange = (row: string[]) => { - const [timeStr] = getRowProperties(logHeaderRow, row, ["time"]); + const [timeStr] = getRowProperties(logHeaderRow, row, [logSheetInfo.header.datetime]); const apiTimeAsUtc = getApiTimeAsServerTimeAsUtc(timeStr); // having getMonth start at Jan = 0 is the stupidest thing ive ever seen return apiResponseMonthsAvailableWithYear.includes( @@ -232,7 +320,7 @@ function writeLedgerLogToSheet(logSheetInfo: ILogSheetInfo) { let monthsToImport = apiResponseMonthsAvailable; if (hasPreviousLogInRange) { const [lastImportedLogTimeStr, lastImportedLogNumStr, lastImportedLogActionStr] - = getRowProperties(logHeaderRow, curValues[1], ["time", "num", "action_id"]); + = getRowProperties(logHeaderRow, curValues[1], [logSheetInfo.header.datetime, logSheetInfo.header.total, logSheetInfo.header.reasonId]); lastImportedLogTime = Date.parse(ensureApiTime(lastImportedLogTimeStr)); lastImportedLogNum = parseInt(lastImportedLogNumStr); lastImportedLogAction = parseInt(lastImportedLogActionStr); @@ -423,6 +511,8 @@ const getResinLog = () => writeImServiceLogToSheet(RESIN_SHEET_INFO); const getArtifactLog = () => writeImServiceLogToSheet(ARTIFACT_SHEET_INFO); const getWeaponLog = () => writeImServiceLogToSheet(WEAPON_SHEET_INFO); const getMoraLog = () => writeLedgerLogToSheet(MORA_SHEET_INFO); +const getStarglitterLog = () => writeImServiceLogToSheet(MASTERLESS_STARGLITTER_SHEET_INFO); +const getStardustLog = () => writeImServiceLogToSheet(MASTERLESS_STARDUST_SHEET_INFO); const LOG_RANGES = { "Primogem Log": { "range_status": "E26", "range_toggle": "E19", "range_dashboard_length": "C15" }, @@ -430,11 +520,15 @@ const LOG_RANGES = { "Resin Log": { "range_status": "E28", "range_toggle": "E21", "range_dashboard_length": "C25" }, "Artifact Log": { "range_status": "E29", "range_toggle": "E22", "range_dashboard_length": "C35" }, "Weapon Log": { "range_status": "E46", "range_toggle": "E45", "range_dashboard_length": "C40" }, - "Mora Log": { "range_status": "E39", "range_toggle": "E35", "range_dashboard_length": "C30" } + "Mora Log": { "range_status": "E39", "range_toggle": "E35", "range_dashboard_length": "C30" }, + "Starglitter Log": { "range_status": "E48", "range_toggle": "E47", "range_dashboard_length": "C45" }, + "Stardust Log": { "range_status": "E50", "range_toggle": "E49", "range_dashboard_length": "C49" }, }; const ltokenInput: string; -const ltuidInput: string; +const ltuidInput: number; +const ltmidInput: string; +const guidInput: number; function importFromAPI() { var settingsSheet = getSettingsSheet(); @@ -467,6 +561,10 @@ function importFromAPI() { getArtifactLog(); } else if (logName == SHEET_NAME_WEAPON_LOG) { getWeaponLog(); + } else if (logName == SHEET_NAME_STARGLITTER_LOG) { + getStarglitterLog(); + } else if (logName == SHEET_NAME_STARDUST_LOG) { + getStardustLog(); } else { settingsSheet.getRange(bannerSettings['range_status']).setValue("Error log sheet"); } @@ -481,6 +579,61 @@ function importFromAPI() { settingsSheet.getRange("E25").setValue(new Date()); } +function loadImportFromHoYoLAB() { + var settingsSheet = getSettingsSheet(); + loadHoYoLabData(settingsSheet); + importFromHoYoLAB(); +} + +function loadHoYoLABUIDPopup(settingsSheet) { + const result = displayUserPrompt("Auto Import with HoYoLab", `Enter ltuid/account_id_v2 to proceed.\nPress 'Yes' to amend\nPress 'No' to keep saved setting:\n`+ltuidInput, SpreadsheetApp.getUi().ButtonSet.YES_NO_CANCEL); + + var button = result.getSelectedButton(); + if (button == SpreadsheetApp.getUi().Button.YES) { + ltuidInput = result.getResponseText(); + if (isHoYoIdCorrect(ltuidInput)) { + settingsSheet.getRange("E31").setValue(ltuidInput); + loadHoYoLABMIDPopup(settingsSheet); + } else { + settingsSheet.getRange(LOG_RANGES[SHEET_NAME_MORA_LOG]['range_status']).setValue("account_id_v2 is invalid"); + } + } else if (button == SpreadsheetApp.getUi().Button.NO) { + loadHoYoLABMIDPopup(settingsSheet); + } else { + settingsSheet.getRange(LOG_RANGES[SHEET_NAME_MORA_LOG]['range_status']).setValue("User cancelled process"); + } +} + +function loadHoYoLABMIDPopup(settingsSheet) { + const result = displayUserPrompt("Auto Import with HoYoLab", `Enter account_mid_v2 to proceed.\nPress 'Yes' to amend\nPress 'No' to keep saved setting:\n`+ltmidInput, SpreadsheetApp.getUi().ButtonSet.YES_NO_CANCEL); + + var button = result.getSelectedButton(); + if (button == SpreadsheetApp.getUi().Button.YES) { + ltmidInput = result.getResponseText(); + settingsSheet.getRange("E32").setValue(ltmidInput); + loadGenshinImpactUIDPopup(settingsSheet); + } else if (button == SpreadsheetApp.getUi().Button.NO) { + loadGenshinImpactUIDPopup(settingsSheet); + } else { + settingsSheet.getRange(LOG_RANGES[SHEET_NAME_MORA_LOG]['range_status']).setValue("User cancelled process"); + } +} + +function loadGenshinImpactUIDPopup(settingsSheet) { + const result = displayUserPrompt("Auto Import with HoYoLab", `Enter Genshin Impact UID to proceed.\nPress 'Yes' to amend\nPress 'No' to keep saved setting:\n`+guidInput, SpreadsheetApp.getUi().ButtonSet.YES_NO_CANCEL); + + var button = result.getSelectedButton(); + if (button == SpreadsheetApp.getUi().Button.YES) { + guidInput = result.getResponseText(); + settingsSheet.getRange("E33").setValue(guidInput); + importFromHoYoLAB(settingsSheet); + } else if (button == SpreadsheetApp.getUi().Button.NO) { + importFromHoYoLAB(settingsSheet); + } else { + settingsSheet.getRange(LOG_RANGES[SHEET_NAME_MORA_LOG]['range_status']).setValue("User cancelled process"); + } +} + function importFromHoYoLAB() { var settingsSheet = getSettingsSheet(); settingsSheet.getRange("E37").setValue(new Date()); @@ -502,17 +655,16 @@ function importFromHoYoLAB() { bannerSheet = SpreadsheetApp.getActive().getSheetByName(logName); if (bannerSheet) { if (logName == SHEET_NAME_MORA_LOG) { - ltuidInput = settingsSheet.getRange("D33").getValue(); - if (ltuidInput.length == 0) { - const result = displayUserPrompt("Auto Import with HoYoLab", `Enter HoYoLAB UID to proceed\n.`); + if (guidInput.length == 0) { + const result = displayUserPrompt("Auto Import with HoYoLab", `Enter Genshin Impact UID to proceed.\n`, SpreadsheetApp.getUi().ButtonSet.OK_CANCEL); var button = result.getSelectedButton(); if (button == SpreadsheetApp.getUi().Button.OK) { - ltuidInput = result.getResponseText(); - if (isHoYoIdCorrect(ltuidInput)) { - settingsSheet.getRange("D33").setValue(ltuidInput); + guidInput = result.getResponseText(); + if (guidInput.length > 0) { + settingsSheet.getRange("E33").setValue(guidInput); getMoraLog(); } else { - settingsSheet.getRange(bannerSettings['range_status']).setValue("HoYoLAB is invalid"); + settingsSheet.getRange(bannerSettings['range_status']).setValue("Genshin Impact UID is empty"); } } else { settingsSheet.getRange(bannerSettings['range_status']).setValue("User cancelled process"); @@ -533,7 +685,7 @@ function importFromHoYoLAB() { settingsSheet.getRange("E38").setValue(new Date()); } -function isHoYoIdCorrect(userInput: string) { +function isHoYoIdCorrect(userInput: string): boolean { let isValid = false; if (userInput.match(/^[0-9]+$/) != null) { isValid = true; diff --git a/src/setup.ts b/src/setup.ts index bffd2b2..e434058 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -28,12 +28,13 @@ function generateInitialiseToolbar() { .addToUi(); } -function displayUserPrompt(titlePrompt: string, messagePrompt: string) { +function displayUserPrompt(titlePrompt: string, messagePrompt: string, buttonSet) { const ui = SpreadsheetApp.getUi(); var result = ui.prompt( titlePrompt, messagePrompt, - SpreadsheetApp.getUi().ButtonSet.OK_CANCEL); + buttonSet + ); return result; } @@ -42,7 +43,8 @@ function displayUserAlert(titleAlert: string, messageAlert: string) { var result = ui.alert( titleAlert, messageAlert, - SpreadsheetApp.getUi().ButtonSet.OK_CANCEL); + SpreadsheetApp.getUi().ButtonSet.OK_CANCEL + ); return result; } @@ -61,12 +63,23 @@ function getDefaultMenu() { var ui = SpreadsheetApp.getUi(); ui.createMenu('TCBS') .addSeparator() + .addSubMenu(ui.createMenu('Log') + .addItem('Add Formula For Primogem', 'addFormulaPrimogemLog') + .addItem('Add Formula For Crystal', 'addFormulaCrystalLog') + .addItem('Add Formula For Resin', 'addFormulaResinLog') + .addItem('Add Formula For Mora', 'addFormulaMoraLog') + .addItem('Add Formula For Artifact', 'addFormulaArtifactLog') + .addItem('Add Formula For Weapon', 'addFormulaWeaponLog') + .addItem('Add Formula For Starglitter', 'addFormulaStarglitterLog') + .addItem('Add Formula For Stardust', 'addFormulaStardustLog') + ) + .addSeparator() .addSubMenu(ui.createMenu('Data Management') - .addItem('Import', 'importDataManagement') - .addSeparator() - .addItem('Auto Import from miHoYo', 'importFromAPI') - .addItem('Auto Import from HoYoLAB', 'importFromHoYoLAB') - ) + .addItem('Import', 'importDataManagement') + .addSeparator() + .addItem('Auto Import from miHoYo', 'importFromAPI') + .addItem('Auto Import from HoYoLAB', 'loadImportFromHoYoLAB') + ) .addSeparator() .addItem('Quick Update', 'quickUpdate') .addItem('Update Items', 'updateItemsList') @@ -98,8 +111,168 @@ var listOfSheets = [ SHEET_NAME_WEAPON_LOG, SHEET_NAME_WEAPON_MONTHLY_REPORT, SHEET_NAME_WEAPON_YEARLY_REPORT, + SHEET_NAME_STARGLITTER_LOG, + SHEET_NAME_STARDUST_LOG, + SHEET_NAME_MASTERLESS_MONTHLY_REPORT, + SHEET_NAME_MASTERLESS_YEARLY_REPORT, SHEET_NAME_KEY_ITEMS ]; + +function loadReasonMapSheet(sheetSource = null) { + let reasonMapSheet; + if (sheetSource == null) { + // Avoid reloading source document + sheetSource = SpreadsheetApp.openById(SHEET_SOURCE_ID); + } + if (sheetSource) { + var reasonMapSource; + var settingsSheet = getSettingsSheet(); + if (settingsSheet) { + var languageFound = settingsSheet.getRange(2, 2).getValue(); + reasonMapSource = sheetSource.getSheetByName(SHEET_NAME_REASON_MAP+"-"+languageFound); + } + if (reasonMapSource) { + // Found language + } else { + // Default + reasonMapSource = sheetSource.getSheetByName(SHEET_NAME_REASON_MAP); + } + if (reasonMapSource) { + reasonMapSheet = reasonMapSource.copyTo(SpreadsheetApp.getActiveSpreadsheet()); + reasonMapSheet.setName(SHEET_NAME_REASON_MAP); + reasonMapSheet.hideSheet(); + } + } + return reasonMapSheet; +} + +/** +* Add Formula Primogem Log +*/ +function addFormulaPrimogemLog() { + addFormulaByLogName(SHEET_NAME_PRIMOGEM_LOG); +} +/** +* Add Formula Crystal Log +*/ +function addFormulaCrystalLog() { + addFormulaByLogName(SHEET_NAME_CRYSTAL_LOG); +} +/** +* Add Formula Resin Log +*/ +function addFormulaResinLog() { + addFormulaByLogName(SHEET_NAME_RESIN_LOG); +} +/** +* Add Formula Mora Log +*/ +function addFormulaMoraLog() { + addFormulaByLogName(SHEET_NAME_MORA_LOG); +} +/** +* Add Formula Artifact Log +*/ +function addFormulaArtifactLog() { + addFormulaByLogName(SHEET_NAME_ARTIFACT_LOG); +} +/** +* Add Formula Weapon Log +*/ +function addFormulaWeaponLog() { + addFormulaByLogName(SHEET_NAME_WEAPON_LOG); +} + +/** +* Add Formula Starglitter Log +*/ +function addFormulaStarglitterLog() { + addFormulaByLogName(SHEET_NAME_STARGLITTER_LOG); +} +/** +* Add Formula Stardust Log +*/ +function addFormulaStardustLog() { + addFormulaByLogName(SHEET_NAME_STARDUST_LOG); +} + +/** +* Add Formula for selected Log sheet +*/ +function addFormulaLog() { + var sheetActive = SpreadsheetApp.getActiveSpreadsheet(); + var logName = sheetActive.getSheetName(); + if (NAME_OF_LOG_HISTORIES.indexOf(logName) != -1) { + addFormulaByLogName(logName); + } else { + var message = 'Sheet must be called "' + SHEET_NAME_PRIMOGEM_LOG + '" or "' + SHEET_NAME_CRYSTAL_LOG + '" or "' + SHEET_NAME_RESIN_LOG + '" or "' + SHEET_NAME_MORA_LOG + '" or "' + SHEET_NAME_ARTIFACT_LOG + '" or "' + '" or "' + SHEET_NAME_STARGLITTER_LOG + '" or "' + '" or "' + SHEET_NAME_STARDUST_LOG + '" or "' + SHEET_NAME_WEAPON_LOG + '"'; + var title = 'Invalid Sheet Name'; + SpreadsheetApp.getActiveSpreadsheet().toast(message, title); + } +} + +/** +* Check is sheet exist in active spreadsheet, otherwise pull sheet from source +*/ +function findLogByName(name, sheetSource) { + var logSheet = SpreadsheetApp.getActive().getSheetByName(name); + if (logSheet == null) { + if (sheetSource == null) { + sheetSource = SpreadsheetApp.openById(SHEET_SOURCE_ID); + } + if (sheetSource) { + var sheetCopySource = sheetSource.getSheetByName(name); + sheetCopySource.copyTo(SpreadsheetApp.getActiveSpreadsheet()).setName(name); + logSheet = SpreadsheetApp.getActive().getSheetByName(name); + logSheet.showSheet(); + } + } + return logSheet; +} + +function addFormulaByLogName(name, sheetSource = null) { + if (sheetSource == null) { + // Avoid reloading source document + sheetSource = SpreadsheetApp.openById(SHEET_SOURCE_ID); + } + if (sheetSource) { + // Add Language + var logSource; + var settingsSheet = getSettingsSheet(); + if (settingsSheet) { + var languageFound = settingsSheet.getRange(2, 2).getValue(); + logSource = sheetSource.getSheetByName(name+"-"+languageFound); + } + if (logSource) { + // Found language + } else { + // Default + logSource = sheetSource.getSheetByName(name); + } + var sheet = findLogByName(name,sheetSource); + var logSourceNumberOfColumnWithFormulas = logSource.getLastColumn(); + + // Get title columns and set current sheet + var titleCells = logSource.getRange(1, 1, 1, logSourceNumberOfColumnWithFormulas).getFormulas(); + sheet.getRange(1, 1, 1, logSourceNumberOfColumnWithFormulas).setValues(titleCells); + + for (var i = 1; i <= logSourceNumberOfColumnWithFormulas; i++) { + // Set column width from source + sheet.setColumnWidth(i, logSource.getColumnWidth(i)); + var logSourceRange = logSource.getRange(1,i); + sheet.getRange(1,i).setTextStyle((logSourceRange.getTextStyle())); + sheet.getRange(1,i).setBackgroundColor(logSource.getRange(1,i).getBackgroundColor()); + } + + // Ensure new row is not the same height as first, if row 2 did not exist + sheet.autoResizeRows(2, 1); + } else { + var message = 'Unable to connect to source'; + var title = 'Error'; + SpreadsheetApp.getActiveSpreadsheet().toast(message, title); + } +} + function getSettingsSheet() { var settingsSheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME_SETTINGS); var sheetSource; @@ -196,6 +369,59 @@ function getSettingsSheet() { } checkUserPreferenceExist(settingsSheet); } + // Migration step for v1.5 loading Starglitter and Stardust user preferences + isAvailable = settingsSheet.getRange("D47").getValue(); + if (isAvailable == "") { + // Data Validation List updated + var rule = SpreadsheetApp.newDataValidation().requireValueInList(listOfSheets, true).build(); + settingsSheet.getRange(11,2,23,1).setBackground("white").setFontSize(10).setFontWeight(null).setHorizontalAlignment("center").setDataValidation(rule); + + settingsSheet.getRange(15,4,1,2).setBorder(false, false, false, false, false, false).breakApart(); + settingsSheet.getRange(16,4,1,2).breakApart(); + // Place Mora at bottom + settingsSheet.getRange("D16").setFontSize(10).setFontWeight("bold").setHorizontalAlignment("center").setValue(SHEET_NAME_MORA_LOG); + settingsSheet.getRange("E16").setFontSize(10).setFontWeight(null).setHorizontalAlignment("center").setValue(settingsSheet.getRange("E14").getValue()); + // Add Starglitter + settingsSheet.getRange("D14").setFontSize(10).setFontWeight("bold").setHorizontalAlignment("center").setValue(SHEET_NAME_STARGLITTER_LOG); + settingsSheet.getRange("E14").setFontSize(10).setFontWeight(null).setHorizontalAlignment("center").setValue('NOT DONE'); + // Add Stardust + settingsSheet.getRange("D15").setFontSize(10).setFontWeight("bold").setHorizontalAlignment("center").setValue(SHEET_NAME_STARDUST_LOG); + settingsSheet.getRange("E15").setFontSize(10).setFontWeight(null).setHorizontalAlignment("center").setValue('NOT DONE'); + settingsSheet.getRange(17,4,1,2).setBorder(true, false, false, false, false, false, "black", SpreadsheetApp.BorderStyle.SOLID); + + settingsSheet.getRange(47,4,2,1).mergeAcross().setFontSize(10).setFontWeight("bold").setHorizontalAlignment("center").setValue(SHEET_NAME_STARGLITTER_LOG); + settingsSheet.getRange("E47").setFontSize(10).setBackground("white").insertCheckboxes().setValue(true); + + settingsSheet.getRange(49,4,2,1).mergeAcross().setFontSize(10).setFontWeight("bold").setHorizontalAlignment("center").setValue(SHEET_NAME_STARDUST_LOG); + settingsSheet.getRange("E49").setFontSize(10).setBackground("white").insertCheckboxes().setValue(true); + + // Load Starglitter Log Sheet if missing + var starglitterLogSheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME_STARGLITTER_LOG); + if (!starglitterLogSheet) { + if (!sheetSource) { + sheetSource = SpreadsheetApp.openById(SHEET_SOURCE_ID); + } + var sheetStarglitterLogSource = sheetSource.getSheetByName(SHEET_NAME_STARGLITTER_LOG); + starglitterLogSheet = sheetStarglitterLogSource.copyTo(SpreadsheetApp.getActiveSpreadsheet()); + starglitterLogSheet.setName(SHEET_NAME_STARGLITTER_LOG); + } + // Load Stardust Log Sheet if missing + var stardustLogSheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME_STARDUST_LOG); + if (!stardustLogSheet) { + if (!sheetSource) { + sheetSource = SpreadsheetApp.openById(SHEET_SOURCE_ID); + } + var sheetStardustLogSource = sheetSource.getSheetByName(SHEET_NAME_STARDUST_LOG); + stardustLogSheet = sheetStardustLogSource.copyTo(SpreadsheetApp.getActiveSpreadsheet()); + stardustLogSheet.setName(SHEET_NAME_STARDUST_LOG); + } + // Remove old Dashboard if exist + var removeDashboardSheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME_DASHBOARD); + if (removeDashboardSheet) { + SpreadsheetApp.getActiveSpreadsheet().deleteSheet(removeDashboardSheet); + } + checkUserPreferenceExist(settingsSheet); + } } var dashboardSheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME_DASHBOARD); var isDashboardUpToDate = false; @@ -261,6 +487,19 @@ function checkUserPreferenceExist(settingsSheet) { settingsSheet.getRange(51,2).setBackground("white").setFontSize(10).setFontWeight(null).setHorizontalAlignment("center").setDataValidation(rulePreferences).setValue("YES"); settingsSheet.getRange(52,1,1,2).setBorder(true, false, false, false, false, false, "black", SpreadsheetApp.BorderStyle.SOLID).mergeAcross().setFontSize(11).setFontWeight("bold").setHorizontalAlignment("center").setValue(""); } + // Migration step for v1.5 + if(settingsSheet.getRange("A52").getValue() != SHEET_NAME_MASTERLESS_LOG) { + // Missing Masterless user preference + settingsSheet.insertRowsAfter(52,3); + + var rulePreferences = SpreadsheetApp.newDataValidation().requireValueInList(listOfPreferences, true).build(); + settingsSheet.getRange(52,1,1,2).setBorder(true, false, false, false, false, false, "black", SpreadsheetApp.BorderStyle.SOLID).mergeAcross().setFontSize(11).setFontWeight("bold").setHorizontalAlignment("center").setValue(SHEET_NAME_MASTERLESS_LOG); + settingsSheet.getRange(53,1).setFontSize(10).setFontWeight("bold").setHorizontalAlignment("center").setValue(USER_PREFERENCE_MONTHLY_REPORT); + settingsSheet.getRange(53,2).setBackground("white").setFontSize(10).setFontWeight(null).setHorizontalAlignment("center").setDataValidation(rulePreferences).setValue("YES"); + settingsSheet.getRange(54,1).setFontSize(10).setFontWeight("bold").setHorizontalAlignment("center").setValue(USER_PREFERENCE_YEARLY_REPORT); + settingsSheet.getRange(54,2).setBackground("white").setFontSize(10).setFontWeight(null).setHorizontalAlignment("center").setDataValidation(rulePreferences).setValue("YES"); + settingsSheet.getRange(55,1,1,2).setBorder(true, false, false, false, false, false, "black", SpreadsheetApp.BorderStyle.SOLID).mergeAcross().setFontSize(11).setFontWeight("bold").setHorizontalAlignment("center").setValue(""); + } } function updateDashboard(dashboardSheet) { diff --git a/src/sheets.ts b/src/sheets.ts index 32e1b43..53cb177 100644 --- a/src/sheets.ts +++ b/src/sheets.ts @@ -2,16 +2,16 @@ var dashboardEditRange = [ "I5", // Status cell - "AB28", // Document Version - "AT46", // Current Document Version - "T29", // Document Status + "AP40", // Document Version + "AT53", // Current Document Version + "AH41", // Document Status "AV1", // Name of drop down 1 (import) "AV2", // Name of drop down 2 (auto import) "AG14", // Selection "", // URL [NOT NEEDED PROMPT HANDLES URL] "AV3", // Name of drop down 3 (HoYoLAB) "AG16", // Name of user input - "A46", // Dashboard embedded or add-on notification + "A53", // Dashboard embedded or add-on notification ]; // Cells that needs refreshing @@ -43,6 +43,38 @@ function refreshMonthlyMonthText(monthlySheet, settingsSheet) { } } +function loadHoYoLabData(settingsSheet) { + if (settingsSheet.getRange("D30").isPartOfMerge()) { + // Migration process for v2.0 + settingsSheet.getRange("D30:E30").breakApart(); + settingsSheet.getRange("D30").setValue("cookie_token_v2").setBackground("#cccccc"); + settingsSheet.getRange("E30").setValue(settingsSheet.getRange("D31").getValue()).setBackground("white").setNumberFormat("@"); + + settingsSheet.getRange("D31:E31").breakApart(); + settingsSheet.getRange("D31").setValue("account_id_v2").setBackground("#cccccc"); + settingsSheet.getRange("E31").setValue(settingsSheet.getRange("D33").getValue()).setBackground("white").setNumberFormat("0"); + + settingsSheet.getRange("D32:E32").breakApart(); + settingsSheet.getRange("D32").setValue("account_mid_v2").setBackground("#cccccc"); + settingsSheet.getRange("E32").setValue("").setBackground("white").setNumberFormat("@"); + + settingsSheet.getRange("D33:E33").breakApart(); + settingsSheet.getRange("D33").setValue("Genshin Impact UID").setBackground("#cccccc"); + settingsSheet.getRange("E33").setValue("").setBackground("white").setNumberFormat("0"); + } + ltokenInput = settingsSheet.getRange("E30").getValue(); + + ltuidInput = settingsSheet.getRange("E31").getValue(); + if(ltuidInput) { + ltuidInput.toFixed(0); + } + ltmidInput = settingsSheet.getRange("E32").getValue(); + guidInput = settingsSheet.getRange("E33").getValue(); + if(guidInput) { + guidInput.toFixed(0); + } +} + function importButtonScript() { var settingsSheet = getSettingsSheet(); var dashboardSheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME_DASHBOARD); @@ -56,12 +88,20 @@ function importButtonScript() { if (userImportSelection != importSelectionText) { if (userAutoImportSelection == importSelectionText) { userInputText += "\n\nNote\nEntering an empty URL will try to load from previously saved Settings"; + // Too long to display URL to user for Auto Import from miHoYo } else { - userInputText += "\n\nNote\nEntering an empty HoYoLAB ltoken will try to load from previously saved Settings"; + loadHoYoLabData(settingsSheet); + userInputText = "Note\nEntering an empty HoYoLAB ltoken/cookie_token_v2 will try to load from previously saved Settings"; + userInputText += "\n\nPreviously Saved HoYoLab Cookies:\ncookie_token_v2: "+ltokenInput; + userInputText += "\nltuid/account_id_v2: "+ltuidInput; + userInputText += "\naccount_mid_v2: "+ltmidInput; + userInputText += "\nGenshin Impact UID: "+guidInput; + + userInputText += "\n\nEnter new cookie_token_v2 in textfield:"; } } - const resultURL = displayUserPrompt(importSelectionText, userInputText); + const resultURL = displayUserPrompt(importSelectionText, userInputText, SpreadsheetApp.getUi().ButtonSet.OK_CANCEL); var button = resultURL.getSelectedButton(); if (button == SpreadsheetApp.getUi().Button.OK) { var urlInput = resultURL.getResponseText(); @@ -73,9 +113,9 @@ function importButtonScript() { settingsSheet.getRange("D17").setValue(urlInput); importFromAPI(); } else { - settingsSheet.getRange("D31").setValue(urlInput); + settingsSheet.getRange("E30").setValue(urlInput); ltokenInput = urlInput; - importFromHoYoLAB(); + loadHoYoLABUIDPopup(settingsSheet); } } else { if (userImportSelection == importSelectionText) { @@ -85,16 +125,27 @@ function importButtonScript() { if (userAutoImportSelection == importSelectionText) { loadPreviousSetting = settingsSheet.getRange("D17").getValue(); } else { - loadPreviousSetting = settingsSheet.getRange("D31").getValue(); + loadPreviousSetting = ltokenInput; } if (loadPreviousSetting.length > 0) { - const result = displayUserAlert(importSelectionText, 'The user input is empty,\nwould you like to reuse previously stored data from settings?'); + var userInputText = 'The user input is empty,\nwould you like to reuse the previously stored data from settings?'; + + if (userAutoImportSelection == importSelectionText) { + // Too long to display URL to user for Auto Import from miHoYo + } else { + // Friendly reminder to user of HoYoLab detailed saving in settings + userInputText = 'Would you like to reuse these previously stored data from settings?'; + userInputText += "\n\nHoYoLab cookie_token_v2: "+loadPreviousSetting; + userInputText += "\nHoYoLAB account_id_v2: "+ltuidInput; + userInputText += "\nHoYoLAB account_mid_v2: "+ltmidInput; + userInputText += "\nGenshin Impact UID: "+guidInput; + } + const result = displayUserAlert(importSelectionText, userInputText); if (result == SpreadsheetApp.getUi().Button.OK) { // User wants to reuse previously stored data if (userAutoImportSelection == importSelectionText) { importFromAPI(); } else { - ltokenInput = settingsSheet.getRange("D31").getValue(); importFromHoYoLAB(); } } @@ -246,4 +297,8 @@ const moveToMoraMonthlyReportSheet = () => moveToSheetByName(SHEET_NAME_MORA_MON const moveToWeaponLogSheet = () => moveToSheetByName(SHEET_NAME_WEAPON_LOG); const moveToWeaponYearlyReportSheet = () => moveToSheetByName(SHEET_NAME_WEAPON_YEARLY_REPORT); const moveToWeaponMonthlyReportSheet = () => moveToSheetByName(SHEET_NAME_WEAPON_MONTHLY_REPORT); +const moveToStarglitterLogSheet = () => moveToSheetByName(SHEET_NAME_STARGLITTER_LOG); +const moveToStardustLogSheet = () => moveToSheetByName(SHEET_NAME_STARDUST_LOG); +const moveToMasterlessYearlyReportSheet = () => moveToSheetByName(SHEET_NAME_MASTERLESS_YEARLY_REPORT); +const moveToMasterlessMonthlyReportSheet = () => moveToSheetByName(SHEET_NAME_MASTERLESS_MONTHLY_REPORT); const moveToKeyItemsSheet = () => moveToSheetByName(SHEET_NAME_KEY_ITEMS); \ No newline at end of file diff --git a/src/update.ts b/src/update.ts index f4f9b78..d5d20af 100644 --- a/src/update.ts +++ b/src/update.ts @@ -187,13 +187,14 @@ function importDataManagement() { if (bannerImportSheet) { var numberOfRows = bannerImportSheet.getMaxRows() - 1; - var range = bannerImportSheet.getRange(2, 1, numberOfRows, 5); + var numberOfColumns = userPreferences[availableSheets[i]]["Log Max Columns"]; + var range = bannerImportSheet.getRange(2, 1, numberOfRows, numberOfColumns); if (numberOfRows > 0) { var bannerSheet = SpreadsheetApp.getActive().getSheetByName(availableSheets[i]); if (bannerSheet) { - bannerSheet.getRange(2, 1, numberOfRows, 5).setValues(range.getValues()); + bannerSheet.getRange(2, 1, numberOfRows, numberOfColumns).setValues(range.getValues()); dashboardSheet.getRange(LOG_RANGES[availableSheets[i]]['range_dashboard_length']).setValue(numberOfRows); settingsSheet.getRange(rowOfStatusWishHistory + i, 5).setValue(wishHistoryDoneStatus); @@ -229,6 +230,18 @@ function importDataManagement() { if (decimalFormat) { settingsSheet.getRange("B6").setValue(decimalFormat); } + var ltokenInput = sourceSettingsSheet.getRange("D30").getValue(); + if (ltokenInput) { + settingsSheet.getRange("D30").setValue(ltokenInput); + } + var ltuidInput = sourceSettingsSheet.getRange("D31").getValue(); + if (ltuidInput) { + settingsSheet.getRange("D31").setValue(ltuidInput); + } + var ltmidInput = sourceSettingsSheet.getRange("D32").getValue(); + if (ltmidInput) { + settingsSheet.getRange("D32").setValue(ltmidInput); + } var uid = sourceSettingsSheet.getRange("D33").getValue(); if (uid) { settingsSheet.getRange("D33").setValue(uid); @@ -322,7 +335,7 @@ function updateItemsList() { } } // Remove sheets - var listOfSheetsToRemove = [SHEET_NAME_ARTIFACT_ITEMS]; + var listOfSheetsToRemove = [SHEET_NAME_ARTIFACT_ITEMS, SHEET_NAME_REASON_MAP]; var availableRangesValues = sheetAvailableSource.getRange(2, 1, sheetAvailableSource.getMaxRows() - 1, 1).getValues(); var availableRanges = String(availableRangesValues).split(","); @@ -437,6 +450,11 @@ function updateItemsList() { } } } + // Reload header + for (var i = 0; i < listOfSheetsLength; i++) { + addFormulaByLogName(listOfSheets[i], sheetSource); + } + loadReasonMapSheet(sheetSource); // Remove placeholder if available if (placeHolderSheet) {