提交 736a5bd8 编写于 作者: AndroidLeaves's avatar AndroidLeaves

update

上级 c5a67db1
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
// icon-color: pink; icon-glyph: feather-alt; // icon-color: pink; icon-glyph: feather-alt;
/** /**
* Author:LSP * Author:LSP
* Date:2023-01-31 * Date:2023-02-04
*/ */
// ------------------------------------------------------- // -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false // 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = false; const isDev = false;
const dependencyLSP = '20230130'; const dependencyLSP = '20230204';
console.log(`开发环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`); console.log(`开发环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`); console.log(`----------------------------------------`);
// 分支 // 分支
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// icon-color: red; icon-glyph: user-astronaut; // icon-color: red; icon-glyph: user-astronaut;
/** /**
* Author:LSP * Author:LSP
* Date:2023-02-03 * Date:2023-02-04
*/ */
// ------------------------------------------------------- // -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false // 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = false; const isDev = false;
const dependencyLSP = '20230202'; const dependencyLSP = '20230204';
console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`); console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`); console.log(`----------------------------------------`);
// 分支 // 分支
const branch = 'dev'; const branch = 'master';
// 仓库根目录 // 仓库根目录
const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`; const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`;
// 依赖包目录 // 依赖包目录
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
*/ */
// 当前环境版本号 // 当前环境版本号
const VERSION = 20230203 const VERSION = 20230204
// 组件配置文件名 // 组件配置文件名
const settingConfigName = 'settings.json'; const settingConfigName = 'settings.json';
// 分支 // 分支
...@@ -56,12 +56,15 @@ class BaseWidget { ...@@ -56,12 +56,15 @@ class BaseWidget {
let widgetSetting = this.readWidgetSetting(); let widgetSetting = this.readWidgetSetting();
let bgImg; let bgImg;
// const styles = ["", "light", "dark", "none"] // const styles = ["", "light", "dark", "none"]
const { shadowColor, shadowColorAlpha = '0', blur = false, blurMode = 'none', blurRadius = 20 } = options; const { shadow = false, shadowColor = '#000000', shadowColorAlpha = '0.5', blur = false, blurMode = 'none', blurRadius = 20 } = options;
if (bgUrlArr.length > 0) { if (bgUrlArr.length > 0) {
if (shadowColor) { if (shadow) {
bgImg = await this.getImageByUrl(bgUrlArr[0]); bgImg = await this.getImageByUrl(bgUrlArr[0]);
bgImg = await this.loadShadowColor2Image(bgImg, new Color(shadowColor, Number(shadowColorAlpha))); bgImg = await this.loadShadowColor2Image(bgImg, new Color(shadowColor, Number(shadowColorAlpha)));
} }
widgetSetting['shadow'] = `${shadow}`;
widgetSetting['shadowColor'] = shadowColor;
widgetSetting['shadowColorAlpha'] = shadowColorAlpha;
widgetSetting['blurBg'] = blur; widgetSetting['blurBg'] = blur;
widgetSetting['blurMode'] = blurMode; widgetSetting['blurMode'] = blurMode;
widgetSetting['blurRadius'] = blurRadius; widgetSetting['blurRadius'] = blurRadius;
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// icon-color: deep-purple; icon-glyph: bell; // icon-color: deep-purple; icon-glyph: bell;
/** /**
* Author:LSP * Author:LSP
* Date:2023-02-03 * Date:2023-02-04
*/ */
// ------------------------------------------------------- // -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false // 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = false; const isDev = false;
const dependencyLSP = '20230202'; const dependencyLSP = '20230204';
console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`); console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`); console.log(`----------------------------------------`);
// 分支 // 分支
const branch = 'dev'; const branch = 'master';
// 仓库根目录 // 仓库根目录
const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`; const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`;
// 依赖包目录 // 依赖包目录
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// icon-color: deep-green; icon-glyph: clock; // icon-color: deep-green; icon-glyph: clock;
/** /**
* Author:LSP * Author:LSP
* Date:2023-02-03 * Date:2023-02-04
*/ */
// ------------------------------------------------------- // -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false // 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = true; const isDev = false;
const dependencyLSP = '20230203'; const dependencyLSP = '20230204';
console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`); console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`); console.log(`----------------------------------------`);
// 分支 // 分支
const branch = 'dev'; const branch = 'master';
// 仓库根目录 // 仓库根目录
const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`; const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`;
// 依赖包目录 // 依赖包目录
...@@ -61,6 +61,7 @@ class Widget extends BaseWidget { ...@@ -61,6 +61,7 @@ class Widget extends BaseWidget {
constructor(scriptName) { constructor(scriptName) {
super(scriptName); super(scriptName);
this.backgroundColor = '#FEFCF3,#0A2647';
} }
async getAppViewOptions() { async getAppViewOptions() {
...@@ -124,7 +125,7 @@ class Widget extends BaseWidget { ...@@ -124,7 +125,7 @@ class Widget extends BaseWidget {
options: [ options: [
{ label: '常规计时', value: '1' }, { label: '常规计时', value: '1' },
{ label: '纪念日', value: '2' }, { label: '纪念日', value: '2' },
{ label: '儿童岁数', value: '3' }, { label: '出生岁数', value: '3' },
], ],
default: '1', default: '1',
}, },
...@@ -233,18 +234,20 @@ class Widget extends BaseWidget { ...@@ -233,18 +234,20 @@ class Widget extends BaseWidget {
async render({ widgetSetting }) { async render({ widgetSetting }) {
const { countdownType = '1' } = widgetSetting; const { countdownType = '1' } = widgetSetting;
if (countdownType == '2') { if (countdownType == '2') {
this.changeBgMode2OnLineBg( await this.changeBgMode2OnLineBg(
[`${remoteRoot}/img/bg-love-letter.png`] [`${remoteRoot}/img/bg-love-letter.png`]
); );
this.backgroundColor = '#E5C1C0,#0A2647';
return await this.provideMemorialWidget(widgetSetting); return await this.provideMemorialWidget(widgetSetting);
} else if (countdownType == '3') { } else if (countdownType == '3') {
this.defaultPreference.countdownFontSize = 30;
await this.changeBgMode2OnLineBg(
[`https://images.pexels.com/photos/1084425/pexels-photo-1084425.jpeg?auto=compress&cs=tinysrgb&w=1600`]
);
return await this.provideBirthdayWidget(widgetSetting);
} else { } else {
this.changeBgMode2OnLineBg( await this.changeBgMode2OnLineBg(
[`${remoteRoot}/img/ic_clock.png`] [`${remoteRoot}/img/ic_clock.png`]
); );
this.backgroundColor = '#FEFCF3,#0A2647';
return await this.provideNormalWidget(widgetSetting); return await this.provideNormalWidget(widgetSetting);
} }
} }
...@@ -265,11 +268,12 @@ class Widget extends BaseWidget { ...@@ -265,11 +268,12 @@ class Widget extends BaseWidget {
const countDownTime = new Date(`${this.countDownDate()} 00:00`).getTime(); const countDownTime = new Date(`${this.countDownDate()} 00:00`).getTime();
const timeInterval = (countDownTime - new Date().getTime()) / 86400 / 1000; const timeInterval = (countDownTime - new Date().getTime()) / 86400 / 1000;
// ---------------------------------------- // ----------------------------------------
let hStack = stack.addStack();
let textSpan = stack.addText(`${this.prefixTitle()}${this.countDownName()}${timeInterval >= 0 ? '还有' : '已过'}:`); hStack.addSpacer();
let textSpan = hStack.addText(`${this.prefixTitle()}${this.countDownName()}${timeInterval >= 0 ? '还有' : '已过'}`);
textSpan.textColor = this.dynamicColor(this.titleDayColor(), this.titleNightColor()); textSpan.textColor = this.dynamicColor(this.titleDayColor(), this.titleNightColor());
textSpan.font = Font.lightSystemFont(this.titleFontSize()); textSpan.font = Font.lightSystemFont(this.titleFontSize());
hStack.addSpacer();
// ---------------------------------------- // ----------------------------------------
stack.addSpacer(); stack.addSpacer();
let countDownStack = stack.addStack(); let countDownStack = stack.addStack();
...@@ -286,13 +290,6 @@ class Widget extends BaseWidget { ...@@ -286,13 +290,6 @@ class Widget extends BaseWidget {
// ---------------------------------------- // ----------------------------------------
stack.addSpacer(); stack.addSpacer();
let btStack = stack.addStack();
btStack.setPadding(0, 6, 10, 0);
btStack.addSpacer();
let image = await this.getImageByUrl('https://cdn-icons-png.flaticon.com/128/8849/8849632.png');
let imgSpan = btStack.addImage(image);
imgSpan.imageSize = new Size(30, 30);
imgSpan.imageOpacity = 0.6;
//================================= //=================================
return widget; return widget;
} }
...@@ -314,11 +311,12 @@ class Widget extends BaseWidget { ...@@ -314,11 +311,12 @@ class Widget extends BaseWidget {
const currShotDate = this.getDateStr(new Date(), 'MM-dd'); const currShotDate = this.getDateStr(new Date(), 'MM-dd');
const isToday = countShotDate == currShotDate; const isToday = countShotDate == currShotDate;
const countDownTime = +new Date(`${this.countDownDate()} 00:00`); const countDownTime = +new Date(`${this.countDownDate()} 00:00`);
const timeInterval = Math.ceil((+new Date() - countDownTime) / 86400 / 1000 / 365); const timeInterval = Math.floor((+new Date() - countDownTime) / 86400 / 1000 / 365);
const isOverdue = (+new Date() - +new Date(`${new Date().getFullYear()}-${countShotDate} 00:00`)) / 86400 / 1000 >= 1;
// ---------------------------------------- // ----------------------------------------
let hStack = stack.addStack(); let hStack = stack.addStack();
hStack.addSpacer(); hStack.addSpacer();
let textSpan = hStack.addText(`${this.prefixTitle()}${isToday ? '' : ''}${this.countDownName()}${timeInterval} 周年`); let textSpan = hStack.addText(`${this.prefixTitle()}${this.countDownName()}${isOverdue ? timeInterval + 1 : timeInterval}周年`);
textSpan.textColor = this.dynamicColor(this.titleDayColor(), this.titleNightColor()); textSpan.textColor = this.dynamicColor(this.titleDayColor(), this.titleNightColor());
textSpan.font = Font.mediumSystemFont(this.titleFontSize()); textSpan.font = Font.mediumSystemFont(this.titleFontSize());
hStack.addSpacer(); hStack.addSpacer();
...@@ -327,7 +325,8 @@ class Widget extends BaseWidget { ...@@ -327,7 +325,8 @@ class Widget extends BaseWidget {
hStack.addSpacer(); hStack.addSpacer();
textSpan = hStack.addText(`纪念日${isToday ? '' : '还有'}`); textSpan = hStack.addText(`纪念日${isToday ? '' : '还有'}`);
textSpan.textColor = this.dynamicColor(this.titleDayColor(), this.titleNightColor()); textSpan.textColor = this.dynamicColor(this.titleDayColor(), this.titleNightColor());
textSpan.font = Font.systemFont(this.titleFontSize()); textSpan.font = Font.systemFont(this.titleFontSize() - 2);
textSpan.textOpacity = 0.9;
hStack.addSpacer(); hStack.addSpacer();
// ---------------------------------------- // ----------------------------------------
...@@ -342,12 +341,9 @@ class Widget extends BaseWidget { ...@@ -342,12 +341,9 @@ class Widget extends BaseWidget {
imgSpan.imageOpacity = 0.9; imgSpan.imageOpacity = 0.9;
} else { } else {
// 倒计 // 倒计
console.log(`isToday->${isToday}===>${new Date().getFullYear()}-${this.countDownDate().slice(5)}`); let realCountDownTime = +new Date(`${new Date().getFullYear()}-${countShotDate} 00:00`);
let realCountDownTime = +new Date(`${new Date().getFullYear()}-${this.countDownDate().slice(5)} 00:00`);
const isOverdue = (+new Date() - +new Date(`${new Date().getFullYear()}-${this.countDownDate().slice(5)} 00:00`)) / 86400 / 1000 >= 1;
if (isOverdue) { if (isOverdue) {
realCountDownTime = +new Date(`${new Date().getFullYear() + 1}-${this.countDownDate().slice(5)} 00:00`); realCountDownTime = +new Date(`${new Date().getFullYear() + 1}-${countShotDate} 00:00`);
console.log(`下一次===>${new Date().getFullYear() + 1}-${this.countDownDate().slice(5)}`);
} }
let dateSpan = countDownStack.addDate(new Date(realCountDownTime)); let dateSpan = countDownStack.addDate(new Date(realCountDownTime));
dateSpan.centerAlignText(); dateSpan.centerAlignText();
...@@ -363,6 +359,82 @@ class Widget extends BaseWidget { ...@@ -363,6 +359,82 @@ class Widget extends BaseWidget {
//================================= //=================================
return widget; return widget;
} }
async provideBirthdayWidget(widgetSetting) {
// ----------------------------------------
const widgetSize = this.getWidgetSize('小号');
//=================================
const widget = new ListWidget();
widget.setPadding(0, 0, 0, 0);
//=================================
let stack = widget.addStack();
stack.size = new Size(widgetSize.width, widgetSize.height);
stack.layoutVertically();
// ----------------------------------------
const countShotDate = this.countDownDate().slice(5);
const currShotDate = this.getDateStr(new Date(), 'MM-dd');
const isToday = countShotDate == currShotDate;
const countDownTime = +new Date(`${this.countDownDate()} 00:00`);
const timeInterval = Math.floor((+new Date() - countDownTime) / 86400 / 1000 / 365);
// ----------------------------------------
// ----------------------------------------
let topStack = stack.addStack();
topStack.size = new Size(widgetSize.width, widgetSize.height * 0.75);
topStack.layoutVertically();
topStack.addSpacer();
//
let hStack = topStack.addStack();
hStack.setPadding(0, 0, 2, 10);
hStack.addSpacer();
let textSpan = hStack.addText(`${this.prefixTitle()}${this.countDownName()}`);
textSpan.textColor = this.dynamicColor(this.titleDayColor(), this.titleNightColor());
textSpan.font = Font.semiboldRoundedSystemFont(this.titleFontSize());
// ----------------------------------------
let bottomStack = stack.addStack();
bottomStack.centerAlignContent();
bottomStack.size = new Size(widgetSize.width, widgetSize.height * 0.3);
bottomStack.backgroundColor = this.dynamicColor('#FEFCF3', '#0A2647');
bottomStack.setPadding(0, 12, 0, 0);
//
textSpan = bottomStack.addText(`${timeInterval}`);
textSpan.textColor = this.dynamicColor(this.countdownDayColor(), this.countdownNightColor());
textSpan.font = Font.semiboldRoundedSystemFont(this.countdownFontSize());
//
bottomStack.addSpacer(4);
let vStack = bottomStack.addStack();
vStack.layoutVertically();
textSpan = vStack.addText(`岁${isToday ? '啦,生日快乐!🎂' : ''}`);
textSpan.textColor = this.dynamicColor(this.countdownDayColor(), this.countdownNightColor());
textSpan.font = Font.systemFont(Math.max(10, this.countdownFontSize() - 20));
//
if (!isToday) {
hStack = vStack.addStack();
textSpan = hStack.addText(`零`);
textSpan.textColor = this.dynamicColor(this.countdownDayColor(), this.countdownNightColor());
textSpan.font = Font.systemFont(Math.max(10, this.countdownFontSize() - 20));
//
let realCountDownTime = +new Date(`${new Date().getFullYear() - 1}-${countShotDate} 00:00`);
let dateSpan = hStack.addDate(new Date(realCountDownTime));
dateSpan.leftAlignText();
dateSpan.lineLimit = 2;
dateSpan.applyRelativeStyle();
dateSpan.font = Font.lightSystemFont(Math.max(10, this.countdownFontSize() - 20));
dateSpan.textColor = this.dynamicColor(this.countdownDayColor(), this.countdownNightColor());
}
//
if (isToday) {
bottomStack.addSpacer(4);
} else {
bottomStack.addSpacer();
}
// ----------------------------------------
stack.addSpacer();
//=================================
return widget;
}
// --------------------------NET START-------------------------- // --------------------------NET START--------------------------
// --------------------------NET END-------------------------- // --------------------------NET END--------------------------
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// icon-color: red; icon-glyph: user-astronaut; // icon-color: red; icon-glyph: user-astronaut;
/** /**
* Author:LSP * Author:LSP
* Date:2023-02-02 * Date:2023-02-04
*/ */
// ------------------------------------------------------- // -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false // 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = false; const isDev = false;
const dependencyLSP = '20230202'; const dependencyLSP = '20230204';
console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`); console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`); console.log(`----------------------------------------`);
// 分支 // 分支
const branch = 'dev'; const branch = 'master';
// 仓库根目录 // 仓库根目录
const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`; const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`;
// 依赖包目录 // 依赖包目录
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// icon-color: red; icon-glyph: user-astronaut; // icon-color: red; icon-glyph: user-astronaut;
/** /**
* Author:LSP * Author:LSP
* Date:2023-02-02 * Date:2023-02-04
*/ */
// ------------------------------------------------------- // -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false // 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = false; const isDev = false;
const dependencyLSP = '20230202'; const dependencyLSP = '20230204';
console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`); console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`); console.log(`----------------------------------------`);
// 分支 // 分支
const branch = 'dev'; const branch = 'master';
// 仓库根目录 // 仓库根目录
const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`; const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`;
// 依赖包目录 // 依赖包目录
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// icon-color: blue; icon-glyph: mobile-alt; // icon-color: blue; icon-glyph: mobile-alt;
/** /**
* Author:LSP * Author:LSP
* Date:2023-01-13 * Date:2023-02-04
*/ */
// ------------------------------------------------------- // -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false // 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = true; const isDev = false;
const dependencyLSP = '20230130'; const dependencyLSP = '20230204';
console.log(`开发环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`); console.log(`开发环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`); console.log(`----------------------------------------`);
// 分支 // 分支
const branch = 'dev'; const branch = 'master';
// 仓库根目录 // 仓库根目录
const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`; const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`;
// 依赖包目录 // 依赖包目录
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// icon-color: deep-blue; icon-glyph: film; // icon-color: deep-blue; icon-glyph: film;
/** /**
* Author:LSP * Author:LSP
* Date:2023-02-03 * Date:2023-02-04
*/ */
// ------------------------------------------------------- // -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false // 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = false; const isDev = false;
const dependencyLSP = '20230202'; const dependencyLSP = '20230204';
console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`); console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`); console.log(`----------------------------------------`);
// 分支 // 分支
const branch = 'dev'; const branch = 'master';
// 仓库根目录 // 仓库根目录
const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`; const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`;
// 依赖包目录 // 依赖包目录
......
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: green; icon-glyph: mobile-alt;
/**
* Author:LSP
* Date:2023-01-10
*/
// -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = false;
console.log(`开发环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`);
const remoteRoot = 'https://gitcode.net/enoyee/scriptable/-/raw/master/';
// 依赖包目录
const fm = FileManager.local();
const rootDir = fm.documentsDirectory();
const cacheDir = fm.joinPath(rootDir, 'LSP');
const dependencyFileName = isDev ? "_LSP.js" : `${cacheDir}/_LSP.js`;
// 下载依赖包
await downloadLSPDependency();
// -------------------------------------------------------
if (typeof require === 'undefined') require = importModule
// 引入相关方法
const { BaseWidget } = require(dependencyFileName);
// @定义小组件
class Widget extends BaseWidget {
preference = {
fetchUrl: {
printLog: 'https://app.10086.cn/biz-orange/SA/clickCount/printLog',
packageDetail: 'https://app.10086.cn/biz-orange/BWX/newComboMealResouceUnite/getNewComboMealResource',
realFee: 'https://app.10086.cn/biz-orange/BWX/realFeeQuery/getRealFee',
},
header: {
'Host': 'app.10086.cn',
'content-type': 'application/json',
'Referer': 'https://servicewechat.com/wxfcd156333d74ee79/164/page-frame.html',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.31(0x18001f34) NetType/WIFI Language/zh_CN',
},
body: {
"cid": "0",
"clientID": "0",
"sn": "0",
"cv": "0",
"st": "0",
"sv": "0",
"sp": "0",
"xk": "0",
"ak": "0",
"xc": "WX001",
},
};
fee = {
title: '📱 话费剩余:',
balance: 0,
unit: '',
};
voice = {
title: '⏳ 语音剩余:',
balance: 0,
unit: '分钟',
};
flow = {
title: '⛽️ 流量剩余:',
balance: 0,
unit: 'MB',
};
constructor(scriptName) {
super(scriptName);
this.defaultConfig.bgType = '2';
this.backgroundColor = '#FEFCF3,#0A2647';
// =============================================
this.openid = 'omXXs0CBQHTDI-_szhKwgAWKvVH8';
// =============================================
const widgetSetting = this.readWidgetSetting();
this.cellNum = widgetSetting.cellNum;
this.cookie = widgetSetting.cookie;
// =============================================
}
async getAppViewOptions() {
return {
widgetProvider: {
small: true, // 是否提供小号组件
medium: false, // 是否提供中号组件
large: true, // 是否提供大号组件
},
// 预览界面的组件设置item
settingItems: [
{
name: 'chinaMobileLogin',
label: '信息输入',
type: 'cell',
icon: 'https://gitcode.net/enoyee/scriptable/-/raw/master/img/icon_mobile.png',
needLoading: true,
desc: this.readWidgetSetting().cookie?.length > 0 ? '已填写' : '未填写'
},
],
// cell类型的item点击回调
onItemClick: async (item) => {
let widgetSetting = this.readWidgetSetting();
let insertDesc;
switch (item.name) {
case 'chinaMobileLogin':
// const webView = new WebView();
// await webView.loadURL('https://wx.10086.cn/website/spa/main/newHome');
// await webView.present();
await this.generateInputAlert({
title: '登录信息填写',
message: '填入中国移动小程序抓取的cookie',
options: [
{ hint: '请输入手机号', value: widgetSetting?.cellNum ?? '' },
{ hint: '请输入cookie', value: widgetSetting?.cookie ?? '' },
]
}, async (inputArr) => {
const cellNum = inputArr[0].value;
const cookie = inputArr[1].value;
// 保存配置
widgetSetting['cellNum'] = cellNum;
widgetSetting['cookie'] = cookie;
this.cellNum = widgetSetting.cellNum;
this.cookie = widgetSetting.cookie;
this.writeWidgetSetting({ ...widgetSetting });
insertDesc = cookie?.length > 0 ? '已填写' : '未填写';
});
break;
}
// 写入更新配置
this.writeWidgetSetting(widgetSetting);
return {
desc: { value: insertDesc },
};
},
};
}
async render({ widgetSetting, _ }) {
return await this.provideSmallWidget(widgetSetting);
}
async provideSmallWidget(widgetSetting) {
// ========================================
await this.printLog();
// 套餐明细
await this.loadDetailInfo();
// ========================================
const widget = new ListWidget();
widget.setPadding(10, 10, 10, 0);
// ========================================
const widgetSize = this.getWidgetSize('小号');
let stack = widget.addStack();
let image = await this.getImageByUrl('https://gitcode.net/enoyee/scriptable/-/raw/master/img/bg_doraemon_1.png');
stack.setPadding(4, 12, 0, 12);
stack.backgroundImage = image;
stack.size = new Size(widgetSize.width, widgetSize.height);
stack.layoutVertically();
stack.addSpacer();
// ========================================
const titleFont = Font.lightSystemFont(13);
const infoFont = Font.mediumSystemFont(16);
const textColor = Color.dynamic(new Color('#000000'), new Color('#FFFFFF'));
const descSpacer = 3;
const lineSpacer = 4;
const descLeftSpacer = 22;
// ========================================
let textSpan = widget.addText(`${response.slice(10)}`);
textSpan.textColor = textColor
textSpan.font = titleFont;
//
stack.addSpacer(descSpacer);
let displayStack = stack.addStack();
displayStack.centerAlignContent();
displayStack.addSpacer(descLeftSpacer);
textSpan = displayStack.addText(`${this.requestSuccess ? `${this.fee.balance}${this.fee.unit}` : 'NAN'}`);
textSpan.textColor = textColor
textSpan.font = infoFont
displayStack.addSpacer();
// ========================================
stack.addSpacer(lineSpacer);
textSpan = stack.addText(`${this.voice.title}`);
textSpan.textColor = textColor
textSpan.font = titleFont;
//
stack.addSpacer(descSpacer);
displayStack = stack.addStack();
displayStack.centerAlignContent();
displayStack.addSpacer(descLeftSpacer);
textSpan = displayStack.addText(`${this.requestSuccess ? `${this.voice.balance}${this.voice.unit}` : 'NAN'}`);
textSpan.textColor = textColor
textSpan.font = infoFont
displayStack.addSpacer();
// ========================================
stack.addSpacer(lineSpacer);
textSpan = stack.addText(`${this.flow.title}`);
textSpan.textColor = textColor
textSpan.font = titleFont;
//
stack.addSpacer(descSpacer);
displayStack = stack.addStack();
displayStack.centerAlignContent();
displayStack.addSpacer(descLeftSpacer);
textSpan = displayStack.addText(`${this.requestSuccess ? `${this.flow.balance}${this.flow.unit}` : 'NAN'}`);
textSpan.textColor = textColor
textSpan.font = infoFont
displayStack.addSpacer();
// ========================================
// ========================================
stack.addSpacer(6);
let btStack = stack.addStack();
btStack.centerAlignContent();
btStack.addSpacer(6);
image = this.getSFSymbol('goforward');
let imgSpan = btStack.addImage(image);
imgSpan.imageSize = new Size(9, 9);
imgSpan.tintColor = textColor
btStack.addSpacer(3);
textSpan = btStack.addText(`${this.getDateStr(new Date(), 'HH:mm')}`);
textSpan.textColor = textColor
textSpan.font = Font.lightSystemFont(10);
btStack.addSpacer();
image = await this.getImageByUrl('https://gitcode.net/enoyee/scriptable/-/raw/master/img/ic__china_mobile.png');
imgSpan = btStack.addImage(image);
imgSpan.imageSize = new Size(14, 14);
stack.addSpacer();
//=================================
return widget;
}
// --------------------------NET START--------------------------
/**
* log
*/
printLog = async () => {
// 自动登录
let req = new Request(this.preference.fetchUrl.printLog);
req.method = 'POST';
req.headers = {
...this.preference.header,
'xs': '929c0b0a9586fec77d1b0bf4823fa01a',
};
req.body = JSON.stringify(
{
...this.preference.body,
"reqBody": {
"cellNum": this.cellNum,
"provinceCode": "200",
"cityCode": "0759",
"adverType": "122",
"adverLocation": "",
"markId": "2"
}
}
);
this.logDivider();
console.log(`🚀 Start Request printLog...`);
const LogREs = await req.loadString();
console.log(LogREs);
console.log(`🚀 End Request printLog...`);
this.logDivider();
}
/**
* 加载明细
* @returns
*/
loadDetailInfo = async () => {
// 套餐信息
let req = new Request(this.preference.fetchUrl.packageDetail);
req.method = 'POST';
req.headers = {
...this.preference.header,
'xs': '01d8cf2c1725bcc876ed1ea4dc321269',
'Cookie': this.cookie,
};
req.body = JSON.stringify(
{
...this.preference.body,
"reqBody": {
"openid": this.openid,
"cellNum": this.cellNum,
"tag": "3"
}
}
);
console.log(`🚀 Start Request detailInfo...`);
const flowRes = await req.loadString();
try {
const FlowRes = JSON.parse(flowRes);
if (FlowRes.retCode == '000000') {
this.requestSuccess = true;
const { resourcesTotal = [] } = FlowRes.rspBody?.qryInfoRsp?.[0];
if (resourcesTotal.length >= 2) {
// 流量
const FlowRes = resourcesTotal[0];
this.flow.balance = FlowRes.allRemainRes;
const remUnit = FlowRes.remUnit;
if (remUnit == '03') {
this.flow.unit = 'KB';
} else if (remUnit == '04') {
this.flow.unit = 'MB';
} else {
this.flow.unit = 'GB';
}
// 语音
const VoiceRes = resourcesTotal[1];
this.voice.balance = VoiceRes.allRemainRes;
}
// 话费余额
req = new Request(this.preference.fetchUrl.realFee);
req.method = 'POST';
req.headers = {
...this.preference.header,
'xs': '0c9477b7647bfb0efa98745e37a9808f',
'Cookie': this.cookie,
};
req.body = JSON.stringify(
{
...this.preference.body,
"reqBody": {
"cellNum": this.cellNum,
"openid": this.openid
}
}
);
const realFeeRes = await req.loadString();
try {
const RealFeeRes = JSON.parse(realFeeRes);
const { retCode, rspBody } = RealFeeRes;
if (retCode == '000000') {
this.fee.balance = rspBody?.realBalanceFee;
}
} catch (error) {
console.error(`余额返回:${realFeeRes}`);
}
} else {
console.log(`失效: ${flowRes}`);
}
} catch (error) {
console.error(`套餐返回:${flowRes}`);
}
console.log(`🚀 End Request detailInfo...`);
this.logDivider();
}
// --------------------------NET END--------------------------
}
await new Widget(Script.name()).run();
// =================================================================================
// =================================================================================
async function downloadLSPDependency() {
let fm = FileManager.local();
const dependencyURL = `${remoteRoot}_LSP.js`;
if (isDev) {
const iCloudPath = FileManager.iCloud().documentsDirectory();
const localIcloudDependencyExit = fm.isFileStoredIniCloud(`${iCloudPath}/_LSP.js`);
const localDependencyExit = fm.fileExists(`${rootDir}/_LSP.js`);
const fileExist = localIcloudDependencyExit || localDependencyExit;
console.log(`🚀 DEV开发依赖文件${fileExist ? '已存在 ✅' : '不存在 🚫'}`);
if (!fileExist) {
console.log(`🤖 DEV 开始下载依赖~`);
await downloadFile2Scriptable('_LSP', dependencyURL);
}
return
}
//////////////////////////////////////////////////////////
console.log(`----------------------------------------`);
const remoteDependencyExit = fm.fileExists(`${cacheDir}/_LSP.js`);
console.log(`🚀 RELEASE依赖文件${remoteDependencyExit ? '已存在 ✅' : '不存在 🚫'}`);
console.log(`----------------------------------------`);
// ------------------------------
if (!remoteDependencyExit) { // 下载依赖
// 创建根目录
if (!fm.fileExists(cacheDir)) {
fm.createDirectory(cacheDir, true);
}
// 下载
console.log('🤖 RELEASE开始下载依赖~');
console.log(`----------------------------------------`);
const req = new Request(dependencyURL);
const moduleJs = await req.load();
if (moduleJs) {
fm.write(fm.joinPath(cacheDir, '/_LSP.js'), moduleJs);
console.log('✅ LSP远程依赖环境下载成功!');
console.log(`----------------------------------------`);
} else {
console.error('🚫 获取依赖环境脚本失败,请重试!');
console.log(`----------------------------------------`);
}
}
}
/**
* 获取保存的文件名
* @param {*} fileName
* @returns
*/
function getSaveFileName(fileName) {
const hasSuffix = fileName.lastIndexOf(".") + 1;
return !hasSuffix ? `${fileName}.js` : fileName;
};
/**
* 保存文件到Scriptable软件目录,app可看到
* @param {*} fileName
* @param {*} content
* @returns
*/
function saveFile2Scriptable(fileName, content) {
try {
const fm = FileManager.iCloud();
let fileSimpleName = getSaveFileName(fileName);
const filePath = fm.joinPath(fm.documentsDirectory(), fileSimpleName);
fm.writeString(filePath, content);
return true;
} catch (error) {
return false;
}
};
/**
* 下载js文件到Scriptable软件目录
* @param {*} moduleName 名称
* @param {*} url 在线地址
* @returns
*/
async function downloadFile2Scriptable(moduleName, url) {
const req = new Request(url);
const content = await req.loadString();
return saveFile2Scriptable(`${moduleName}`, content);
};
// =================================================================================
// =================================================================================
\ No newline at end of file
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// icon-color: red; icon-glyph: mobile-alt; // icon-color: red; icon-glyph: mobile-alt;
/** /**
* Author:LSP * Author:LSP
* Date:2023-01-31 * Date:2023-02-04
*/ */
// ------------------------------------------------------- // -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false // 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = true; const isDev = false;
const dependencyLSP = '20230130'; const dependencyLSP = '20230204';
console.log(`开发环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`); console.log(`开发环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`); console.log(`----------------------------------------`);
// 分支 // 分支
const branch = 'dev'; const branch = 'master';
// 仓库根目录 // 仓库根目录
const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`; const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`;
// 依赖包目录 // 依赖包目录
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// icon-color: green; icon-glyph: frog; // icon-color: green; icon-glyph: frog;
/** /**
* Author:LSP * Author:LSP
* Date:2023-02-03 * Date:2023-02-04
*/ */
// ------------------------------------------------------- // -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false // 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = false; const isDev = false;
const dependencyLSP = '20230202'; const dependencyLSP = '20230204';
console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`); console.log(`当前环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`); console.log(`----------------------------------------`);
// 分支 // 分支
const branch = 'dev'; const branch = 'master';
// 仓库根目录 // 仓库根目录
const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`; const remoteRoot = `https://gitcode.net/enoyee/scriptable/-/raw/${branch}`;
// 依赖包目录 // 依赖包目录
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册