From 4d51fbdce91fb3284df8fb10ae4b29416c786cbb Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Mon, 10 Oct 2022 00:44:32 +0100 Subject: [PATCH 01/12] Update script version to v1.22 --- package.json | 2 +- src/config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f83ed27..4bcd3a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "primorina", - "version": "1.21", + "version": "1.22", "description": "log primogems", "main": "index.js", "devDependencies": { diff --git a/src/config.ts b/src/config.ts index 6fabc8c..b9ea0f4 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.22"; const SHEET_SOURCE_ID = '1p-SkTsyzoxuKHqqvCJSUCaFBUmxd5uEEvCtb7bAqfDk'; const SHEET_SOURCE_SUPPORTED_LOCALE = "en_GB"; From 81e691a758244a8f3ac2d48f48368934101445ed Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Wed, 31 May 2023 02:14:07 +0100 Subject: [PATCH 02/12] Provide a friendly reminder to user about the HoYoLab details saved in settings. --- src/sheets.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/sheets.ts b/src/sheets.ts index 32e1b43..e3bbf68 100644 --- a/src/sheets.ts +++ b/src/sheets.ts @@ -59,6 +59,17 @@ function importButtonScript() { } else { userInputText += "\n\nNote\nEntering an empty HoYoLAB ltoken will try to load from previously saved Settings"; } + + var loadPreviousKeySetting = ""; + if (userAutoImportSelection == importSelectionText) { + // Too long to display URL to user for Auto Import from miHoYo + } else { + loadPreviousKeySetting = settingsSheet.getRange("D31").getValue(); + if (loadPreviousKeySetting.length > 0) { + userInputText += "\nHoYoLab ltoken: "+loadPreviousKeySetting; + userInputText += "\nHoYoLAB UID: "+settingsSheet.getRange("D33").getValue(); + } + } } const resultURL = displayUserPrompt(importSelectionText, userInputText); @@ -88,7 +99,17 @@ function importButtonScript() { loadPreviousSetting = settingsSheet.getRange("D31").getValue(); } 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 ltoken: "+loadPreviousSetting; + userInputText += "\nHoYoLAB UID: "+settingsSheet.getRange("D33").getValue(); + } + const result = displayUserAlert(importSelectionText, userInputText); if (result == SpreadsheetApp.getUi().Button.OK) { // User wants to reuse previously stored data if (userAutoImportSelection == importSelectionText) { From ee1b87e1b8a0bbb0879e56f758ad56cc73da51ea Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Wed, 31 May 2023 02:26:29 +0100 Subject: [PATCH 03/12] Fix issue where Importing document would only transfer 5 columns, useful for artifact. --- src/update.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/update.ts b/src/update.ts index f4f9b78..fd0fa39 100644 --- a/src/update.ts +++ b/src/update.ts @@ -187,7 +187,8 @@ function importDataManagement() { if (bannerImportSheet) { var numberOfRows = bannerImportSheet.getMaxRows() - 1; - var range = bannerImportSheet.getRange(2, 1, numberOfRows, 5); + var numberOfColumns = bannerImportSheet.getMaxColumns(); + var range = bannerImportSheet.getRange(2, 1, numberOfRows, numberOfColumns); if (numberOfRows > 0) { var bannerSheet = SpreadsheetApp.getActive().getSheetByName(availableSheets[i]); From 9a9ae6244b6528f8e296eba95dc29bdc5a6b213b Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Wed, 31 May 2023 02:42:09 +0100 Subject: [PATCH 04/12] Fix: Log import where current document will not match with source get range --- src/config.ts | 12 ++++++------ src/update.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/config.ts b/src/config.ts index b9ea0f4..c2fa6bc 100644 --- a/src/config.ts +++ b/src/config.ts @@ -117,12 +117,12 @@ 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": 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 = { diff --git a/src/update.ts b/src/update.ts index fd0fa39..255bd3b 100644 --- a/src/update.ts +++ b/src/update.ts @@ -187,14 +187,14 @@ function importDataManagement() { if (bannerImportSheet) { var numberOfRows = bannerImportSheet.getMaxRows() - 1; - var numberOfColumns = bannerImportSheet.getMaxColumns(); + 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); From 2bc128f3d473a28c708e88eda396194836d4dcfb Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 1 Jun 2023 02:06:56 +0100 Subject: [PATCH 05/12] Support Italian and Turkish --- src/config.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index c2fa6bc..ec660c2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -149,7 +149,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 From 54adce2808842d853d1b9f8b2e98c107c8c10bfa Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 1 Jun 2023 02:09:22 +0100 Subject: [PATCH 06/12] Updated - Reason Mapping URL from miHoYo --- src/genshinApi.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/genshinApi.ts b/src/genshinApi.ts index 5dc8e65..9449109 100644 --- a/src/genshinApi.ts +++ b/src/genshinApi.ts @@ -76,6 +76,7 @@ interface ImServiceLogEntry { id: string, uid: string, time: string, + datetime: string, add_num: string, reason: string, } @@ -210,18 +211,18 @@ 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; } From 8f6abb14be8a913ccbcfd2208ffc5cec6cca5b46 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 1 Jun 2023 03:00:52 +0100 Subject: [PATCH 07/12] Fix extracting data from new URL Implement local reason map from source, to help override incorrect key names Implement formula redone for headers of each logs --- src/config.ts | 64 ++++++++++++++++++--- src/import.ts | 98 ++++++++++++++++++++++++++++---- src/setup.ts | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/update.ts | 7 ++- 4 files changed, 303 insertions(+), 19 deletions(-) diff --git a/src/config.ts b/src/config.ts index ec660c2..6120798 100644 --- a/src/config.ts +++ b/src/config.ts @@ -32,6 +32,7 @@ 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_KEY_ITEMS = "Key Items"; +const SHEET_NAME_REASON_MAP = "Reason Map"; const MONTHLY_SHEET_NAME = [ SHEET_NAME_PRIMOGEM_MONTHLY_REPORT, @@ -59,14 +60,22 @@ const LOG_CACHE_PREFIX = "CACHED"; // sheet info interface ILogSheetInfo { sheetName: string, - apiPaths: { [serverDivide in ServerDivide]: string } + apiPaths: { [serverDivide in ServerDivide]: string }, + header: { [headerName in HeaderName]: string } } const PRIMOGEM_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_PRIMOGEM_LOG, apiPaths: { cn: "/ysulog/api/getPrimogemLog", - os: "/ysulog/api/getPrimogemLog", + os: "/common/hk4e_self_help_query/User/GetPrimogemLog", + }, + header: { + id: "id", + datetime: "datetime", + total: "add_num", + reasonId: "reason_id", + reasonDetail: "reason" } } @@ -74,7 +83,14 @@ const CRYSTAL_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_CRYSTAL_LOG, apiPaths: { cn: "/ysulog/api/getCrystalLog", - os: "/ysulog/api/getCrystalLog", + os: "/common/hk4e_self_help_query/User/GetCrystalLog", + }, + header: { + id: "id", + datetime: "datetime", + total: "add_num", + reasonId: "reason_id", + reasonDetail: "reason" } } @@ -82,7 +98,14 @@ const RESIN_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_RESIN_LOG, apiPaths: { cn: "/ysulog/api/getResinLog", - os: "/ysulog/api/getResinLog", + os: "/common/hk4e_self_help_query/User/GetResinLog", + }, + header: { + id: "id", + datetime: "datetime", + total: "add_num", + reasonId: "reason_id", + reasonDetail: "reason" } } @@ -90,7 +113,17 @@ const ARTIFACT_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_ARTIFACT_LOG, apiPaths: { cn: "/ysulog/api/getArtifactLog", - os: "/ysulog/api/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" } } @@ -98,7 +131,14 @@ const MORA_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_MORA_LOG, 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" } } @@ -106,7 +146,17 @@ const WEAPON_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_WEAPON_LOG, apiPaths: { cn: "/ysulog/api/getWeaponLog", - os: "/ysulog/api/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" } } diff --git a/src/import.ts b/src/import.ts index cbc0396..8b0ae6b 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,10 +238,7 @@ 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; @@ -198,7 +274,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 +308,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); diff --git a/src/setup.ts b/src/setup.ts index bffd2b2..bc6e6c5 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -61,6 +61,15 @@ 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') + ) + .addSeparator() .addSubMenu(ui.createMenu('Data Management') .addItem('Import', 'importDataManagement') .addSeparator() @@ -100,6 +109,150 @@ var listOfSheets = [ SHEET_NAME_WEAPON_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 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 "' + 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; diff --git a/src/update.ts b/src/update.ts index 255bd3b..0baafd2 100644 --- a/src/update.ts +++ b/src/update.ts @@ -323,7 +323,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(","); @@ -438,6 +438,11 @@ function updateItemsList() { } } } + // Reload header + for (var i = 0; i < listOfSheetsLength; i++) { + addFormulaByLogName(listOfSheets[i], sheetSource); + } + loadReasonMapSheet(sheetSource); // Remove placeholder if available if (placeHolderSheet) { From ea04ffbbfe87159358a7b256c6dfca3619763e84 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 1 Jun 2023 03:08:03 +0100 Subject: [PATCH 08/12] Update v1.3, change China URL to same as Global --- package.json | 2 +- src/config.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 4bcd3a4..7740049 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "primorina", - "version": "1.22", + "version": "1.30", "description": "log primogems", "main": "index.js", "devDependencies": { diff --git a/src/config.ts b/src/config.ts index 6120798..6876a17 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.22"; +const SCRIPT_VERSION = "1.30"; const SHEET_SOURCE_ID = '1p-SkTsyzoxuKHqqvCJSUCaFBUmxd5uEEvCtb7bAqfDk'; const SHEET_SOURCE_SUPPORTED_LOCALE = "en_GB"; @@ -67,7 +67,7 @@ interface ILogSheetInfo { const PRIMOGEM_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_PRIMOGEM_LOG, apiPaths: { - cn: "/ysulog/api/getPrimogemLog", + cn: "/common/hk4e_self_help_query/User/GetPrimogemLog", os: "/common/hk4e_self_help_query/User/GetPrimogemLog", }, header: { @@ -82,7 +82,7 @@ const PRIMOGEM_SHEET_INFO: ILogSheetInfo = { const CRYSTAL_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_CRYSTAL_LOG, apiPaths: { - cn: "/ysulog/api/getCrystalLog", + cn: "/common/hk4e_self_help_query/User/GetCrystalLog", os: "/common/hk4e_self_help_query/User/GetCrystalLog", }, header: { @@ -97,7 +97,7 @@ const CRYSTAL_SHEET_INFO: ILogSheetInfo = { const RESIN_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_RESIN_LOG, apiPaths: { - cn: "/ysulog/api/getResinLog", + cn: "/common/hk4e_self_help_query/User/GetResinLog", os: "/common/hk4e_self_help_query/User/GetResinLog", }, header: { @@ -112,7 +112,7 @@ const RESIN_SHEET_INFO: ILogSheetInfo = { const ARTIFACT_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_ARTIFACT_LOG, apiPaths: { - cn: "/ysulog/api/getArtifactLog", + cn: "/common/hk4e_self_help_query/User/GetArtifactLog", os: "/common/hk4e_self_help_query/User/GetArtifactLog", }, header: { @@ -145,7 +145,7 @@ const MORA_SHEET_INFO: ILogSheetInfo = { const WEAPON_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_WEAPON_LOG, apiPaths: { - cn: "/ysulog/api/getWeaponLog", + cn: "/common/hk4e_self_help_query/User/GetWeaponLog", os: "/common/hk4e_self_help_query/User/GetWeaponLog", }, header: { From 31bb76a32242c4933b563e19305a76128de77dfa Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 1 Jun 2023 03:26:28 +0100 Subject: [PATCH 09/12] Fixed Import for Weapon logs from old document --- src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index 6876a17..2dc0e84 100644 --- a/src/config.ts +++ b/src/config.ts @@ -172,7 +172,7 @@ const userPreferences = { "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": 5} + "Weapon Log": { "Monthly Report": "B50", "Yearly Report": "B51", "Log Max Columns": 8} } // 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 = { From 7343c0e05038d0b0221c90316e666da167bf6688 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Mon, 1 Apr 2024 04:22:56 +0100 Subject: [PATCH 10/12] Added support for gs.hoyoverse.com and cs.hoyoverse.com feedback URL. Added Masterless Starglitter and Masterless Stardust extractions using Auto Import from miHoYo Added Migration steps for v1.5, where options needs to be added and pull new dashboard. --- src/config.ts | 58 ++++++++++++++++++++++++-- src/genshinApi.ts | 29 ++++++++++--- src/import.ts | 102 +++++++++++++++++++++++++++++++++++++++------ src/setup.ts | 104 ++++++++++++++++++++++++++++++++++++++++++---- src/sheets.ts | 71 +++++++++++++++++++++---------- src/update.ts | 12 ++++++ 6 files changed, 323 insertions(+), 53 deletions(-) diff --git a/src/config.ts b/src/config.ts index 2dc0e84..5892594 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.30"; +const SCRIPT_VERSION = "1.5"; const SHEET_SOURCE_ID = '1p-SkTsyzoxuKHqqvCJSUCaFBUmxd5uEEvCtb7bAqfDk'; const SHEET_SOURCE_SUPPORTED_LOCALE = "en_GB"; @@ -31,6 +31,11 @@ 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"; @@ -40,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 = [ @@ -48,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 = [ @@ -60,12 +68,14 @@ const LOG_CACHE_PREFIX = "CACHED"; // sheet info interface ILogSheetInfo { sheetName: 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: "/common/hk4e_self_help_query/User/GetPrimogemLog", os: "/common/hk4e_self_help_query/User/GetPrimogemLog", @@ -74,6 +84,7 @@ const PRIMOGEM_SHEET_INFO: ILogSheetInfo = { id: "id", datetime: "datetime", total: "add_num", + quantity: "quantity", reasonId: "reason_id", reasonDetail: "reason" } @@ -81,6 +92,7 @@ const PRIMOGEM_SHEET_INFO: ILogSheetInfo = { const CRYSTAL_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_CRYSTAL_LOG, + endpointType: "feedback", apiPaths: { cn: "/common/hk4e_self_help_query/User/GetCrystalLog", os: "/common/hk4e_self_help_query/User/GetCrystalLog", @@ -96,6 +108,7 @@ const CRYSTAL_SHEET_INFO: ILogSheetInfo = { const RESIN_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_RESIN_LOG, + endpointType: "feedback", apiPaths: { cn: "/common/hk4e_self_help_query/User/GetResinLog", os: "/common/hk4e_self_help_query/User/GetResinLog", @@ -111,6 +124,7 @@ const RESIN_SHEET_INFO: ILogSheetInfo = { const ARTIFACT_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_ARTIFACT_LOG, + endpointType: "feedback", apiPaths: { cn: "/common/hk4e_self_help_query/User/GetArtifactLog", os: "/common/hk4e_self_help_query/User/GetArtifactLog", @@ -129,6 +143,7 @@ const ARTIFACT_SHEET_INFO: ILogSheetInfo = { const MORA_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_MORA_LOG, + endpointType: "diary", apiPaths: { cn: "/event/ys_ledger/monthDetail", os: "/event/ysledgeros/month_detail" @@ -144,6 +159,7 @@ const MORA_SHEET_INFO: ILogSheetInfo = { const WEAPON_SHEET_INFO: ILogSheetInfo = { sheetName: SHEET_NAME_WEAPON_LOG, + endpointType: "feedback", apiPaths: { cn: "/common/hk4e_self_help_query/User/GetWeaponLog", os: "/common/hk4e_self_help_query/User/GetWeaponLog", @@ -160,6 +176,38 @@ const WEAPON_SHEET_INFO: ILogSheetInfo = { } } +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" + } +} + const LEDGER_FETCH_MULTI = 100; const LEDGER_RUN_TIME_LIMIT = 1000 * 60 * 4; // we'll only use 4 to leave some time for other things @@ -172,7 +220,9 @@ const userPreferences = { "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} + "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 = { diff --git a/src/genshinApi.ts b/src/genshinApi.ts index 9449109..467088d 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: "hk4e-api.mihoyo.com", + os: "hk4e-api-os.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" }, @@ -79,6 +87,9 @@ interface ImServiceLogEntry { datetime: string, add_num: string, reason: string, + quantity: number, + sub_action_name: string, + battle_path_type: string } interface ImServiceLogData { @@ -100,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 { @@ -228,7 +247,7 @@ function getReasonMap(config = getConfig()): Map { } 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 8b0ae6b..1b8d7d1 100644 --- a/src/import.ts +++ b/src/import.ts @@ -245,8 +245,19 @@ function writeLedgerLogToSheet(logSheetInfo: ILogSheetInfo) { 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(); @@ -257,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; @@ -499,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" }, @@ -506,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(); @@ -543,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"); } @@ -557,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()); @@ -578,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"); @@ -609,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 bc6e6c5..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; } @@ -68,14 +70,16 @@ function getDefaultMenu() { .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') @@ -107,6 +111,10 @@ 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 ]; @@ -175,6 +183,18 @@ 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 @@ -185,7 +205,7 @@ function addFormulaLog() { 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 "' + SHEET_NAME_WEAPON_LOG + '"'; + 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); } @@ -349,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; @@ -414,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 e3bbf68..521c0da 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,31 @@ 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().toFixed(0); + ltmidInput = settingsSheet.getRange("E32").getValue(); + guidInput = settingsSheet.getRange("E33").getValue().toFixed(0); +} + function importButtonScript() { var settingsSheet = getSettingsSheet(); var dashboardSheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME_DASHBOARD); @@ -56,23 +81,20 @@ function importButtonScript() { if (userImportSelection != importSelectionText) { if (userAutoImportSelection == importSelectionText) { userInputText += "\n\nNote\nEntering an empty URL will try to load from previously saved Settings"; - } else { - userInputText += "\n\nNote\nEntering an empty HoYoLAB ltoken will try to load from previously saved Settings"; - } - - var loadPreviousKeySetting = ""; - if (userAutoImportSelection == importSelectionText) { // Too long to display URL to user for Auto Import from miHoYo } else { - loadPreviousKeySetting = settingsSheet.getRange("D31").getValue(); - if (loadPreviousKeySetting.length > 0) { - userInputText += "\nHoYoLab ltoken: "+loadPreviousKeySetting; - userInputText += "\nHoYoLAB UID: "+settingsSheet.getRange("D33").getValue(); - } + 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(); @@ -84,9 +106,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) { @@ -96,7 +118,7 @@ function importButtonScript() { if (userAutoImportSelection == importSelectionText) { loadPreviousSetting = settingsSheet.getRange("D17").getValue(); } else { - loadPreviousSetting = settingsSheet.getRange("D31").getValue(); + loadPreviousSetting = ltokenInput; } if (loadPreviousSetting.length > 0) { var userInputText = 'The user input is empty,\nwould you like to reuse the previously stored data from settings?'; @@ -106,8 +128,10 @@ function importButtonScript() { } 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 ltoken: "+loadPreviousSetting; - userInputText += "\nHoYoLAB UID: "+settingsSheet.getRange("D33").getValue(); + 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) { @@ -115,7 +139,6 @@ function importButtonScript() { if (userAutoImportSelection == importSelectionText) { importFromAPI(); } else { - ltokenInput = settingsSheet.getRange("D31").getValue(); importFromHoYoLAB(); } } @@ -267,4 +290,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 0baafd2..d5d20af 100644 --- a/src/update.ts +++ b/src/update.ts @@ -230,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); From d29ae3027ae4255354e237882a07dd7e520faf17 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Sat, 17 Aug 2024 20:31:48 +0100 Subject: [PATCH 11/12] Fixed toFixed(0 function for empty value for v1.51 --- src/sheets.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sheets.ts b/src/sheets.ts index 521c0da..53cb177 100644 --- a/src/sheets.ts +++ b/src/sheets.ts @@ -63,9 +63,16 @@ function loadHoYoLabData(settingsSheet) { settingsSheet.getRange("E33").setValue("").setBackground("white").setNumberFormat("0"); } ltokenInput = settingsSheet.getRange("E30").getValue(); - ltuidInput = settingsSheet.getRange("E31").getValue().toFixed(0); + + ltuidInput = settingsSheet.getRange("E31").getValue(); + if(ltuidInput) { + ltuidInput.toFixed(0); + } ltmidInput = settingsSheet.getRange("E32").getValue(); - guidInput = settingsSheet.getRange("E33").getValue().toFixed(0); + guidInput = settingsSheet.getRange("E33").getValue(); + if(guidInput) { + guidInput.toFixed(0); + } } function importButtonScript() { From ce8457154b5f8e617f240dcccc94278d7fda1993 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Sat, 17 Aug 2024 20:32:45 +0100 Subject: [PATCH 12/12] Fixed URL for importing data from miHoYo, for script v1.6 --- package-lock.json | 4 ++-- package.json | 2 +- src/config.ts | 2 +- src/genshinApi.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) 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 7740049..fed6403 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "primorina", - "version": "1.30", + "version": "1.6", "description": "log primogems", "main": "index.js", "devDependencies": { diff --git a/src/config.ts b/src/config.ts index 5892594..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.5"; +const SCRIPT_VERSION = "1.6"; const SHEET_SOURCE_ID = '1p-SkTsyzoxuKHqqvCJSUCaFBUmxd5uEEvCtb7bAqfDk'; const SHEET_SOURCE_SUPPORTED_LOCALE = "en_GB"; diff --git a/src/genshinApi.ts b/src/genshinApi.ts index 467088d..f6b5b8e 100644 --- a/src/genshinApi.ts +++ b/src/genshinApi.ts @@ -8,8 +8,8 @@ type LocaleCode = const API_DOMAINS_BY_SERVER_DIVIDE = { feedback: { - cn: "hk4e-api.mihoyo.com", - os: "hk4e-api-os.hoyoverse.com", + cn: "public-operation-hk4e.mihoyo.com", + os: "public-operation-hk4e-sg.hoyoverse.com", }, diary: { cn: "hk4e-api.mihoyo.com",