From 153dc25d38af81e48b12c09f5be7d15b58116016 Mon Sep 17 00:00:00 2001 From: rainerosion <1782832653@qq.com> Date: Mon, 7 Mar 2022 19:26:28 +0800 Subject: [PATCH 1/3] Add the function of updating badge times. --- skyBadge.js | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/skyBadge.js b/skyBadge.js index b29f945..90164f3 100644 --- a/skyBadge.js +++ b/skyBadge.js @@ -86,7 +86,7 @@ function startSky() { break; case "delete": let len = Object.keys(menu_map).length - if (len > 3) { + if (len > 4) { delete_options = []; storage_map = {}; Object.keys(menu_map).map(function (key, index) { @@ -94,7 +94,7 @@ function startSky() { if (!isOptions(key, menu_map)) { delete_options.push(key); } - if(!isSwitchOptions(key, menu_map)){ + if (!isSwitchOptions(key, menu_map)) { storage_map[key] = menu_map[key] } }); @@ -115,6 +115,9 @@ function startSky() { selectAppChannelPackageName(); startSky(); break; + case "update": + // 更新徽章次数 + break; default: // 启动app console.log(value); @@ -134,7 +137,12 @@ function startSky() { * @returns {boolean} */ function isOptions(key, menu) { - if (menu[key] == "add" || menu[key] == "delete" || menu[key] == "clear" || menu[key] == "channel") { + if (menu[key] == "add" + || menu[key] == "delete" + || menu[key] == "clear" + || menu[key] == "channel" + || menu[key] == "update" + ) { return true; } return false; @@ -147,7 +155,7 @@ function isOptions(key, menu) { * @param menu * @returns {boolean} */ - function isSwitchOptions(key, menu) { +function isSwitchOptions(key, menu) { if (menu[key] == "channel") { return true; } @@ -179,7 +187,7 @@ function selectAppChannelPackageName() { "[C] 小米": "com.netease.sky.mi", "[C] VIVO": "com.netease.sky.vivo", "[C] 应用宝": "com.tencent.tmgp.eyou.eygy", - "[C] 华为" : "com.netease.sky.huawei", + "[C] 华为": "com.netease.sky.huawei", "[I] 国际服": "com.tgc.sky.android", }; let channel_options = Object.keys(package_map).map(function (data) { @@ -205,7 +213,8 @@ function getMenu() { return { "[O] 录入徽章": "add", "[O] 清空徽章": "clear", - "[O] 删除徽章": "delete" + "[O] 删除徽章": "delete", + "[O] 更新次数": "update" }; } @@ -250,4 +259,33 @@ function currentChannel() { storage.put("channel", channel_map); } return storage.get("channel"); +} + +/** + * 16进制转10进制 + * @param {*} num 16进制 + * @returns + */ +function hex2dec(num) { + return parseInt(num, 16); +} + +/** + * 10进制转16进制 + * + * @param {*} dec 10进制 + * @param {*} len 长度 + * @returns + */ +function dec2hex(dec, len) { + var hex = ""; + while (dec) { + var last = dec & 15; + hex = String.fromCharCode(((last > 9) ? 55 : 48) + last) + hex; + dec >>= 4; + } + if (len) { + while (hex.length < len) hex = '0' + hex; + } + return '0x' + hex; } \ No newline at end of file -- 2.45.2 From 6f1fe978b49714778df87e95b6ffba89289b62ef Mon Sep 17 00:00:00 2001 From: rainerosion <1782832653@qq.com> Date: Mon, 7 Mar 2022 20:21:34 +0800 Subject: [PATCH 2/3] Complete the badge times update function. --- skyBadge.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/skyBadge.js b/skyBadge.js index 90164f3..d36029b 100644 --- a/skyBadge.js +++ b/skyBadge.js @@ -1,6 +1,7 @@ "auto" +console.show(); // 徽章数据 -var storage = storages.create("com.netease.sky:badge"); +var storage = storages.create("com.netease.sky:badge1"); // storage.clear(); var global_option = getMenu(); if (!storage.contains("menu")) { @@ -49,6 +50,8 @@ function startSky() { console.log(options[i]); let value = menu_map[options[i]]; if (value.length > 0) { + // 计算菜单长度 + let len = Object.keys(menu_map).length; switch (value) { case "add": toast("添加徽章"); @@ -85,8 +88,8 @@ function startSky() { startSky(); break; case "delete": - let len = Object.keys(menu_map).length - if (len > 4) { + // let len = Object.keys(menu_map).length; + if (len - 1 > Object.keys(getMenu()).length) { delete_options = []; storage_map = {}; Object.keys(menu_map).map(function (key, index) { @@ -117,6 +120,52 @@ function startSky() { break; case "update": // 更新徽章次数 + // let len = Object.keys(menu_map).length; + console.log("len => " + len + " menuLen => " + Object.keys(getMenu()).length); + if (len - 1 > Object.keys(getMenu()).length) { + update_options = []; + storage_map = {}; + Object.keys(menu_map).map(function (key, index) { + console.log("key => " + key, "index => " + index); + if (!isOptions(key, menu_map)) { + update_options.push(key); + } + if (!isSwitchOptions(key, menu_map)) { + storage_map[key] = menu_map[key] + } + }); + let update_index = dialogs.select("请选择需要更新的徽章", update_options); + console.log("update => " + update_options[update_index]); + // 获取数据 + let uri = storage_map[update_options[update_index]]; + // 截取前缀 + let prefix = uri.substring(0, uri.length - 6); + // 计数器 + let counter = uri.substring(uri.length - 6); + console.log("prefix => " + prefix + ",counter => " + counter + ",counterDec => " + hex2dec(counter)); + // 保存数据 + let num = rawInput("请在输入框输入新的次数,当前:" + hex2dec(counter) + "次").trim(); + rules = /^[0-9]+$/; + if (rules.test(num)) { + if (num < hex2dec(counter)) { + toast("将要更新的次数[" + num + "]小于当前次数[" + hex2dec(counter) + "]可能会无法使用,请悉知!!!"); + } + // 转换为16进制 + let counter_hex = dec2hex(num, 6) + console.log("num => " + num + ",hex => " + counter_hex + "newData => " + (prefix + counter_hex)); + // 更新数据 + storage_map[update_options[update_index]] = prefix + counter_hex; + storage.put("menu", storage_map); + } else { + toast("徽章次数只能输入整数。"); + return; + } + startSky(); + } else { + toast("你没有录入任何徽章信息"); + // 再次打开菜单 + startSky(); + } break; default: // 启动app @@ -263,11 +312,11 @@ function currentChannel() { /** * 16进制转10进制 - * @param {*} num 16进制 + * @param {*} hex 16进制 * @returns */ -function hex2dec(num) { - return parseInt(num, 16); +function hex2dec(hex) { + return parseInt(hex, 16); } /** @@ -287,5 +336,5 @@ function dec2hex(dec, len) { if (len) { while (hex.length < len) hex = '0' + hex; } - return '0x' + hex; + return hex; } \ No newline at end of file -- 2.45.2 From 4ae73cd37f6c60ac282911bb4ba72587c50e196a Mon Sep 17 00:00:00 2001 From: rainerosion <1782832653@qq.com> Date: Mon, 7 Mar 2022 20:23:06 +0800 Subject: [PATCH 3/3] Remove debug code. --- skyBadge.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/skyBadge.js b/skyBadge.js index d36029b..fa6e333 100644 --- a/skyBadge.js +++ b/skyBadge.js @@ -1,5 +1,4 @@ "auto" -console.show(); // 徽章数据 var storage = storages.create("com.netease.sky:badge1"); // storage.clear(); @@ -135,14 +134,14 @@ function startSky() { } }); let update_index = dialogs.select("请选择需要更新的徽章", update_options); - console.log("update => " + update_options[update_index]); + // console.log("update => " + update_options[update_index]); // 获取数据 let uri = storage_map[update_options[update_index]]; // 截取前缀 let prefix = uri.substring(0, uri.length - 6); // 计数器 let counter = uri.substring(uri.length - 6); - console.log("prefix => " + prefix + ",counter => " + counter + ",counterDec => " + hex2dec(counter)); + // console.log("prefix => " + prefix + ",counter => " + counter + ",counterDec => " + hex2dec(counter)); // 保存数据 let num = rawInput("请在输入框输入新的次数,当前:" + hex2dec(counter) + "次").trim(); rules = /^[0-9]+$/; @@ -152,7 +151,7 @@ function startSky() { } // 转换为16进制 let counter_hex = dec2hex(num, 6) - console.log("num => " + num + ",hex => " + counter_hex + "newData => " + (prefix + counter_hex)); + // console.log("num => " + num + ",hex => " + counter_hex + "newData => " + (prefix + counter_hex)); // 更新数据 storage_map[update_options[update_index]] = prefix + counter_hex; storage.put("menu", storage_map); -- 2.45.2