提交 26799c50 编写于 作者: AndroidLeaves's avatar AndroidLeaves

up

上级 52556e6d
......@@ -27,7 +27,7 @@ const { BaseWidget } = require(dependencyFileName);
class Widget extends BaseWidget {
defaultPreference = {
version: 20221213,
version: 20221213_2,
domain: 'https://tophub.today',
hotban: [{ title: '微博 · 热搜榜', link: 'https://tophub.today/n/KqndgxeLl9' }],
weiboOpenOptions: [
......@@ -59,27 +59,35 @@ class Widget extends BaseWidget {
largeItemCount: 13
};
getCookie() {
async getCookie() {
let cookie = '';
const { hotbanCK } = this.readWidgetSetting();
console.log(`???${hotbanCK}`);
if (hotbanCK) {
let index = hotbanCK.lastIndexOf(";");
let subStr = hotbanCK.slice(0, index);
let stamp1 = hotbanCK.slice(index, hotbanCK.length);
index = stamp1.lastIndexOf("=");
stamp1 = stamp1.slice(0, index);
stamp1 = stamp1 + `=${Math.round(new Date() / 1000)}`
index = subStr.lastIndexOf(";");
let preStr = subStr.slice(0, index);
let stamp2 = subStr.slice(index, subStr.length);
index = stamp2.lastIndexOf("=");
stamp2 = stamp2.slice(0, index);
stamp2 = stamp2 + `=${Math.round(new Date() / 1000) - 86400 * Math.ceil(Math.random() * 10)},${Math.round(new Date() / 1000) - 86400 * Math.ceil(Math.random() * 6)},${Math.round(new Date() / 1000) - 86400 * Math.ceil(Math.random() * 3)},${Math.round(new Date() / 1000)}`
cookie = (preStr + stamp2 + stamp1).replace('\n', '');
const hotbanCKArr = hotbanCK.split(";");
if (hotbanCKArr.length !== 3) {
await this.generateAlert('TopHub添加cookie', `添加的cookie不符合要求,需要登录后的cookie`, ['确定']);
} else {
let itc_center_user;
let Hm_lvt;
let Hm_lpvt;
//
hotbanCKArr.forEach(element => {
if (element.startsWith('Hm_lvt')) {
let index = element.lastIndexOf("=");
Hm_lvt = element.slice(0, index)
Hm_lvt += `=${Math.round(new Date() / 1000)}`
} else if (element.startsWith('Hm_lpvt')) {
let index = element.lastIndexOf("=");
Hm_lpvt = element.slice(0, index)
Hm_lpvt += `=${Math.round(new Date() / 1000) - 86400 * Math.ceil(Math.random() * 6)},${Math.round(new Date() / 1000) - 86400 * Math.ceil(Math.random() * 3)}`
} else {
itc_center_user = element;
}
});
//
}
cookie = (itc_center_user + Hm_lvt + Hm_lpvt).replace('\n', '');
console.log(`cookie=>${cookie}`);
}
return cookie;
......@@ -627,8 +635,10 @@ class Widget extends BaseWidget {
async provideWidget(itemCount, small = false) {
const defaultHotArr = this.defaultPreference.hotban;
const cacheHotStr = this.useFileManager().readStringCache('hotban');
const hotbanArr = cacheHotStr ? JSON.parse(cacheHotStr) : defaultHotArr;
let hotbanArr = cacheHotStr ? JSON.parse(cacheHotStr) : defaultHotArr;
hotbanArr = hotbanArr.length === 0 ? defaultHotArr : hotbanArr;
const index = this.carouselIndex(`HotbanRandom${this.defaultPreference.version}`, hotbanArr.length);
console.log(`????>>>index=${index}, hotbanArr=${JSON.stringify(hotbanArr)}`);
const response = await this.loadHotBanRES(hotbanArr[index].link);
// 数据
const { hotTitle = '', logoUrl = '', linkArr = [], titleArr = [] } = response;
......
......@@ -1055,6 +1055,9 @@ class BaseWidget {
}
carouselIndex = (cacheKey, size) => {
if (size <= 0) {
return 0;
}
let index = -1;
if (Keychain.contains(cacheKey)) {
let cacheString = this.keyGet(cacheKey);
......
......@@ -131,7 +131,7 @@ class Widget extends BaseWidget {
textSpan.lineLimit = 1;
// ------------
leftStack.addSpacer(4);
textSpan = leftStack.addText(`完成率:${Math.floor((finishedCount / totalCount) * 100)}%`);
textSpan = leftStack.addText(`完成率:${totalCount > 0 ? Math.floor((finishedCount / totalCount) * 100) : 0}%`);
textSpan.textColor = leftTextColor;
textSpan.font = leftTextFont;
textSpan.lineLimit = 1;
......@@ -171,11 +171,11 @@ class Widget extends BaseWidget {
}
rdStack.backgroundColor = new Color(`${rd.color}`, alpha);
rdStack.cornerRadius = 4;
textSpan = rdStack.addText(`@ ${rd.title}`)
textSpan = rdStack.addText(`@${rd.title}`)
textSpan.textColor = new Color(`${rd.color}`, 0.8);
let fontSize = 13;
if (rd.title.length >= 14) {
fontSize = 11;
if (rd.title.length >= 13) {
fontSize = 12;
}
textSpan.font = Font.semiboldSystemFont(fontSize);
textSpan.lineLimit = 1;
......@@ -200,7 +200,12 @@ class Widget extends BaseWidget {
// calendar.color.hex
const calendar = await Calendar.forReminders();
const originalRdList = await Reminder.all(calendar);
const filterList = originalRdList.filter(item => (item.dueDate ? this.getDateStr(item.dueDate, 'yyyy-MM-dd') : '') == this.getDateStr(new Date(), 'yyyy-MM-dd'));
const filterList = originalRdList.filter(item => {
const { isCompleted, dueDate } = item;
const date = item.dueDate ? this.getDateStr(item.dueDate, 'yyyy-MM-dd') : '';
const currDate = this.getDateStr(new Date(), 'yyyy-MM-dd')
return date == currDate || (!isCompleted && date < currDate);
});
const reminderList = filterList.map(item => ({
title: item.title,
notes: item.notes,
......@@ -211,7 +216,7 @@ class Widget extends BaseWidget {
calendar: item.calendar
}));
const unfinishedList = reminderList.filter(reminder => !reminder.isCompleted);
unfinishedList.sort(function (a, b) { return a.priority - b.priority });
unfinishedList.sort(function (a, b) { return (a.isOverdue || b.isOverdue) ? 1 : (a.priority - b.priority) });
const finishedList = reminderList.filter(reminder => reminder.isCompleted);
return { finishedList, unfinishedList };
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册