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

update

上级 6c095e44
......@@ -3,7 +3,7 @@
// icon-color: red; icon-glyph: user-astronaut;
/**
* Author:LSP
* Date:2022-12-12
* Date:2022-12-13
*/
// -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false
......@@ -27,7 +27,7 @@ const { BaseWidget } = require(dependencyFileName);
class Widget extends BaseWidget {
defaultPreference = {
version: 20221212,
version: 20221213,
domain: 'https://tophub.today',
hotban: [{ title: '微博 · 热搜榜', link: 'https://tophub.today/n/KqndgxeLl9' }],
weiboOpenOptions: [
......@@ -39,8 +39,9 @@ class Widget extends BaseWidget {
// 网络请求头
phoneHeaders: [
{
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1",
"referer": "https://tophub.today/",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.17(0x17001126) NetType/WIFI Language/zh_CN",
"referer": "https://tophub.today/c/news",
},
],
// --------------------------
......@@ -58,6 +59,32 @@ class Widget extends BaseWidget {
largeItemCount: 13
};
getCookie() {
let cookie = '';
const { hotbanCK } = this.readWidgetSetting();
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', '');
console.log(`cookie=>${cookie}`);
}
return cookie;
}
getHotban = (defaultValue) => JSON.parse(this.useFileManager().readStringCache('hotban') ?? (defaultValue ? defaultValue : JSON.stringify(this.defaultPreference.hotban)));
getWeiboOpenType = () => this.getSettingValueByKey('weiboOpenType', this.defaultPreference.weiboOpenOptions[2].name);
getTitleFontSize = () => Number(this.getSettingValueByKey('titleFontSize', `${this.defaultPreference.titleFontSize}`));
......@@ -304,6 +331,23 @@ class Widget extends BaseWidget {
icon: 'https://gitcode.net/4qiao/framework/raw/master/img/icon/setting.gif',
needLoading: true,
childItems: [
{
name: 'hotbanCK',
label: 'TopHub的cookie',
type: 'cell',
icon: { name: 'person.crop.circle.badge.clock', color: '#80b918', },
needLoading: false,
alert: {
title: 'TopHub登录的cookie',
options: [
{
key: 'hotbanCK',
hint: '请输入cookie',
}
]
},
showDesc: false,
},
{
name: 'titleFontSize',
label: '标题文字大小',
......@@ -375,7 +419,7 @@ class Widget extends BaseWidget {
name: 'banCount',
label: '榜单条数',
type: 'cell',
icon: { name: 'list.bullet.rectangle', color: '#00a8e8' },
icon: { name: 'doc.text.below.ecg', color: '#00a8e8' },
alert: {
title: '榜单显示条数',
message: "小组件每次展示的热榜条数",
......@@ -419,7 +463,8 @@ class Widget extends BaseWidget {
let response = undefined;
try {
//////
const html = await this.httpGet(`${this.defaultPreference.domain}/search?q=${encodeURIComponent(keyword)}`, { jsonFormat: false, useCache: false, headers: this.getRandowArrValue(this.defaultPreference.phoneHeaders) });
const headers = { ...this.getRandowArrValue(this.defaultPreference.phoneHeaders), cookie: this.getCookie() };
const html = await this.httpGet(`${this.defaultPreference.domain}/search?q=${encodeURIComponent(keyword)}`, { jsonFormat: false, useCache: false, headers });
let webview = new WebView();
await webview.loadHTML(html);
// 通过dom操作把HTML里面的热榜内容提取出来
......@@ -433,25 +478,50 @@ class Widget extends BaseWidget {
titleArr = []
// 描述
tipArr = []
nodeSize = 0
totalCount = 10
// 图片封面
let allItemNodeList = document.getElementsByClassName('weui-media-box__thumb radius');
for(let node of allItemNodeList) {
if(nodeSize < totalCount) {
coverArr.push(node.src)
} else {
break
}
nodeSize += 1
}
// 链接
nodeSize = 0
allItemNodeList = document.getElementsByClassName('weui-media-box weui-media-box_appmsg weui-cell');
for(let node of allItemNodeList) {
if(nodeSize < totalCount) {
linkArr.push(node.href)
} else {
break
}
nodeSize += 1
}
// 标题
nodeSize = 0
allItemNodeList = document.getElementsByClassName('weui-media-box__title');
for(let node of allItemNodeList) {
if(nodeSize < totalCount) {
titleArr.push(node.innerText)
} else {
break
}
nodeSize += 1
}
// 订阅人数
nodeSize = 0
allItemNodeList = document.getElementsByClassName('weui-media-box__desc');
for(let node of allItemNodeList) {
if(nodeSize < totalCount) {
tipArr.push(node.innerText)
} else {
break
}
nodeSize += 1
}
return { coverArr, linkArr, titleArr, tipArr };
}
......@@ -580,7 +650,19 @@ class Widget extends BaseWidget {
}
textSpan.font = Font.semiboldSystemFont(titleSize);
textSpan.lineLimit = 1;
//
titleStack.addSpacer();
if (!small) {
img = this.getSFSymbol('goforward');
imgSpan = titleStack.addImage(img);
imgSpan.imageSize = new Size(12, 12);
imgSpan.tintColor = new Color(this.getTitleFontColor());
titleStack.addSpacer(4);
textSpan = titleStack.addText(this.getDateStr(new Date(), 'HH:mm'));
textSpan.textColor = new Color(this.getTitleFontColor());
textSpan.font = Font.semiboldSystemFont(titleSize - 4);
titleStack.addSpacer(10);
}
// item
for (let index = 0; index < itemCount; index++) {
const name = titleArr[index];
......@@ -617,14 +699,13 @@ class Widget extends BaseWidget {
return widget;
}
// --------------------------NET START--------------------------
async loadHotBanRES(link) {
// 热榜数据
let response = undefined;
try {
const html = await this.httpGet(link, { jsonFormat: false, headers: this.getRandowArrValue(this.defaultPreference.phoneHeaders) });
const headers = { ...this.getRandowArrValue(this.defaultPreference.phoneHeaders), cookie: this.getCookie() };
const html = await this.httpGet(link, { jsonFormat: false, headers });
let webview = new WebView();
await webview.loadHTML(html);
// 通过dom操作把HTML里面的热榜内容提取出来
......@@ -650,11 +731,17 @@ class Widget extends BaseWidget {
titleArr = []
allItemNodeList = document.querySelectorAll('.rank-item-container')
// 链接&标题
nodeSize = 0
for(let node of allItemNodeList) {
if(nodeSize < 30) {
link = node.href;
linkArr.push(link);
title = node.getElementsByClassName('s-title')[0].innerText
titleArr.push(title);
} else {
break
}
nodeSize += 1
}
return { hotTitle, logoUrl, linkArr, titleArr };
}
......@@ -662,7 +749,9 @@ class Widget extends BaseWidget {
`
// 热榜数据
response = await webview.evaluateJavaScript(getData, false);
if (response.titleArr?.length > 0) {
this.useFileManager().writeStringCache('hot', JSON.stringify(response));
}
} catch (error) {
response = JSON.parse(this.useFileManager().readStringCache('hot'));
console.error(`🚫 请求热板数据出错了=>${error}`);
......@@ -675,7 +764,6 @@ class Widget extends BaseWidget {
await new Widget(Script.name()).run();
// =================================================================================
// =================================================================================
async function downloadLSPDependency() {
......
......@@ -2590,7 +2590,7 @@ class BaseWidget {
case 'itemClick':
widgetSetting = this.readWidgetSetting();
const { label, name, alert, childItems = [] } = data;
const { label, name, showDesc, alert, childItems = [] } = data;
if (childItems.length > 0) {
await this.renderAppView({
isChildLevel: true,
......@@ -2613,7 +2613,7 @@ class BaseWidget {
}
});
this.writeWidgetSetting({ ...widgetSetting });
if (options.length == 1) {
if (options.length == 1 && showDesc) {
this.insertTextByElementId(previewWebView, name, inputArr[0].value);
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册