diff --git a/script/magicjs/images/qinglong.png b/script/magicjs/images/qinglong.png index e064a89ec..20c1443e1 100644 Binary files a/script/magicjs/images/qinglong.png and b/script/magicjs/images/qinglong.png differ diff --git a/script/magicjs/images/qinglong_dark.png b/script/magicjs/images/qinglong_dark.png index 05fddfe7a..10411217a 100644 Binary files a/script/magicjs/images/qinglong_dark.png and b/script/magicjs/images/qinglong_dark.png differ diff --git a/script/smzdm/README.md b/script/smzdm/README.md index d9ff862cc..f0209e641 100644 --- a/script/smzdm/README.md +++ b/script/smzdm/README.md @@ -1,30 +1,25 @@ -# 什么值得买 - -## 特别说明 - -什么值得买执行任务时,对每次任务的时间间隔有一定的要求,过短的时间间隔可能会没有任何奖励。如果在短时间内并行发起大量请求的话,严重的情况会导致账号异常,需要修改密码。所以在每次执行任务时,都加入了3秒的休眠时间,这会导致脚本的执行时间需要非常长,差不多1分钟左右。请把脚本超时时间设置到最长,建议2分钟以上,以免因为超时被强制中断。 - -2021年1月18日 - -实测会引起账号异常,无法参与幸运屋抽奖,其他功能暂未发现异常,不在意抽奖的可以继续使用,在意抽奖的请谨慎考虑。**目前将签到和任务拆分为两个脚本,仅需要签到使用signin脚本即可。** - -## 最近更新 - -2020年12月22日: - -适配最新的个人中心返回Html格式。 - -去除威望显示,现在获取不到威望这个属性了。 - -去除完成点击“去购买”的任务的功能,现在只能在APP端操作才有经验。现在每日经验约有40左右。什么值得买官方完全有办法封禁所有的Web端完成任务功能,现在还能执行部分任务纯属官方放水,且用且珍惜吧,不保证哪一天就没办法通过脚本完成任务了。 +# 🧸什么值得买 ## 签到与每日任务 -什么值得买Web端和App端每日自动签到脚本,并且完成每日点击去购买10次、点值5次、点赞5次、收藏5次的任务。 +什么值得买签到和任务脚本,每日完成Web端签到、抽奖一次,收藏文章7次。 -执行效果如下,会显示昵称、级别、经验值变动总数、经验值变动明细、任务完成情况。 +## 特别说明 -![](https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/images/01.png) +### 脚本执行时间 + +什么值得买执行任务时,对每次任务的时间间隔有一定的要求,过短的时间间隔可能会没有任何奖励。如果在短时间内并行发起大量请求的话,严重的情况会导致账号异常,需要修改密码。所以在每次执行任务时,都加入休眠时间,这会导致脚本的执行时间需要非常长。请把脚本超时时间设置到最长,建议2分钟以上,以免因为超时被强制中断。 + +### 账号异常 + +可能会引起账号异常,无法参与幸运屋抽奖,其他功能暂未发现异常,不在意抽奖的可以继续使用,在意抽奖的请谨慎考虑。 + +## 最近更新 + +2022年9月8日 + +1. 合并签到和任务脚本,可以在BoxJS中关闭 +2. 增加多账号签到和任务功能 ### 配置说明 @@ -32,43 +27,55 @@ ##### **安装模块** -Surge推荐使用模块进行部署,模块地址:https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.sgmodule +```ini +https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_daily.sgmodule +``` ### Loon -**远程脚本** - -直接在配置里修改 +安装插件 ```ini -[Remote Script] -https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.lnscript, tag=什么值得买_每日签到, enabled=true +https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_daily.lnplugin ``` ### Quantumult X -远程复写配置 +配置重写 ```ini [rewrite_remote] -https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.qxrewrite, tag=什么值得买_获取Cookie, update-interval=86400, opt-parser=false, enabled=true +https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_daily.qxrewrite, tag=什么值得买_获取Cookie, update-interval=86400, opt-parser=false, enabled=true [task_local] -5 0 * * * https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.js, tag=什么值得买每日签到 +5 0 * * * https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_daily.js, tag=什么值得买每日签到 ``` -### 使用说明 +## 获取Cookies -#### **Web端获取Cookie:** +**使用Safari,不要使用第三方浏览器!** -使用Safari,不要使用第三方浏览器! - -使用手机浏览器访问 https://zhiyou.smzdm.com/ 进行一次登录,通常会显示获取cookie成功。 +使用Safari访问 https://zhiyou.smzdm.com/ 进行一次登录,通常会显示获取Cookie成功。 可能因为重定向的问题,登录成功后访问的不是https://zhiyou.smzdm.com/user/ ,则重新在浏览器中访问一次https://zhiyou.smzdm.com/user/ 即可。 如果还是没有获取到Cookie,请查阅Surge等第三方App的执行日志。 +### 多账号获取Cookies + +使用浏览器的无痕模式、隐身模式等功能实现不同账号的登录和切换。 + +## 脚本变量 + +| 名称 | 类型 | 说明 | +| ------------------- | ---- | --------------------------------- | +| smzdm_cookie | Json | 存储什么值得买Cookies | +| smzdm_cookie_id | Json | 辅助判断什么值得买Cookies是否变化 | +| smzdm_signin | Bool | 是否打开什么值得买签到 | +| smzdm_mission | Bool | 是否打开什么值得买每日任务 | +| smzdm_lottery | Bool | 是否打开什么值得买每日抽奖 | +| smzdm_sync_qinglong | Bool | 是否同步Cookies至青龙面板 | + ## 去广告 去除什么值得买首页、好价、好文内的广告 @@ -77,95 +84,26 @@ https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smz #### Surge -##### 配置文件 - -在配置文件中修改。 +使用模块 ```ini -[MITM] -hostname = homepage-api.smzdm.com, haojia-api.smzdm.com, article-api.smzdm.com - -[Script] -什么值得买_首页去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https:\/\/homepage-api.smzdm.com\/home,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_remove_ads.js -什么值得买_好价去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https:\/\/haojia-api.smzdm.com\/home\/list,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_remove_ads.js -什么值得买_好文去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https:\/\/article-api.smzdm.com\/article\/index_home_page,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_remove_ads.js + https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_remove_ads.sgmodule ``` -##### 模块安装 - -模块地址: https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_remove_ads.sgmodule - ### Loon -**远程脚本** +使用插件 ```ini -[Remote Script] -https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_remove_ads.lnscript, tag=什么值得买_去广告, enabled=true +https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_remove_ads.lnplugin ``` ### Quantumult X -**远程复写脚本** +配置重写 ```ini [rewrite_remote] https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_remove_ads.qxrewrite, tag=什么值得买_去广告, update-interval=86400, opt-parser=false, enabled=true ``` -## 统一推送 - -MagicJS利用Bark,实现了跨设备的统一推送能力,将多个iOS设备的脚本执行结果,统一推送到一个设备上。 - -执行效果图,以饿了么为例: - -![](https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/eleme/images/bark.jpg) - -### 开启统一推送 - -你需要安装Bark这个APP,打开后可以得到类似这样的链接: - -```http -https://api.day.app/VXTWvaQ18N29bsQAg7DgkT -``` - -在Surge、Loon、QuantumultX中执行以下代码,将链接写入(如何执行代码请自己动手解决)。 - -**Surge、Loon** - -```javascript -# 开启所有脚本统一推送 -$persistentStore.write("https://api.day.app/VXTWvaQ18N29bsQAg7DgkT", "magicjs_unified_push_url"); -``` - -**Quantumult X** - -```javascript -# 开启所有脚本统一推送 -$prefs.setValueForKey("https://api.day.app/VXTWvaQ18N29bsQAg7DgkT", "magicjs_unified_push_url"); -``` - -### 关闭统一推送 - -**Surge、Loon** - -```javascript -# 关闭所有脚本统一推送 -$persistentStore.write("", "magicjs_unified_push_url"); -``` - -**Quantumult X** - -```javascript -# 关闭所有脚本统一推送 -$prefs.setValueForKey("", "magicjs_unified_push_url"); -``` - -### 其他 - -1. 统一推送能力仅对支持的脚本有效。 -2. 开启统一推送后,所有支持统一推送的脚本,都会把通知推送到目标设备上。 -3. 限于Bark的功能,统一推送中的多媒体和链接不可用。 -4. 统一推送需要使用Bark的服务器,推送成功与否,与Bark服务器的可用性有关。 -5. 统一推送不会关闭APP的本地推送,即两个iOS设备都会有推送。 -6. 如有隐私考虑,可以参考Bark的服务端文档,自建服务端。 \ No newline at end of file diff --git a/script/smzdm/images/checkin.jpg b/script/smzdm/images/checkin.jpg deleted file mode 100644 index c2b848145..000000000 Binary files a/script/smzdm/images/checkin.jpg and /dev/null differ diff --git a/script/smzdm/smzdm_daily.js b/script/smzdm/smzdm_daily.js new file mode 100644 index 000000000..c9452f769 --- /dev/null +++ b/script/smzdm/smzdm_daily.js @@ -0,0 +1,471 @@ +const zhiyouRegex = /^https?:\/\/zhiyou\.smzdm\.com\/user$/; +const smzdmCookieKey = "smzdm_cookie"; +const smzdmCookieIdKey = "smzdm_cookie_id"; +const smzdmSigninKey = "smzdm_signin"; +const smzdmMissionKey = "smzdm_mission"; +const smzdmLotteryKey = "smzdm_lottery"; +const smzdmSyncQinglongKey = "smzdm_sync_qinglong"; +const scriptName = '什么值得买'; +const clickFavArticleMaxTimes = 7; // 好文收藏次数 + +const $ = MagicJS(scriptName, "INFO"); +let currentCookie = ""; + +function randomStr() { + let len = 17; + let char = '0123456789'; + let str = '' + for (i = 0; i < len; i++) { + str += char.charAt(Math.floor(Math.random() * char.length)); + } + return str; +} + +$.http.interceptors.request.use((config) => { + if (!!currentCookie) { + config.headers.Cookie = currentCookie; + } + return config; +}); + +// Web端登录获取Cookie +async function getWebCookie() { + try { + currentCookie = $.request.headers.cookie || $.request.headers.Cookie; + if (currentCookie.length >= 200) { + + $.logger.info(`当前页面获取的Cookie: ${currentCookie}`); + const matchStr = currentCookie.match(/__ckguid=[^\s]*;/); + const cookieId = matchStr !== null ? matchStr[0] : null; + $.logger.info(`当前页面获取的CookieId\n${cookieId}`); + // 获取新的session_id + if (cookieId) { + const userInfo = await getWebUserInfo(); + // 获取持久化的session_id + let oldCookieId = $.data.read(smzdmCookieIdKey, "", userInfo.smzdm_id); + $.logger.info(`从客户端存储池中读取的CookieId\n${oldCookieId}`); + // 获取新的session_id + $.logger.info(`旧的CookieId:\n${oldCookieId}\n新的CookieId:\n${cookieId}`); + // 比较差异 + if (oldCookieId == cookieId) { + $.logger.info('当前页面获取的Cookie与客户端存储的Cookie相同,无需更新。'); + } + else { + if (userInfo.blackroom_desc && userInfo.blackroom_level) { + $.notification.post(`⚠️您的账户已在小黑屋中,请谨慎使用自动签到和任务!\n小黑屋类型:${userInfo.blackroom_desc}\小黑屋等级:${userInfo.blackroom_level}`); + } + $.data.write(smzdmCookieIdKey, cookieId, userInfo.smzdm_id); + $.data.write(smzdmCookieKey, currentCookie, userInfo.smzdm_id); + $.logger.info(`写入cookie\n${currentCookie}`); + $.notification.post(scriptName, '', '🎈获取Cookie成功!!'); + } + + // 同步到青龙面板 + if ($.data.read(smzdmSyncQinglongKey, false) === true) { + oldCookieId = await $.qinglong.read(smzdmCookieIdKey, "", userInfo.smzdm_id); + $.logger.info(`从青龙面板读取的CookieId\n${oldCookieId}`); + if (oldCookieId !== cookieId) { + await $.qinglong.write(smzdmCookieIdKey, cookieId, userInfo.smzdm_id); + await $.qinglong.write(smzdmCookieKey, currentCookie, userInfo.smzdm_id); + $.logger.info(`同步cookie\n${currentCookie}`); + $.notification.post(scriptName, '', '🎈同步Cookie至青龙面板成功!!'); + } + else { + $.logger.info(`当前页面获取的Cookie与青龙面板存储的Cookie相同,无需更新。`) + } + } + } + } + else { + $.logger.warning('没有读取到有效的Cookie信息。'); + } + } + catch (err) { + $.logger.error(`获取什么值得买Cookies出现异常,${err}`); + } +} + +// Web端签到 +function webSignin() { + return new Promise((resolve, reject) => { + let ts = Date.parse(new Date()); + $.http.get({ + url: `https://zhiyou.smzdm.com/user/checkin/jsonp_checkin?callback=jQuery11240${randomStr()}_${ts}&_=${ts + 3}`, + headers: { + 'Accept': '*/*', + 'Accept-Language': 'zh-cn', + 'Connection': 'keep-alive', + 'Host': 'zhiyou.smzdm.com', + 'Referer': 'https://www.smzdm.com/', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15' + } + }).then(resp => { + let data = /\((.*)\)/.exec(resp.body); + if (data) { + let obj = JSON.parse(data[1]); + if (!!obj && obj.hasOwnProperty('error_code')) { + if (obj.error_code == -1) { + $.logger.warning(`Web端签到出现异常,网络繁忙,接口返回:${data}`); + reject('Web:网络繁忙'); + } + else if (obj['error_code'] == 99) { + $.logger.warning('Web端Cookie已过期'); + resolve([false, 'Web:Cookie过期']); + } + else if (obj['error_code'] == 0) { + $.logger.info('Web:签到成功'); + resolve([true, 'Web:签到成功']); + } + else { + $.logger.warning(`Web端签到出现异常,接口返回数据不合法:${data}`); + reject('Web:返回错误'); + } + } + } + else { + $.logger.warning(`Web端签到出现异常,接口返回数据不存在:${data}`); + reject('Web:签到异常'); + } + }).catch(err => { + $.logger.error(`Web端签到出现异常,${err}`); + reject('Web:签到异常'); + }) + }) +} + +// 获取用户信息 +function getWebUserInfo() { + let userInfo = { + "smzdm_id": null, // 什么值得买Id + "nick_name": null, // 昵称 + "avatar": null, // 头像链接 + "has_checkin": null, // 是否签到 + "daily_checkin_num": null, // 连续签到天数 + "unread_msg": null, // 未读消息 + "level": null, // 旧版等级 + "vip": null, // 新版VIP等级 + "exp": null, // 旧版经验 + "point": null, // 积分 + "gold": null, // 金币 + "silver": null, // 碎银子 + "prestige": null, // 威望 + "user_point_list": [], // 近期经验变动情况 + "blackroom_desc": "", + "blackroom_level": "" + } + return new Promise(async resolve => { + // 获取旧版用户信息 + await $.http.get({ + url: `https://zhiyou.smzdm.com/user/info/jsonp_get_current?with_avatar_ornament=1&callback=jQuery112403507528653716241_${new Date().getTime()}&_=${new Date().getTime()}`, + headers: { + 'Accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01', + 'Accept-Language': 'zh-CN,zh;q=0.9', + 'Connection': 'keep-alive', + 'Host': 'zhiyou.smzdm.com', + 'Referer': 'https://zhiyou.smzdm.com/user/', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36' + } + }).then(resp => { + let obj = JSON.parse(/\((.*)\)/.exec(resp.body)[1]); + if (obj['smzdm_id'] !== 0) { + userInfo.smzdm_id = obj['smzdm_id']; + userInfo.nick_name = obj['nickname'] // 昵称 + userInfo.avatar = `https:${obj['avatar']}` // 头像链接 + userInfo.has_checkin = obj['checkin']['has_checkin'] // 是否签到 + userInfo.daily_checkin_num = obj['checkin']['daily_checkin_num'] // 连续签到天数 + userInfo.unread_msg = obj['unread']['notice']['num'] // 未读消息数 + userInfo.level = obj['level'] // 旧版等级 + userInfo.vip = obj['vip_level'] // 新版VIP等级 + userInfo.blackroom_desc = obj['blackroom_desc'] // 小黑屋描述 + userInfo.blackroom_desc = obj['blackroom_level'] // 小黑屋等级 + // userInfo.exp = obj['exp'] // 旧版经验 + // userInfo.point = obj['point'] // 积分 + // userInfo.gold = obj['gold'] // 金币 + // userInfo.silver = obj['silver'] // 碎银子 + } + else { + $.logger.warning(`获取用户信息异常,Cookie过期或接口变化:${JSON.stringify(obj)}`); + } + }).catch(err => { + $.logger.error(`获取用户信息异常,${err}`); + }) + // 获取新版用户信息 + await $.http.get({ + url: "https://zhiyou.smzdm.com/user/exp/", + body: '' + }).then(resp => { + const data = resp.body; + // 获取用户名 + userInfo.nick_name = data.match(/info-stuff-nickname.*zhiyou\.smzdm\.com\/user[^<]*>([^<]*)(.*)<\/div>/ig); + const pointDetailList = data.match(/
(.*)<\/div>/ig); + const minLength = pointTimeList.length > pointDetailList.length ? pointDetailList.length : pointTimeList.length; + let userPointList = []; + for (let i = 0; i < minLength; i++) { + userPointList.push({ + 'time': pointTimeList[i].match(/\
(.*)\<\/div\>/)[1], + 'detail': pointDetailList[i].match(/\
(.*)\<\/div\>/)[1] + }); + } + userInfo.user_point_list = userPointList; + // 获取用户资源 + const assetsNumList = data.match(/assets-part[^<]*>(.*)(.*)(.*)(.*)(.*) { + $.logger.error(`获取新版用户信息出现异常,${err}`); + }) + // 返回结果 + resolve(userInfo); + }) +} + +// 每日抽奖 +function lotteryDraw() { + return new Promise(async (resolve, reject) => { + let activeId = ""; + await $.http.get({ + url: "https://m.smzdm.com/zhuanti/life/choujiang/", + headers: { + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Host": "m.smzdm.com", + "User-Agent": + "Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148/smzdm 9.9.6 rv:93.4 (iPhone13,4; iOS 14.5; zh_CN)/iphone_smzdmapp/9.9.6/wkwebview/jsbv_1.0.0", + } + }).then(resp => { + let _activeId = /name\s?=\s?\"lottery_activity_id\"\s+value\s?=\s?\"([a-zA-Z0-9]*)\"/.exec(resp.body); + if (_activeId) { + activeId = _activeId[1]; + } else { + $.logger.warning(`获取每日抽奖activeId失败`); + } + }).catch(err => { + $.logger.error(`获取每日抽奖activeId失败,${err}`); + }) + if (!!activeId) { + await $.http.get({ + url: `https://zhiyou.smzdm.com/user/lottery/jsonp_draw?callback=jQuery34109305207178886287_${new Date().getTime()}&active_id=${activeId}&_=${new Date().getTime()}`, + headers: { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Host": "zhiyou.smzdm.com", + "Referer": "https://m.smzdm.com/zhuanti/life/choujiang/", + "User-Agent": + "Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148/smzdm 9.9.0 rv:91 (iPhone 11 Pro Max; iOS 14.2; zh_CN)/iphone_smzdmapp/9.9.0/wkwebview/jsbv_1.0.0", + } + }).then(resp => { + let data = /\((.*)\)/.exec(resp.body); + let obj = JSON.parse(data[1]); + if (obj.error_code === 0 || obj.error_code === 1 || obj.error_code === 4) { + resolve(obj.error_msg); + } else { + $.logger.error(`每日抽奖失败,接口响应异常:${data}`); + resolve("每日抽奖失败,接口响应异常"); + } + }).catch(err => { + $.logger.error(`每日抽奖失败,${err}`); + resolve("每日抽奖失败,接口/执行异常"); + }) + } + }) +} + +// 收藏文章 +function clickFavArticle(articleId) { + return new Promise((resolve, reject) => { + $.http.post({ + url: "https://zhiyou.smzdm.com/user/favorites/ajax_favorite", + headers: { + "Accept": "application/json, text/javascript, */*; q=0.01", + "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + "Host": "zhiyou.smzdm.com", + "Origin": "https://post.smzdm.com", + "Referer": "https://post.smzdm.com/", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.41", + }, + body: `article_id=${articleId}&channel_id=11&client_type=PC&event_key=%E6%94%B6%E8%97%8F&otype=%E6%94%B6%E8%97%8F&aid=${articleId}&cid=11&p=2&source=%E6%97%A0&atp=76&tagID=%E6%97%A0&sourcePage=https%3A%2F%2Fpost.smzdm.com%2F&sourceMode=%E6%97%A0`, + }).then(resp => { + const obj = resp.body; + if (obj.error_code == 0) { + $.logger.debug(`好文${articleId}收藏成功`); + resolve(true); + } else if (obj.error_code == 2) { + $.logger.debug(`好文${articleId}取消收藏成功`); + resolve(true); + } else { + $.logger.error(`好文${articleId}收藏失败,${JSON.stringify(obj)}`); + resolve(false); + } + }).catch(err => { + $.logger.error(`文章加入/取消收藏失败,${err}`); + reject(false); + }) + }) +} + +// 收藏文章任务 +function favArticles() { + return new Promise(async (resolve, reject) => { + let articlesId = []; + let success = 0; + await $.http.get({ + url: "https://post.smzdm.com/", + headers: { + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", + "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", + "Host": "post.smzdm.com", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.41", + }, + body: "" + }).then(resp => { + const articleList = resp.body.match(/data-article=".*" data-type="zan"/gi); + articleList.forEach((element) => { + articlesId.push(element.match(/data-article="(.*)" data-type="zan"/)[1]); + }); + }).catch(err => { + $.logger.error(`获取待收藏的文章列表失败,${err}`); + reject(err); + }) + let favArticlesId = articlesId.splice(0, clickFavArticleMaxTimes); + if (favArticlesId.length > 0) { + // 加入收藏 + for (let articleId of favArticlesId) { + await $.utils.retry(clickFavArticle, 3, 500)(articleId + ).then(result => { + if (result === true) { + success += 1; + } + }).catch(err => { + $.logger.error(`文章加入收藏失败,${err}`); + }) + await $.utils.sleep(500); + } + // 取消收藏 + for (let articleId of articlesId) { + await $.utils.retry(clickFavArticle, 3, 500)(articleId).catch(err => { + $.logger.error(`文章取消收藏失败,${err}`); + }) + } + } + resolve(success); + }) +} + +// 多用户签到 +async function multiUsersSingin() { + const allSessions = $.data.allSessions(smzdmCookieKey); + if (!allSessions || allSessions.length === 0) { + $.logger.error(scriptName, "", "没有发现需要签到的Cookies\n请点击通知进行登录。", { "open-url": "https://zhiyou.smzdm.com/user/login?redirect_to=http://zhiyou.smzdm.com/user" }); + } + else { + $.logger.info(`当前共 ${allSessions.length} 个Cookies需要进行签到/任务。`); + for (let [index, session] of allSessions.entries()) { + $.logger.info(`当前正在进行第 ${index + 1} 个Cookie签到`); + // 通知信息 + let title = ''; + let subTitle = ''; + let content = ''; + + // 获取Cookies + currentCookie = $.data.read(smzdmCookieKey, "", session); + + // 查询签到前用户数据 + const beforeUserInfo = await getWebUserInfo(); + + // Web端签到 + if ($.data.read(smzdmSigninKey, true) === true) { + await $.utils.retry(webSignin, 10, 500)().catch(err => { + subTitle = `Web端签到异常: ${err}`; + }); + } + + // 日常任务 + if ($.data.read(smzdmMissionKey, true) === true) { + const success = await favArticles(); + const msg = `每日收藏文章任务 ${success}/${clickFavArticleMaxTimes}`; + content += !!content ? `\n${msg}` : msg; + $.logger.info(msg); + } + + // 抽奖 + if ($.data.read(smzdmLotteryKey, true) === true) { + const msg = await lotteryDraw(); + content += !!content ? '\n' : ''; + content += msg; + $.logger.info(msg); + } + + // 休眠 + await $.utils.sleep(3000); + + // 获取签到后的用户信息 + const afterUserInfo = await getWebUserInfo(); + + // 重复签到 + if (afterUserInfo.has_checkin === true && beforeUserInfo.has_checkin === true) { + subTitle = "Web端重复签到"; + } + else { + subTitle = `已连续签到${afterUserInfo.daily_checkin_num}天`; + } + + // 记录日志 + let msg = `昵称:${beforeUserInfo.nick_name}\nWeb端签到状态:${afterUserInfo.has_checkin}\n签到后等级${afterUserInfo.vip},积分${afterUserInfo.point},经验${afterUserInfo.exp},金币${afterUserInfo.gold},碎银子${afterUserInfo.silver},未读消息${afterUserInfo.unread_msg}`; + $.logger.info(msg); + + // 通知 + if (beforeUserInfo.exp && afterUserInfo.exp) { + let addPoint = afterUserInfo.point - beforeUserInfo.point; + let addExp = afterUserInfo.exp - beforeUserInfo.exp; + let addGold = afterUserInfo.gold - beforeUserInfo.gold; + let addSilver = afterUserInfo.silver - beforeUserInfo.silver; + content += !!content ? '\n' : ''; + content += '积分' + afterUserInfo.point + (addPoint > 0 ? '(+' + addPoint + ')' : '') + + ' 经验' + afterUserInfo.exp + (addExp > 0 ? '(+' + addExp + ')' : '') + + ' 金币' + afterUserInfo.gold + (addGold > 0 ? '(+' + addGold + ')' : '') + '\n' + + '碎银子' + afterUserInfo.silver + (addSilver > 0 ? '(+' + addSilver + ')' : '') + + ' 未读消息' + afterUserInfo.unread_msg; + } + title = `${scriptName} - ${afterUserInfo.nick_name} V${afterUserInfo.vip}`; + $.notification.post(title, subTitle, content, { 'media-url': afterUserInfo.avatar }); + + $.logger.info(`第 ${index + 1} 个Cookie签到完毕`); + } + } +} + +(async () => { + if ($.isRequest && zhiyouRegex.test($.request.url) && $.request.method.toUpperCase() == "GET") { + await getWebCookie(); + } + else { + await multiUsersSingin(); + } + $.done(); +})() + +/** + * + * $$\ $$\ $$\ $$$$$\ $$$$$$\ $$$$$$\ + * $$$\ $$$ | \__| \__$$ |$$ __$$\ $$ ___$$\ + * $$$$\ $$$$ | $$$$$$\ $$$$$$\ $$\ $$$$$$$\ $$ |$$ / \__| \_/ $$ | + * $$\$$\$$ $$ | \____$$\ $$ __$$\ $$ |$$ _____| $$ |\$$$$$$\ $$$$$ / + * $$ \$$$ $$ | $$$$$$$ |$$ / $$ |$$ |$$ / $$\ $$ | \____$$\ \___$$\ + * $$ |\$ /$$ |$$ __$$ |$$ | $$ |$$ |$$ | $$ | $$ |$$\ $$ | $$\ $$ | + * $$ | \_/ $$ |\$$$$$$$ |\$$$$$$$ |$$ |\$$$$$$$\\$$$$$$ |\$$$$$$ | \$$$$$$ | + * \__| \__| \_______| \____$$ |\__| \_______|\______/ \______/ \______/ + * $$\ $$ | + * \$$$$$$ | + * \______/ + * +*/ +function MagicJS(e="MagicJS",t="INFO"){const r=()=>{const e=typeof $loon!=="undefined";const t=typeof $task!=="undefined";const n=typeof module!=="undefined";const r=typeof $httpClient!=="undefined"&&!e;const i=typeof $storm!=="undefined";const o=typeof $environment!=="undefined"&&typeof $environment["stash-build"]!=="undefined";const s=r||e||i||o;const a=typeof importModule!=="undefined";return{isLoon:e,isQuanX:t,isNode:n,isSurge:r,isStorm:i,isStash:o,isSurgeLike:s,isScriptable:a,get name(){if(e){return"Loon"}else if(t){return"QuantumultX"}else if(n){return"NodeJS"}else if(r){return"Surge"}else if(a){return"Scriptable"}else{return"unknown"}},get build(){if(r){return $environment["surge-build"]}else if(o){return $environment["stash-build"]}else if(i){return $storm.buildVersion}},get language(){if(r||o){return $environment["language"]}},get version(){if(r){return $environment["surge-version"]}else if(o){return $environment["stash-version"]}else if(i){return $storm.appVersion}else if(n){return process.version}},get system(){if(r){return $environment["system"]}else if(n){return process.platform}},get systemVersion(){if(i){return $storm.systemVersion}},get deviceName(){if(i){return $storm.deviceName}}}};const i=(n,e="INFO")=>{let r=e;const i={SNIFFER:6,DEBUG:5,INFO:4,NOTIFY:3,WARNING:2,ERROR:1,CRITICAL:0,NONE:-1};const o={SNIFFER:"",DEBUG:"",INFO:"",NOTIFY:"",WARNING:"❗ ",ERROR:"❌ ",CRITICAL:"❌ ",NONE:""};const t=(e,t="INFO")=>{if(!(i[r]{r=e};return{setLevel:s,sniffer:e=>{t(e,"SNIFFER")},debug:e=>{t(e,"DEBUG")},info:e=>{t(e,"INFO")},notify:e=>{t(e,"NOTIFY")},warning:e=>{t(e,"WARNING")},error:e=>{t(e,"ERROR")},retry:e=>{t(e,"RETRY")}}};return new class{constructor(e,t){this._startTime=Date.now();this.version="3.0.0";this.scriptName=e;this.env=r();this.logger=i(e,t);this.http=typeof MagicHttp==="function"?MagicHttp(this.env,this.logger):undefined;this.data=typeof MagicData==="function"?MagicData(this.env,this.logger):undefined;this.notification=typeof MagicNotification==="function"?MagicNotification(this.scriptName,this.env,this.logger,this.http):undefined;this.utils=typeof MagicUtils==="function"?MagicUtils(this.env,this.logger):undefined;this.qinglong=typeof MagicQingLong==="function"?MagicQingLong(this.env,this.data,this.logger):undefined;if(typeof this.data!=="undefined"){let e=this.data.read("magic_loglevel");const n=this.data.read("magic_bark_url");if(e){this.logger.setLevel(e.toUpperCase())}if(n){this.notification.setBark(n)}}}get isRequest(){return typeof $request!=="undefined"&&typeof $response==="undefined"}get isResponse(){return typeof $response!=="undefined"}get isDebug(){return this.logger.level==="DEBUG"}get request(){return typeof $request!=="undefined"?$request:undefined}get response(){if(typeof $response!=="undefined"){if($response.hasOwnProperty("status"))$response["statusCode"]=$response["status"];if($response.hasOwnProperty("statusCode"))$response["status"]=$response["statusCode"];return $response}else{return undefined}}done=(e={})=>{this._endTime=Date.now();let t=(this._endTime-this._startTime)/1e3;this.logger.info(`SCRIPT COMPLETED: ${t} S.`);if(typeof $done!=="undefined"){$done(e)}}}(e,t)}function MagicHttp(u,c){const t="Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1";const n="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36 Edg/84.0.522.59";let f;if(u.isNode){const a=require("axios");f=a.create()}class e{constructor(e=true){this.handlers=[];this.isRequest=e}use(e,t,n){this.handlers.push({fulfilled:e,rejected:t,synchronous:n?n.synchronous:false,runWhen:n?n.runWhen:null});return this.handlers.length-1}eject(e){if(this.handlers[e]){this.handlers[e]=null}}forEach(t){this.handlers.forEach(e=>{if(e!==null){t(e)}})}}function r(e){let n={...e};if(!!n.params){if(!u.isNode){let e=Object.keys(n.params).map(e=>{const t=encodeURIComponent(e);n.url=n.url.replace(new RegExp(`${e}=[^&]*`,"ig"),"");n.url=n.url.replace(new RegExp(`${t}=[^&]*`,"ig"),"");return`${t}=${encodeURIComponent(n.params[e])}`}).join("&");if(n.url.indexOf("?")<0)n.url+="?";if(!/(&|\?)$/g.test(n.url)){n.url+="&"}n.url+=e;delete n.params;c.debug(`Params to QueryString: ${n.url}`)}}return n}const d=(e,t)=>{let n=typeof t==="object"?{headers:{},...t}:{url:t,headers:{}};if(!n.method){n["method"]=e}n=r(n);if(n["rewrite"]===true){if(u.isSurge){n.headers["X-Surge-Skip-Scripting"]=false;delete n["rewrite"]}else if(u.isQuanX){n["hints"]=false;delete n["rewrite"]}}if(u.isSurge){if(n["method"]!=="GET"&&n.headers["Content-Type"].indexOf("application/json")>=0&&n.body instanceof Array){n.body=JSON.stringify(n.body);c.debug(`Convert Array object to String: ${n.body}`)}}else if(u.isQuanX){if(n.hasOwnProperty("body")&&typeof n["body"]!=="string")n["body"]=JSON.stringify(n["body"]);n["method"]=e}else if(u.isNode){if(e==="POST"||e==="PUT"||e==="PATCH"||e==="DELETE"){n.data=n.data||n.body}else if(e==="GET"){n.params=n.params||n.body}delete n.body}return n};const p=(t,n=null)=>{if(t){let e={...t,config:t.config||n,status:t.statusCode||t.status,body:t.body||t.data,headers:t.headers||t.header};if(typeof e.body==="string"){try{e.body=JSON.parse(e.body)}catch{}}delete t.data;return e}else{return t}};const i=r=>{if(!!r){delete r["Content-Length"];let e=new Set(["Accept","Accept-CH","Accept-Charset","Accept-Features","Accept-Encoding","Accept-Language","Accept-Ranges","Access-Control-Allow-Credentials","Access-Control-Allow-Origin","Access-Control-Allow-Methods","Access-Control-Allow-Headers","Access-Control-Max-Age","Access-Control-Expose-Headers","Access-Control-Request-Method","Access-Control-Request-Headers","Age","Allow","Alternates","Authorization","Cache-Control","Connection","Content-Encoding","Content-Language","ontent-Length","Content-Location","Content-Range","Content-Security-Policy","Content-Type","Cookie","DNT","Date","ETag","Expect","Expires","From","Host","If-Match","If-Modified-Since","If-None-Match","If-Range","If-Unmodified-Since","Last-Event-ID","Last-Modified","Link","Location","Max-Forwards","Negotiate","Origin","Pragma","Proxy-Authenticate","Proxy-Authorization","Range","Referer","Retry-After","Sec-Websocket-Extensions","Sec-Websocket-Key","Sec-Websocket-Origin","Sec-Websocket-Protocol","Sec-Websocket-Version","Server","Set-Cookie","Set-Cookie2","Strict-Transport-Security","TCN","TE","Trailer","Transfer-Encoding","Upgrade","User-Agent","Variant-Vary","Vary","Via","Warning","WWW-Authenticate","X-Content-Duration","X-Content-Security-Policy","X-DNSPrefetch-Control","X-Frame-Options","X-Requested-With"]);for(let n of Object.keys(r)){if(!e.has(n)){for(let t of e){let e=n.replace(new RegExp(t,"ig"),t);if(n!==e){r[e]=r[n];delete r[n];break}}}}if(!r["User-Agent"]){if(u.isNode){r["User-Agent"]=n}else{r["User-Agent"]=t}}return r}return r};const g=(t,n=null)=>{if(!!t&&t.status>=400){c.debug(`Raise exception when status code is ${t.status}`);let e={name:"RequestException",message:`Request failed with status code ${t.status}`,config:n||t.config,response:t};return e}};const o={request:new e,response:new e(false)};let y=[];let h=[];let m=true;function $(e){if(typeof e==="object"&&e["modify"]!==false){e["headers"]=i(e["headers"])}e=r(e);return e}function b(e){try{e=!!e?p(e):e;c.sniffer(`HTTP ${e.config["method"].toUpperCase()}:\n${JSON.stringify(e.config)}\nSTATUS CODE:\n${e.status}\nRESPONSE:\n${typeof e.body==="object"?JSON.stringify(e.body):e.body}`);const t=g(e);if(!!t){return Promise.reject(t)}return e}catch(t){c.error(t);return e}}const S=t=>{try{y=[];h=[];o.request.forEach(e=>{if(typeof e.runWhen==="function"&&e.runWhen(t)===false){return}m=m&&e.synchronous;y.unshift(e.fulfilled,e.rejected)});o.response.forEach(e=>{h.push(e.fulfilled,e.rejected)})}catch(e){c.error(`failed to register interceptors: ${e}`)}};const s=(e,r)=>{let i;const t=e.toUpperCase();r=d(t,r);if(u.isNode){i=f}else{if(u.isSurgeLike){i=o=>{return new Promise((r,i)=>{$httpClient[e.toLowerCase()](o,(t,n,e)=>{if(t){let e={name:t.name||t,message:t.message||t,stack:t.stack||t,config:o,response:p(n)};i(e)}else{n.config=o;n.body=e;r(n)}})})}}else{i=i=>{return new Promise((n,r)=>{$task.fetch(i).then(e=>{e=p(e,i);const t=g(e,i);if(t){return Promise.reject(t)}n(e)}).catch(e=>{let t={name:e.message||e.error,message:e.message||e.error,stack:e.error,config:i,response:!!e.response?p(e.response):null};r(t)})})}}}let o;S(r);const s=[$,undefined];const a=[b,undefined];if(!m){c.debug("Interceptors are executed in asynchronous mode");let n=[i,undefined];Array.prototype.unshift.apply(n,s);Array.prototype.unshift.apply(n,y);Array.prototype.unshift.apply(n,s);n=n.concat(a);n=n.concat(h);o=Promise.resolve(r);while(n.length){try{let e=n.shift();let t=n.shift();if(!u.isNode&&r["timeout"]&&e===i){o=l(r)}else{o=o.then(e,t)}}catch(e){c.error(`request exception: ${e}`)}}return o}else{c.debug("Interceptors are executed in synchronous mode");Array.prototype.unshift.apply(y,s);y=y.concat([$,undefined]);while(y.length){let e=y.shift();let t=y.shift();try{r=e(r)}catch(e){t(e);break}}try{if(!u.isNode&&r["timeout"]){o=l(r)}else{o=i(r)}}catch(e){return Promise.reject(e)}Array.prototype.unshift.apply(h,a);while(h.length){o=o.then(h.shift(),h.shift())}return o}function l(n){try{const e=new Promise((e,t)=>{setTimeout(()=>{let e={message:`timeout of ${n["timeout"]}ms exceeded`,config:n};t(e)},n["timeout"])});return Promise.race([i(n),e])}catch(e){c.error(`Request Timeout exception: ${e}`)}}};return{request:s,interceptors:o,modifyHeaders:i,modifyResponse:p,get:e=>{return s("GET",e)},post:e=>{return s("POST",e)},put:e=>{return s("PUT",e)},patch:e=>{return s("PATCH",e)},delete:e=>{return s("DELETE",e)},head:e=>{return s("HEAD",e)},options:e=>{return s("OPTIONS",e)}}}function MagicNotification(o,s,a,l){let u=null;let c=null;const e=t=>{try{let e=t.replace(/\/+$/g,"");u=`${/^https?:\/\/([^/]*)/.exec(e)[0]}/push`;c=/\/([^\/]+)\/?$/.exec(e)[1]}catch(e){a.error(`Bark url error: ${e}.`)}};function t(e=o,t="",n="",r=""){const i=n=>{try{let t={};if(typeof n==="string"){if(s.isLoon)t={openUrl:n};else if(s.isQuanX)t={"open-url":n};else if(s.isSurge)t={url:n}}else if(typeof n==="object"){if(s.isLoon){t["openUrl"]=!!n["open-url"]?n["open-url"]:"";t["mediaUrl"]=!!n["media-url"]?n["media-url"]:""}else if(s.isQuanX){t=!!n["open-url"]||!!n["media-url"]?n:{}}else if(s.isSurge){let e=n["open-url"]||n["openUrl"];t=e?{url:e}:{}}}return t}catch(e){a.error(`Failed to convert notification option, ${e}`)}return n};r=i(r);if(arguments.length==1){e=o;t="",n=arguments[0]}a.notify(`title:${e}\nsubTitle:${t}\nbody:${n}\noptions:${typeof r==="object"?JSON.stringify(r):r}`);if(s.isSurge){$notification.post(e,t,n,r)}else if(s.isLoon){if(!!r)$notification.post(e,t,n,r);else $notification.post(e,t,n)}else if(s.isQuanX){$notify(e,t,n,r)}if(u&&c){f(e,t,n)}}function n(e=o,t="",n="",r=""){if(a.level==="DEBUG"){if(arguments.length==1){e=o;t="",n=arguments[0]}this.notify(e,t,n,r)}}function f(e=o,t="",n="",r=""){if(typeof l==="undefined"||typeof l.post==="undefined"){throw"Bark notification needs to import MagicHttp module."}let i={url:u,headers:{"Content-Type":"application/json; charset=utf-8"},body:{title:e,body:t?`${t}\n${n}`:n,device_key:c}};l.post(i).catch(e=>{a.error(`Bark notify error: ${e}`)})}return{post:t,debug:n,bark:f,setBark:e}}function MagicData(s,a){let l={fs:undefined,data:{}};if(s.isNode){l.fs=require("fs");try{l.fs.accessSync("./magic.json",l.fs.constants.R_OK|l.fs.constants.W_OK)}catch(e){l.fs.writeFileSync("./magic.json","{}",{encoding:"utf8"})}l.data=require("./magic.json")}const u=(e,t)=>{if(typeof t==="object"){return false}else{return e===t}};const c=e=>{if(e==="true"){return true}else if(e==="false"){return false}else if(typeof e==="undefined"){return null}else{return e}};const f=(e,t,n,r)=>{if(n){try{if(typeof e==="string")e=JSON.parse(e);if(e["magic_session"]===true){e=e[n]}else{e=null}}catch{e=null}}if(typeof e==="string"&&e!=="null"){try{e=JSON.parse(e)}catch{}}if(r===false&&!!e&&e["magic_session"]===true){e=null}if((e===null||typeof e==="undefined")&&t!==null&&typeof t!=="undefined"){e=t}e=c(e);return e};const o=t=>{if(typeof t==="string"){let e={};try{e=JSON.parse(t);const n=typeof e;if(n!=="object"||e instanceof Array||n==="bool"||e===null){e={}}}catch{}return e}else if(t instanceof Array||t===null||typeof t==="undefined"||t!==t||typeof t==="boolean"){return{}}else{return t}};const d=(e,t=null,n="",r=false,i=null)=>{let o=i||l.data;if(!!o&&typeof o[e]!=="undefined"&&o[e]!==null){val=o[e]}else{val=!!n?{}:null}val=f(val,t,n,r);return val};const p=(e,t=null,n="",r=false,i=null)=>{let o="";if(i||s.isNode){o=d(e,t,n,r,i)}else{if(s.isSurgeLike){o=$persistentStore.read(e)}else if(s.isQuanX){o=$prefs.valueForKey(e)}o=f(o,t,n,r)}a.debug(`READ DATA [${e}]${!!n?`[${n}]`:""} <${typeof o}>\n${JSON.stringify(o)}`);return o};const g=(t,n,r="",e=null)=>{let i=e||l.data;i=o(i);if(!!r){let e=o(i[t]);e["magic_session"]=true;e[r]=n;i[t]=e}else{i[t]=n}if(e!==null){e=i}return i};const y=(e,t,n="",r=null)=>{if(typeof t==="undefined"||t!==t){return false}if(!s.isNode&&(typeof t==="boolean"||typeof t==="number")){t=String(t)}let i="";if(r||s.isNode){i=g(e,t,n,r)}else{if(!n){i=t}else{if(s.isSurgeLike){i=!!$persistentStore.read(e)?$persistentStore.read(e):i}else if(s.isQuanX){i=!!$prefs.valueForKey(e)?$prefs.valueForKey(e):i}i=o(i);i["magic_session"]=true;i[n]=t}}if(!!i&&typeof i==="object"){i=JSON.stringify(i,"","\t")}a.debug(`WRITE DATA [${e}]${n?`[${n}]`:""} <${typeof t}>\n${JSON.stringify(t)}`);if(!r){if(s.isSurgeLike){return $persistentStore.write(i,e)}else if(s.isQuanX){return $prefs.setValueForKey(i,e)}else if(s.isNode){try{l.fs.writeFileSync("./magic.json",i);return true}catch(e){a.error(e);return false}}}return true};const e=(t,n,r,i=u,o=null)=>{n=c(n);const e=p(t,null,r,false,o);if(i(e,n)===true){return false}else{const s=y(t,n,r,o);let e=p(t,null,r,false,o);if(i===u&&typeof e==="object"){return s}return i(n,e)}};const h=(e,t,n)=>{let r=n||l.data;r=o(r);if(!!t){obj=o(r[e]);delete obj[t];r[e]=obj}else{delete r[e]}if(!!n){n=r}return r};const t=(e,t="",n=null)=>{let r={};if(n||s.isNode){r=h(e,t,n);if(!n){l.fs.writeFileSync("./magic.json",JSON.stringify(r))}else{n=r}}else{if(!t){if(s.isStorm){return $persistentStore.remove(e)}else if(s.isSurgeLike){return $persistentStore.write(null,e)}else if(s.isQuanX){return $prefs.removeValueForKey(e)}}else{if(s.isSurgeLike){r=$persistentStore.read(e)}else if(s.isQuanX){r=$prefs.valueForKey(e)}r=o(r);delete r[t];const i=JSON.stringify(r);y(e,i)}}a.debug(`DELETE KEY [${e}]${!!t?`[${t}]`:""}`)};const n=(e,t=null)=>{let n=[];let r=p(e,null,null,true,t);r=o(r);if(r["magic_session"]!==true){n=[]}else{n=Object.keys(r).filter(e=>e!=="magic_session")}a.debug(`READ ALL SESSIONS [${e}] <${typeof n}>\n${JSON.stringify(n)}`);return n};return{read:p,write:y,del:t,update:e,allSessions:n,defaultValueComparator:u,convertToObject:o}}function MagicUtils(r,u){const e=(o,s=5,a=0,l=null)=>{return(...e)=>{return new Promise((n,r)=>{function i(...t){Promise.resolve().then(()=>o.apply(this,t)).then(e=>{if(typeof l==="function"){Promise.resolve().then(()=>l(e)).then(()=>{n(e)}).catch(e=>{if(s>=1){if(a>0)setTimeout(()=>i.apply(this,t),a);else i.apply(this,t)}else{r(e)}s--})}else{n(e)}}).catch(e=>{u.error(e);if(s>=1&&a>0){setTimeout(()=>i.apply(this,t),a)}else if(s>=1){i.apply(this,t)}else{r(e)}s--})}i.apply(this,e)})}};const t=(e,t="yyyy-MM-dd hh:mm:ss")=>{let n={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};if(/(y+)/.test(t))t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length));for(let e in n)if(new RegExp("("+e+")").test(t))t=t.replace(RegExp.$1,RegExp.$1.length==1?n[e]:("00"+n[e]).substr((""+n[e]).length));return t};const n=()=>{return t(new Date,"yyyy-MM-dd hh:mm:ss")};const i=()=>{return t(new Date,"yyyy-MM-dd")};const o=t=>{return new Promise(e=>setTimeout(e,t))};const s=(e,t=null)=>{if(r.isNode){const n=require("assert");if(t)n(e,t);else n(e)}else{if(e!==true){let e=`AssertionError: ${t||"The expression evaluated to a falsy value"}`;u.error(e)}}};return{retry:e,formatTime:t,now:n,today:i,sleep:o,assert:s}}function MagicQingLong(e,l,i){let o="";let s="";let a="";let u="";let c="";let t="";const f="magic.json";const n=3e3;const d=MagicHttp(e,i);const r=(e,t,n,r,i)=>{o=e;a=t;u=n;s=r;c=i};function p(e){o=o||l.read("magic_qlurl");t=t||l.read("magic_qltoken");return e}function g(e){if(!o){o=l.read("magic_qlurl")}if(e.url.indexOf(o)<0){e.url=`${o}${e.url}`}return{...e,timeout:n}}function y(e){e.params={...e.params,t:Date.now()};return e}function h(e){t=t||l.read("magic_qltoken");if(t){e.headers["Authorization"]=`Bearer ${t}`}return e}function m(e){a=a||l.read("magic_qlclient");if(!!a){e.url=e.url.replace("/api/","/open/")}return e}async function $(e){try{const t=e.message||e.error||JSON.stringify(e);if((t.indexOf("NSURLErrorDomain")>=0&&t.indexOf("-1012")>=0||!!e.response&&e.response.status===401)&&(!!e.config&&e.config.refreshToken!==true)){i.warning(`Qinglong panel token has expired`);await b();e.config["refreshToken"]=true;return await d.request(e.config.method,e.config)}else{return Promise.reject(e)}}catch(e){return Promise.reject(e)}}d.interceptors.request.use(p,undefined);d.interceptors.request.use(g,undefined);d.interceptors.request.use(m,undefined,{runWhen:e=>{return e.url.indexOf("api/user/login")<0&&e.url.indexOf("open/auth/token")<0}});d.interceptors.request.use(h,undefined,{runWhen:e=>{return e.url.indexOf("api/user/login")<0&&e.url.indexOf("open/auth/token")<0}});d.interceptors.request.use(y,undefined,{runWhen:e=>{return e.url.indexOf("open/auth/token")<0&&e.url.indexOf("t=")<0}});d.interceptors.response.use(undefined,$);async function b(){a=a||l.read("magic_qlclient");u=u||l.read("magic_qlsecrt");s=s||l.read("magic_qlname");c=c||l.read("magic_qlpwd");if(o&&a&&u){await d.get({url:`/open/auth/token`,headers:{"Content-Type":"application/json"},params:{client_id:a,client_secret:u}}).then(e=>{i.info("Log in to Qinglong panel successfully");t=e.body.data.token;l.update("magic_qltoken",t);return t}).catch(e=>{i.error(`Failed to log in to Qinglong panel.\n${e.message}`)})}else if(o&&s&&c){await d.post({url:`/api/user/login`,headers:{"Content-Type":"application/json"},body:{username:s,password:c}}).then(e=>{i.info("Log in to Qinglong panel successfully");t=e.body.data.token;l.update("magic_qltoken",t);return t}).catch(e=>{i.error(`Failed to log in to Qinglong panel.\n${e.message}`)})}}async function S(t,n,r=null){o=o||l.read("magic_qlurl");if(r===null){let e=await N([{name:t,value:n}]);if(!!e&&e.length===1){return e[0]}}else{d.put({url:`/api/envs`,headers:{"Content-Type":"application/json"},body:{name:t,value:n,id:r}}).then(e=>{if(e.body.code===200){i.debug(`QINGLONG UPDATE ENV ${t} <${typeof n}> (${r})\n${JSON.stringify(n)}`);return true}else{i.error(`Failed to update Qinglong panel environment variable.\n${JSON.stringify(e)}`)}}).catch(e=>{i.error(`Failed to update Qinglong panel environment variable.\n${e.message}`);return false})}}async function N(e){let t=[];await d.post({url:`/api/envs`,headers:{"Content-Type":"application/json"},body:e}).then(e=>{if(e.body.code===200){e.body.data.forEach(e=>{i.debug(`QINGLONG ADD ENV ${e.name} <${typeof e.value}> (${e.id})\n${JSON.stringify(e)}`);t.push(e.id)})}else{i.error(`Failed to add Qinglong panel environment variable.\n${JSON.stringify(e)}`)}}).catch(e=>{i.error(`Failed to add Qinglong panel environment variable.\n${e.message}`)});return t}async function v(t){return await d.delete({url:`/api/envs`,headers:{Accept:"application/json","Accept-Language":"zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",Connection:"keep-alive","Content-Type":"application/json;charset=UTF-8","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.30"},body:t}).then(e=>{if(e.body.code===200){i.debug(`QINGLONG DELETE ENV IDS: ${t}`);return true}else{i.error(`Failed to delete QingLong envs.\n${JSON.stringify(e)}`);return false}}).catch(e=>{i.error(`Failed to delete QingLong envs.\n${e.message}`)})}async function O(n=null,e=""){let r=[];await d.get({url:`/api/envs`,headers:{"Content-Type":"application/json"},params:{searchValue:e}}).then(e=>{if(e.body.code===200){const t=e.body.data;if(!!n){let e=[];for(const e of t){if(e.name===n){r.push(e)}}r=e}r=t}else{i.error(`Failed to get environment variables from Qinglong panel.\n${JSON.stringify(e)}`)}}).catch(e=>{i.error(`Failed to get environment variables from Qinglong panel.\n${JSON.stringify(e)}`)});return r}async function E(e){let t=null;const n=await O();for(const r of n){if(r.id===e){t=r;break}}return t}async function T(t){let n=false;await d.put({url:`/api/envs/disable`,headers:{Accept:"application/json","Accept-Language":"zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",Connection:"keep-alive","Content-Type":"application/json;charset=UTF-8","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.30"},body:t}).then(e=>{if(e.body.code===200){i.debug(`QINGLONG DISABLED ENV IDS: ${t}`);n=true}else{i.error(`Failed to disable QingLong envs.\n${JSON.stringify(e)}`)}}).catch(e=>{i.error(`Failed to disable QingLong envs.\n${e.message}`)});return n}async function w(t){let n=false;await d.put({url:`/api/envs/enable`,headers:{Accept:"application/json","Accept-Language":"zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",Connection:"keep-alive","Content-Type":"application/json;charset=UTF-8","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.30"},body:t}).then(e=>{if(e.body.code===200){i.debug(`QINGLONG ENABLED ENV IDS: ${t}`);n=true}else{i.error(`Failed to enable QingLong envs.\n${JSON.stringify(e)}`)}}).catch(e=>{i.error(`Failed to enable QingLong envs.\n${e.message}`)});return n}async function C(e,t="",n=""){let r=false;await d.post({url:`/api/scripts`,headers:{"Content-Type":"application/json"},body:{filename:e,path:t,content:n}}).then(e=>{if(e.body.code===200){r=true}else{i.error(`Failed to add script content from Qinglong panel.\n${JSON.stringify(e)}`)}}).catch(e=>{i.error(`Failed to add script content from Qinglong panel.\n${e.message}`)});return r}async function A(e,t=""){let n="";await d.get({url:`/api/scripts/${e}`,params:{path:t}}).then(e=>{if(e.body.code===200){n=e.body.data}else{i.error(`Failed to read script content from Qinglong panel.\n${JSON.stringify(e)}`)}}).catch(e=>{i.error(`Failed to read script content from Qinglong panel.\n${e.message}`)});return n}async function k(e,t="",n=""){let r=false;await d.put({url:`/api/scripts`,headers:{"Content-Type":"application/json"},body:{filename:e,path:t,content:n}}).then(e=>{if(e.body.code===200){r=true}else{i.error(`Failed to read script content from Qinglong panel.\n${JSON.stringify(e)}`)}}).catch(e=>{i.error(`Failed to read script content from Qinglong panel.\n${e.message}`)});return r}async function L(e,t=""){let n=false;await d.delete({url:`/api/scripts`,headers:{"Content-Type":"application/json"},body:{filename:e,path:t}}).then(e=>{if(e.body.code===200){n=true}else{i.error(`Failed to read script content from Qinglong panel.\n${JSON.stringify(e)}`)}}).catch(e=>{i.error(`Failed to read script content from Qinglong panel.\n${e.message}`)});return n}async function F(e,t,n=""){let r=await A(f,"");let i=l.convertToObject(r);let o=l.write(e,t,n,i);r=JSON.stringify(i,"","\t");let s=await k(f,"",r);return s&&o}async function j(e,t,n,r=l.defaultValueComparator){let i=await A(f,"");let o=l.convertToObject(i);const s=l.update(e,t,n,r,o);let a=false;if(s===true){i=JSON.stringify(o,"","\t");a=await k(f,"",i)}return s&&a}async function M(e,t,n=""){let r=await A(f,"");let i=l.convertToObject(r);const o=l.read(e,t,n,false,i);return o}async function R(e,t=""){let n=await A(f,"");let r=l.convertToObject(n);const i=l.del(e,t,r);n=JSON.stringify(r,"","\t");const o=await k(f,"",n);return i&&o}async function q(e){let t=await A(f,"");let n=l.convertToObject(t);const r=l.allSessions(e,n);return r}return{init:r,getToken:b,setEnv:S,setEnvs:N,getEnv:E,getEnvs:O,delEnvs:v,disableEnvs:T,enbleEnvs:w,addScript:C,getScript:A,editScript:k,delScript:L,write:F,read:M,del:R,update:j,allSessions:q}} \ No newline at end of file diff --git a/script/smzdm/smzdm_daily.lnplugin b/script/smzdm/smzdm_daily.lnplugin new file mode 100644 index 000000000..a74af2eec --- /dev/null +++ b/script/smzdm/smzdm_daily.lnplugin @@ -0,0 +1,13 @@ +#!name= 什么值得买 +#!desc= 什么值得买每日签到、抽奖与任务 +#!openUrl=https://github.com/blackmatrix7/ios_rule_script/tree/master/script/smzdm +#!author= blackmatrix7 +#!homepage= https://github.com/blackmatrix7/ios_rule_script +#!icon= https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm.png + +[Script] +http-request ^https?:\/\/zhiyou\.smzdm\.com\/user$ script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_daily.js,tag=什么值得买_获取Cookie +cron "30 9 * * *" script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_daily.js,timeout=60,tag=什么值得买_每日签到 + +[MITM] +hostname = zhiyou.smzdm.com \ No newline at end of file diff --git a/script/smzdm/smzdm_daily.qxrewrite b/script/smzdm/smzdm_daily.qxrewrite new file mode 100644 index 000000000..7a5cec23a --- /dev/null +++ b/script/smzdm/smzdm_daily.qxrewrite @@ -0,0 +1,6 @@ +# 什么值得买每日自动签到 + +^https?:\/\/zhiyou\.smzdm\.com\/user$ url script-request-header https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_daily.js +# ^https?:\/\/user-api\.smzdm\.com\/user_login\/normal$ url script-request-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_daily.js + +hostname = zhiyou.smzdm.com \ No newline at end of file diff --git a/script/smzdm/smzdm_signin.sgmodule b/script/smzdm/smzdm_daily.sgmodule similarity index 71% rename from script/smzdm/smzdm_signin.sgmodule rename to script/smzdm/smzdm_daily.sgmodule index 8d7e25a2f..d1de039b6 100644 --- a/script/smzdm/smzdm_signin.sgmodule +++ b/script/smzdm/smzdm_daily.sgmodule @@ -3,8 +3,8 @@ #!system=ios [Script] -什么值得买_每日签到 = script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.js,timeout=120,type=cron,cronexp=5 0 * * * -什么值得买_获取cookie = script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.js,type=http-request,requires-body=true,pattern=^https?:\/\/zhiyou\.smzdm\.com\/user$ +什么值得买_每日签到 = script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_daily.js,timeout=120,type=cron,cronexp=5 0 * * * +什么值得买_获取cookie = script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_daily.js,type=http-request,requires-body=false,pattern=^https?:\/\/zhiyou\.smzdm\.com\/user$ [MITM] hostname = %APPEND% zhiyou.smzdm.com \ No newline at end of file diff --git a/script/smzdm/smzdm_mission.js b/script/smzdm/smzdm_mission.js deleted file mode 100644 index f39c90a9e..000000000 --- a/script/smzdm/smzdm_mission.js +++ /dev/null @@ -1,571 +0,0 @@ -const smzdmCookieKey = "smzdm_cookie"; -const scriptName = "什么值得买"; -let clickGoBuyMaxTimes = 0; // 好价点击去购买的次数 -let clickLikeProductMaxTimes = 0; // 好价点值次数 -let clickLikeArticleMaxTimes = 0; // 好文点赞次数 -let clickFavArticleMaxTimes = 7; // 好文收藏次数 - -let magicJS = MagicJS(scriptName, "INFO"); -magicJS.barkUrl = magicJS.read("smzdm_unified_push_url") || magicJS.read("magicjs_unified_push_url"); - -// 获取点击去购买和点值的链接 -function GetProductList() { - return new Promise((resolve, reject) => { - let getGoBuyOptions = { - url: "https://faxian.smzdm.com/", - headers: { - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", - "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", - "Cache-Control": "max-age=0", - "Connection": "keep-alive", - "Host": "www.smzdm.com", - "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Edg/84.0.522.52", - }, - body: "", - }; - magicJS.get(getGoBuyOptions, (err, resp, data) => { - if (err) { - reject(err); - } else { - // 获取每日去购买的链接 - let goBuyList = data.match(/https?:\/\/go\.smzdm\.com\/[0-9a-zA-Z]*\/[^"']*_0/gi); - if (!!goBuyList) { - // 去除重复的商品链接 - let goBuyDict = {}; - goBuyList.forEach((element) => { - let productCode = element.match(/https?:\/\/go\.smzdm\.com\/[0-9a-zA-Z]*\/([^"']*_0)/)[1]; - goBuyDict[productCode] = element; - }); - goBuyList = Object.values(goBuyDict); - magicJS.logDebug(`当前获取的每日去购买链接: ${JSON.stringify(goBuyList)}`); - } else { - goBuyList = []; - } - - // 获取每日点值的链接 - let productUrlList = data.match(/https?:\/\/www\.smzdm\.com\/p\/[0-9]*/gi); - let likeProductList = []; - if (!!productUrlList) { - productUrlList.forEach((element) => { - likeProductList.push(element.match(/https?:\/\/www\.smzdm\.com\/p\/([0-9]*)/)[1]); - }); - } - resolve([goBuyList, likeProductList]); - } - }); - }); -} - -// 获取点赞和收藏的好文Id -function GetDataArticleIdList() { - return new Promise((resolve, reject) => { - let getArticleOptions = { - url: "https://post.smzdm.com/", - headers: { - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", - "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", - "Host": "post.smzdm.com", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.41", - }, - body: "", - }; - magicJS.get(getArticleOptions, (err, resp, data) => { - if (err) { - magicJS.logWarning(`获取好文列表失败,请求异常:${err}`); - reject("GetArticleListErr"); - } else { - try { - let articleList = data.match(/data-article=".*" data-type="zan"/gi); - let result = []; - articleList.forEach((element) => { - result.push(element.match(/data-article="(.*)" data-type="zan"/)[1]); - }); - resolve(result); - } catch (err) { - magicJS.logWarning(`获取好文列表失败,执行异常:${err}`); - reject("GetArticleListErr"); - } - } - }); - }); -} - -// 点击去购买 -function ClickGoBuyButton(cookie, url) { - return new Promise((resolve) => { - let clickGoBuyOptions = { - url: url, - headers: { - Cookie: cookie, - }, - }; - magicJS.get(clickGoBuyOptions, (err, resp, data) => { - resolve(); - }); - }); -} - -// 好价点值 -function ClickLikeProduct(cookie, articleId) { - return new Promise((resolve) => { - let ClickLikeProductOptions = { - url: "https://zhiyou.smzdm.com/user/rating/ajax_add", - headers: { - "Accept": "application/json, text/javascript, */*; q=0.01", - "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", - "Host": "zhiyou.smzdm.com", - "Origin": "https://faxian.smzdm.com", - "Referer": "https://faxian.smzdm.com/", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.41", - "Cookie": cookie, - }, - body: `article_id=${articleId}&channel_id=3&rating=1&client_type=PC&event_key=%E7%82%B9%E5%80%BC&otype=%E5%80%BC&aid=${articleId}&p=16&cid=2&source=%E6%97%A0&atp=3&tagID=%E6%97%A0&sourcePage=https%3A%2F%2Ffaxian.smzdm.com%2F&sourceMode=%E6%97%A0`, - }; - magicJS.post(ClickLikeProductOptions, (err, resp, data) => { - if (err) { - magicJS.logWarning(`好价${articleId}点值失败,请求异常:${articleId}`); - resolve(false); - } else { - try { - let obj = JSON.parse(data); - if (obj.error_code == 0) { - magicJS.logDebug(`好价${articleId}点值成功`); - resolve(true); - } else if (obj.error_code == 1) { - magicJS.logDebug(`好价${articleId}点值重复点值`); - resolve(true); - } else { - magicJS.logWarning(`好价${articleId}点值失败,接口响应异常:${data}`); - resolve(false); - } - } catch (err) { - magicJS.logWarning(`好价${articleId}点值失败,执行异常:${articleId}`); - resolve(false); - } - } - }); - }); -} - -// 好文点赞 -function ClickLikeArticle(cookie, articleId) { - return new Promise((resolve) => { - let ClickLikeProductOptions = { - url: "https://zhiyou.smzdm.com/user/rating/ajax_add", - headers: { - "Accept": "application/json, text/javascript, */*; q=0.01", - "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", - "Host": "zhiyou.smzdm.com", - "Origin": "https://post.smzdm.com", - "Referer": "https://post.smzdm.com/", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.41", - "Cookie": cookie, - }, - body: `article_id=${articleId}&channel_id=11&rating=1&client_type=PC&event_key=%E7%82%B9%E5%80%BC&otype=%E7%82%B9%E8%B5%9E&aid=${articleId}&p=2&cid=11&source=%E6%97%A0&atp=76&tagID=%E6%97%A0&sourcePage=https%3A%2F%2Fpost.smzdm.com%2F&sourceMode=%E6%97%A0`, - }; - magicJS.post(ClickLikeProductOptions, (err, resp, data) => { - if (err) { - magicJS.logWarning(`好文${articleId}点赞失败,请求异常:${articleId}`); - resolve(false); - } else { - try { - let obj = JSON.parse(data); - if (obj.error_code == 0) { - magicJS.logDebug(`好文${articleId}点赞成功`); - resolve(true); - } else if (obj.error_code == 1 && obj.error_msg == "已喜欢") { - magicJS.logDebug(`好文${articleId}点赞失败,重复点值。`); - resolve(false); - } else { - magicJS.logWarning(`好文${articleId}点赞失败,接口响应异常:${data}`); - resolve(false); - } - } catch (err) { - magicJS.logWarning(`好文${articleId}点赞失败,请求异常:${err}`); - resolve(false); - } - } - }); - }); -} - -// 好文收藏/取消收藏 -function ClickFavArticle(cookie, articleId) { - return new Promise((resolve) => { - let options = { - url: "https://zhiyou.smzdm.com/user/favorites/ajax_favorite", - headers: { - "Accept": "application/json, text/javascript, */*; q=0.01", - "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", - "Host": "zhiyou.smzdm.com", - "Origin": "https://post.smzdm.com", - "Referer": "https://post.smzdm.com/", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.41", - "Cookie": cookie, - }, - body: `article_id=${articleId}&channel_id=11&client_type=PC&event_key=%E6%94%B6%E8%97%8F&otype=%E6%94%B6%E8%97%8F&aid=${articleId}&cid=11&p=2&source=%E6%97%A0&atp=76&tagID=%E6%97%A0&sourcePage=https%3A%2F%2Fpost.smzdm.com%2F&sourceMode=%E6%97%A0`, - }; - magicJS.post(options, (err, resp, data) => { - if (err) { - magicJS.logWarning(`好文${articleId}收藏失败,请求异常:${articleId}`); - resolve(false); - } else { - try { - let obj = JSON.parse(data); - if (obj.error_code == 0) { - magicJS.logDebug(`好文${articleId}收藏成功`); - resolve(true); - } else if (obj.error_code == 2) { - magicJS.logDebug(`好文${articleId}取消收藏成功`); - resolve(true); - } else { - magicJS.logWarning(`好文${articleId}收藏失败,接口响应异常:${data}`); - resolve(false); - } - } catch (err) { - magicJS.logWarning(`好文${articleId}收藏失败,请求异常:${err}`); - resolve(false); - } - } - }); - }); -} - -// 获取每日抽奖active_id -function GetLotteryActiveId(cookie) { - return new Promise((resolve) => { - let options = { - url: "https://m.smzdm.com/zhuanti/life/choujiang/", - headers: { - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", - "Accept-Encoding": "gzip, deflate, br", - "Accept-Language": "zh-cn", - "Connection": "keep-alive", - "Cookie": cookie, - "Host": "m.smzdm.com", - "User-Agent": - "Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148/smzdm 9.9.6 rv:93.4 (iPhone13,4; iOS 14.5; zh_CN)/iphone_smzdmapp/9.9.6/wkwebview/jsbv_1.0.0", - }, - }; - magicJS.get(options, (err, resp, data) => { - if (err) { - magicJS.logWarning(`获取每日抽奖Id失败,请求异常:${err}`); - resolve("获取每日抽奖Id失败,请求异常"); - } else { - try { - let activeId = /name\s?=\s?\"lottery_activity_id\"\s+value\s?=\s?\"([a-zA-Z0-9]*)\"/.exec(data); - if (activeId) { - resolve(activeId[1]); - } else { - magicJS.logWarning(`获取每日抽奖activeId失败`); - resolve(""); - } - } catch (err) { - magicJS.logWarning(`获取每日抽奖activeId失败,请求异常:${err}`); - resolve(""); - } - } - }); - }); -} - -// 每日抽奖 -function LotteryDraw(cookie, activeId) { - return new Promise((resolve) => { - let options = { - url: `https://zhiyou.smzdm.com/user/lottery/jsonp_draw?callback=jQuery34109305207178886287_${new Date().getTime()}&active_id=${activeId}&_=${new Date().getTime()}`, - headers: { - "Accept": "*/*", - "Accept-Encoding": "gzip, deflate, br", - "Accept-Language": "zh-cn", - "Connection": "keep-alive", - "Cookie": cookie, - "Host": "zhiyou.smzdm.com", - "Referer": "https://m.smzdm.com/zhuanti/life/choujiang/", - "User-Agent": - "Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148/smzdm 9.9.0 rv:91 (iPhone 11 Pro Max; iOS 14.2; zh_CN)/iphone_smzdmapp/9.9.0/wkwebview/jsbv_1.0.0", - }, - }; - magicJS.get(options, (err, resp, data) => { - if (err) { - magicJS.logWarning(`每日抽奖失败,请求异常:${err}`); - resolve("每日抽奖失败,请求异常"); - } else { - try { - let newData = /\((.*)\)/.exec(data); - let obj = JSON.parse(newData[1]); - if (obj.error_code === 0 || obj.error_code === 1 || obj.error_code === 4) { - magicJS.logInfo(`每日抽奖结果:${obj.error_msg}`); - resolve(obj.error_msg); - } else { - magicJS.logWarning(`每日抽奖失败,接口响应异常:${data}`); - resolve("每日抽奖失败,接口响应异常"); - } - } catch (err) { - magicJS.logWarning(`每日抽奖失败,请求异常:${err}`); - resolve("每日抽奖失败,请求异常"); - } - } - }); - }); -} - -// 获取用户信息,新版 -function WebGetCurrentInfoNewVersion(smzdmCookie) { - return new Promise((resolve) => { - let options = { - url: "https://zhiyou.smzdm.com/user/exp/", - headers: { - Cookie: smzdmCookie, - }, - body: "", - }; - magicJS.get(options, (err, resp, data) => { - if (err) { - magicJS.logError(`获取用户信息失败,异常信息:${err}`); - resolve([null, null, null, null, null, null, null]); - } else { - try { - // 获取用户名 - let userName = data.match(/info-stuff-nickname.*zhiyou\.smzdm\.com\/user[^<]*>([^<]*)(.*)<\/div>/gi); - let pointDetailList = data.match(/
(.*)<\/div>/gi); - let minLength = pointTimeList.length > pointDetailList.length ? pointDetailList.length : pointTimeList.length; - let userPointList = []; - for (let i = 0; i < minLength; i++) { - userPointList.push({ - time: pointTimeList[i].match(/\
(.*)\<\/div\>/)[1], - detail: pointDetailList[i].match(/\
(.*)\<\/div\>/)[1], - }); - } - // 获取用户资源 - let assetsNumList = data.match(/assets-part[^<]*>(.*)(.*)(.*)(.*)(.*)(.*) { - let webGetCurrentInfo = { - url: `https://zhiyou.smzdm.com/user/info/jsonp_get_current?with_avatar_ornament=1&callback=jQuery112403507528653716241_${new Date().getTime()}&_=${new Date().getTime()}`, - headers: { - "Accept": "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01", - "Accept-Language": "zh-CN,zh;q=0.9", - "Connection": "keep-alive", - "DNT": "1", - "Host": "zhiyou.smzdm.com", - "Referer": "https://zhiyou.smzdm.com/user/", - "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36", - "Cookie": smzdmCookie, - }, - }; - magicJS.get(webGetCurrentInfo, (err, resp, data) => { - try { - let obj = JSON.parse(/\((.*)\)/.exec(data)[1]); - if (obj["smzdm_id"] !== 0) { - resolve([ - obj["nickname"], // 昵称 - `https:${obj["avatar"]}`, // 头像 - obj["vip_level"], // 新版VIP等级 - obj["checkin"]["has_checkin"], //是否签到 - Number(obj["checkin"]["daily_checkin_num"]), //连续签到天数 - Number(obj["unread"]["notice"]["num"]), // 未读消息 - Number(obj["level"]), // 旧版等级 - Number(obj["exp"]), // 旧版经验 - Number(obj["point"]), // 积分 - Number(obj["gold"]), // 金币 - Number(obj["silver"]), // 碎银子 - ]); - } else { - magicJS.logWarning(`获取用户信息异常,Cookie过期或接口变化:${data}`); - resolve([null, null, null, null, null, false, null, null]); - } - } catch (err) { - magicJS.logError(`获取用户信息异常,代码执行异常:${err},接口返回数据:${data}`); - resolve([null, null, null, null, null, false, null, null]); - } - }); - }); -} - -(async () => { - // 通知信息 - let title = ""; - let subTitle = ""; - let content = ""; - // 获取Cookie - let smzdmCookie = magicJS.read(smzdmCookieKey); - - if (!!smzdmCookie === false) { - magicJS.logWarning("没有读取到什么值得买有效cookie,请访问zhiyou.smzdm.com进行登录"); - magicJS.notify(scriptName, "", "❓没有获取到Web端Cookie,请先进行登录。"); - } else { - try { - // 任务完成情况 - let clickGoBuyTimes = 0; - let clickLikePrductTimes = 0; - let clickLikeArticleTimes = 0; - let clickFavArticleTimes = 0; - - // 查询签到前用户数据 - let [nickName, avatar, beforeVIPLevel, beforeHasCheckin, , beforeNotice, , , beforePoint, beforeGold, beforeSilver] = await WebGetCurrentInfo(smzdmCookie); - if (!nickName) { - magicJS.notify(scriptName, "", "❌Cookie过期或接口变化,请尝试重新登录"); - magicJS.done(); - } else { - let [, , , beforeExp, , beforePrestige] = await WebGetCurrentInfoNewVersion(smzdmCookie); - magicJS.logInfo( - `昵称:${nickName}\nWeb端签到状态:${beforeHasCheckin}\n签到前等级${beforeVIPLevel},积分${beforePoint},经验${beforeExp},金币${beforeGold},碎银子${beforeSilver}, 未读消息${beforeNotice}` - ); - - // 每日抽奖 - let activeId = await GetLotteryActiveId(smzdmCookie); - if (activeId) { - content = await LotteryDraw(smzdmCookie, activeId); - } - - // 获取去购买和好价Id列表 - let [, [goBuyList = [], likProductList = []]] = await magicJS.attempt(magicJS.retry(GetProductList, 5, 1000)(), [[], []]); - // 获取好文列表 - let [, articleList = []] = await magicJS.attempt(magicJS.retry(GetDataArticleIdList, 5, 1000)(), []); - - // 好价点击去购买,Web端点击已无奖励,放弃 - const clickGoBuyAsync = async () => { - let clickGoBuyList = goBuyList.splice(0, clickGoBuyMaxTimes); - if (clickGoBuyList.length > 0) { - for (let i = 0; i < clickGoBuyList.length; i++) { - await ClickGoBuyButton(smzdmCookie, clickGoBuyList[i]); - magicJS.logInfo(`完成第${i + 1}次“每日去购买”任务,点击链接:\n${clickGoBuyList[i]}`); - clickGoBuyTimes += 1; - await magicJS.sleep(3100); - } - } - }; - - // 好价点值 - const clickLikeProductAsync = async () => { - let clickLikeProductList = likProductList.splice(0, clickLikeProductMaxTimes); - if (clickLikeProductList.length > 0) { - for (let i = 0; i < clickLikeProductList.length; i++) { - await ClickLikeProduct(smzdmCookie, clickLikeProductList[i]); - magicJS.logInfo(`完成第${i + 1}次“好价点值”任务,好价Id:${clickLikeProductList[i]}`); - clickLikePrductTimes += 1; - await magicJS.sleep(3100); - } - } - }; - - // 好文点赞 - const clickLikeArticleAsync = async () => { - let likeArticleList = articleList.splice(0, clickLikeArticleMaxTimes); - if (likeArticleList.length > 0) { - for (let i = 0; i < likeArticleList.length; i++) { - await ClickLikeArticle(smzdmCookie, likeArticleList[i]); - magicJS.logInfo(`完成第${i + 1}次“好文点赞”任务,好文Id:${likeArticleList[i]}`); - clickLikeArticleTimes += 1; - await magicJS.sleep(3100); - } - } - }; - - // 好文收藏 - const clickFavArticleAsync = async () => { - let favArticleList = articleList.splice(0, clickFavArticleMaxTimes); - if (favArticleList.length > 0) { - // 好文收藏 - for (let i = 0; i < favArticleList.length; i++) { - await ClickFavArticle(smzdmCookie, articleList[i]); - magicJS.logInfo(`完成第${i + 1}次“好文收藏”任务,好文Id:${articleList[i]}`); - clickFavArticleTimes += 1; - await magicJS.sleep(3100); - } - // 取消收藏 - for (let i = 0; i < favArticleList.length; i++) { - await ClickFavArticle(smzdmCookie, articleList[i]); - magicJS.logInfo(`取消第${i + 1}次“好文收藏”任务的好文,好文Id:${articleList[i]}`); - await magicJS.sleep(3100); - } - } - }; - - await Promise.all([clickGoBuyAsync(), clickLikeProductAsync()]); - await Promise.all([clickLikeArticleAsync(), clickFavArticleAsync()]); - - // 查询签到后用户数据 - await magicJS.sleep(3000); - let [, , afterVIPLevel, afterHasCheckin, afterCheckinNum, afterNotice, , , afterPoint, afterGold, afterSilver] = await WebGetCurrentInfo(smzdmCookie); - let [, afteruserPointList, , afterExp, , afterPrestige] = await WebGetCurrentInfoNewVersion(smzdmCookie); - magicJS.logInfo( - `昵称:${nickName}\nWeb端签到状态:${afterHasCheckin}\n签到后等级${afterVIPLevel},积分${afterPoint},经验${afterExp},金币${afterGold},碎银子${afterSilver},未读消息${afterNotice}` - ); - - // 通知内容 - if (afterExp && beforeExp) { - let addPoint = afterPoint - beforePoint; - let addExp = afterExp - beforeExp; - let addGold = afterGold - beforeGold; - // let addPrestige = afterPrestige - beforePrestige; - let addSilver = afterSilver - beforeSilver; - content += !!content ? "\n" : ""; - content += - "积分" + - afterPoint + - (addPoint > 0 ? "(+" + addPoint + ")" : "") + - " 经验" + - afterExp + - (addExp > 0 ? "(+" + addExp + ")" : "") + - " 金币" + - afterGold + - (addGold > 0 ? "(+" + addGold + ")" : "") + - "\n" + - "碎银子" + - afterSilver + - (addSilver > 0 ? "(+" + addSilver + ")" : "") + - // ' 威望' + afterPrestige + (addPrestige > 0 ? '(+' + addPrestige + ')' : '') + - " 未读消息" + - afterNotice; - } - - content += `\n点值 ${clickLikePrductTimes}/${clickLikeProductMaxTimes} 去购买 ${clickGoBuyTimes}/${clickGoBuyMaxTimes}\n点赞 ${clickLikeArticleTimes}/${clickLikeArticleMaxTimes} 收藏 ${clickLikeArticleTimes}/${clickFavArticleTimes}`; - - content += !!content ? "\n" : ""; - if (afteruserPointList.length > 0) { - content += "用户近期经验变动情况(有延迟):"; - afteruserPointList.forEach((element) => { - content += `\n${element["time"]} ${element["detail"]}`; - }); - content += "\n如经验值无变动,请更新Cookie。"; - } else { - content += "没有获取到用户近期的经验变动情况"; - } - - title = `${scriptName} - ${nickName} V${afterVIPLevel}`; - magicJS.notify(title, subTitle, content, { "media-url": avatar }); - } - } catch (err) { - magicJS.logError(`执行任务出现异常:${err}`); - magicJS.notify(scriptName, "", "❌执行任务出现,请查阅日志"); - } - } - magicJS.done(); -})(); - -// prettier-ignore -function MagicJS(scriptName="MagicJS",logLevel="INFO"){return new class{constructor(){if(this.version="2.2.3.5",this.scriptName=scriptName,this.logLevels={DEBUG:5,INFO:4,NOTIFY:3,WARNING:2,ERROR:1,CRITICAL:0,NONE:-1},this.isLoon="undefined"!=typeof $loon,this.isQuanX="undefined"!=typeof $task,this.isJSBox="undefined"!=typeof $drive,this.isNode="undefined"!=typeof module&&!this.isJSBox,this.isSurge="undefined"!=typeof $httpClient&&!this.isLoon,this.node={request:void 0,fs:void 0,data:{}},this.iOSUserAgent="Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1",this.pcUserAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36 Edg/84.0.522.59",this.logLevel=logLevel,this._barkUrl="",this._barkKey="",this.isNode){this.node.fs=require("fs"),this.node.request=require("request");try{this.node.fs.accessSync("./magic.json",this.node.fs.constants.R_OK|this.node.fs.constants.W_OK)}catch(err){this.node.fs.writeFileSync("./magic.json","{}",{encoding:"utf8"})}this.node.data=require("./magic.json")}else this.isJSBox&&($file.exists("drive://MagicJS")||$file.mkdir("drive://MagicJS"),$file.exists("drive://MagicJS/magic.json")||$file.write({data:$data({string:"{}"}),path:"drive://MagicJS/magic.json"}))}set barkUrl(url){try{let _url=url.replace(/\/+$/g,"");this._barkUrl=`${/^https?:\/\/([^/]*)/.exec(_url)[0]}/push`,this._barkKey=/\/([^\/]+)\/?$/.exec(_url)[1]}catch(err){this.logDebug("读取Bark推送链接失败。")}}set logLevel(level){this._logLevel="string"==typeof level?level.toUpperCase():"DEBUG"}get logLevel(){return this._logLevel}get isRequest(){return"undefined"!=typeof $request&&"undefined"==typeof $response}get isResponse(){return"undefined"!=typeof $response}get request(){return"undefined"!=typeof $request?$request:void 0}get response(){return"undefined"!=typeof $response?($response.hasOwnProperty("status")&&($response.statusCode=$response.status),$response.hasOwnProperty("statusCode")&&($response.status=$response.statusCode),$response):void 0}get platform(){return this.isSurge?"Surge":this.isQuanX?"Quantumult X":this.isLoon?"Loon":this.isJSBox?"JSBox":this.isNode?"Node.js":"Unknown"}read(key,session=""){let val="";this.isSurge||this.isLoon?val=$persistentStore.read(key):this.isQuanX?val=$prefs.valueForKey(key):this.isNode?val=this.node.data:this.isJSBox&&(val=$file.read("drive://MagicJS/magic.json").string);try{this.isNode&&(val=val[key]),this.isJSBox&&(val=JSON.parse(val)[key]),session&&("string"==typeof val&&(val=JSON.parse(val)),val=val&&"object"==typeof val?val[session]:null)}catch(err){this.logError(err),val=session?{}:null,this.del(key)}void 0===val&&(val=null);try{val&&"string"==typeof val&&(val=JSON.parse(val))}catch(err){}return this.logDebug(`READ DATA [${key}]${session?`[${session}]`:""}(${typeof val})\n${JSON.stringify(val)}`),val}write(key,val,session=""){let data=session?{}:"";if(session&&(this.isSurge||this.isLoon)?data=$persistentStore.read(key):session&&this.isQuanX?data=$prefs.valueForKey(key):this.isNode?data=this.node.data:this.isJSBox&&(data=JSON.parse($file.read("drive://MagicJS/magic.json").string)),session){try{"string"==typeof data&&(data=JSON.parse(data)),data="object"==typeof data&&data?data:{}}catch(err){this.logError(err),this.del(key),data={}}this.isJSBox||this.isNode?(data[key]&&"object"==typeof data[key]||(data[key]={}),data[key].hasOwnProperty(session)||(data[key][session]=null),void 0===val?delete data[key][session]:data[key][session]=val):void 0===val?delete data[session]:data[session]=val}else this.isNode||this.isJSBox?void 0===val?delete data[key]:data[key]=val:data=void 0===val?null:val;"object"==typeof data&&(data=JSON.stringify(data)),this.isSurge||this.isLoon?$persistentStore.write(data,key):this.isQuanX?$prefs.setValueForKey(data,key):this.isNode?this.node.fs.writeFileSync("./magic.json",data):this.isJSBox&&$file.write({data:$data({string:data}),path:"drive://MagicJS/magic.json"}),this.logDebug(`WRITE DATA [${key}]${session?`[${session}]`:""}(${typeof val})\n${JSON.stringify(val)}`)}del(key,session=""){this.logDebug(`DELETE KEY [${key}]${session?`[${session}]`:""}`),this.write(key,null,session)}notify(title=this.scriptName,subTitle="",body="",opts=""){let convertOptions;if(opts=(_opts=>{let newOpts={};if("string"==typeof _opts)this.isLoon?newOpts={openUrl:_opts}:this.isQuanX?newOpts={"open-url":_opts}:this.isSurge&&(newOpts={url:_opts});else if("object"==typeof _opts)if(this.isLoon)newOpts.openUrl=_opts["open-url"]?_opts["open-url"]:"",newOpts.mediaUrl=_opts["media-url"]?_opts["media-url"]:"";else if(this.isQuanX)newOpts=_opts["open-url"]||_opts["media-url"]?_opts:{};else if(this.isSurge){let openUrl=_opts["open-url"]||_opts.openUrl;newOpts=openUrl?{url:openUrl}:{}}return newOpts})(opts),1==arguments.length&&(title=this.scriptName,subTitle="",body=arguments[0]),this.logNotify(`title:${title}\nsubTitle:${subTitle}\nbody:${body}\noptions:${"object"==typeof opts?JSON.stringify(opts):opts}`),this.isSurge)$notification.post(title,subTitle,body,opts);else if(this.isLoon)opts?$notification.post(title,subTitle,body,opts):$notification.post(title,subTitle,body);else if(this.isQuanX)$notify(title,subTitle,body,opts);else if(this.isJSBox){let push={title:title,body:subTitle?`${subTitle}\n${body}`:body};$push.schedule(push)}this._barkUrl&&this._barkKey&&this.notifyBark(title,subTitle,body)}notifyDebug(title=this.scriptName,subTitle="",body="",opts=""){"DEBUG"===this.logLevel&&(1==arguments.length&&(title=this.scriptName,subTitle="",body=arguments[0]),this.notify(title,subTitle,body,opts))}notifyBark(title=this.scriptName,subTitle="",body="",opts=""){let options={url:this._barkUrl,headers:{"Content-Type":"application/json; charset=utf-8"},body:{title:title,body:subTitle?`${subTitle}\n${body}`:body,device_key:this._barkKey}};this.post(options,err=>{})}log(msg,level="INFO"){this.logLevels[this._logLevel]void 0===_options.body?"":`${encodeURIComponent(key)}=${encodeURIComponent(_options.body[key])}`).join("&");_options.url.indexOf("?")<0&&(_options.url+="?"),_options.url.lastIndexOf("&")+1!=_options.url.length&&_options.url.lastIndexOf("?")+1!=_options.url.length&&(_options.url+="&"),_options.url+=qs,delete _options.body}return this.isQuanX?(_options.hasOwnProperty("body")&&"string"!=typeof _options.body&&(_options.body=JSON.stringify(_options.body)),_options.method=method):this.isNode?(delete _options.headers["Accept-Encoding"],"object"==typeof _options.body&&("GET"===method?(_options.qs=_options.body,delete _options.body):"POST"===method&&(_options.json=!0,_options.body=_options.body))):this.isJSBox&&(_options.header=_options.headers,delete _options.headers),_options}adapterHttpResponse(resp){let _resp={body:resp.body,headers:resp.headers,json:()=>JSON.parse(_resp.body)};return resp.hasOwnProperty("statusCode")&&resp.statusCode&&(_resp.status=resp.statusCode),_resp}get(options,callback){let _options=this.adapterHttpOptions(options,"GET");this.logDebug(`HTTP GET: ${JSON.stringify(_options)}`),this.isSurge||this.isLoon?$httpClient.get(_options,callback):this.isQuanX?$task.fetch(_options).then(resp=>{resp.status=resp.statusCode,callback(null,resp,resp.body)},reason=>callback(reason.error,null,null)):this.isNode?this.node.request.get(_options,(err,resp,data)=>{resp=this.adapterHttpResponse(resp),callback(err,resp,data)}):this.isJSBox&&(_options.handler=resp=>{let err=resp.error?JSON.stringify(resp.error):void 0,data="object"==typeof resp.data?JSON.stringify(resp.data):resp.data;callback(err,resp.response,data)},$http.get(_options))}getPromise(options){return new Promise((resolve,reject)=>{magicJS.get(options,(err,resp)=>{err?reject(err):resolve(resp)})})}post(options,callback){let _options=this.adapterHttpOptions(options,"POST");if(this.logDebug(`HTTP POST: ${JSON.stringify(_options)}`),this.isSurge||this.isLoon)$httpClient.post(_options,callback);else if(this.isQuanX)$task.fetch(_options).then(resp=>{resp.status=resp.statusCode,callback(null,resp,resp.body)},reason=>{callback(reason.error,null,null)});else if(this.isNode){let resp=this.node.request.post(_options,callback);resp.status=resp.statusCode,delete resp.statusCode}else this.isJSBox&&(_options.handler=resp=>{let err=resp.error?JSON.stringify(resp.error):void 0,data="object"==typeof resp.data?JSON.stringify(resp.data):resp.data;callback(err,resp.response,data)},$http.post(_options,{}))}get http(){return{get:this.getPromise,post:this.post}}done(value={}){"undefined"!=typeof $done&&$done(value)}isToday(day){if(null==day)return!1;{let today=new Date;return"string"==typeof day&&(day=new Date(day)),today.getFullYear()==day.getFullYear()&&today.getMonth()==day.getMonth()&&today.getDay()==day.getDay()}}isNumber(val){return"NaN"!==parseFloat(val).toString()}attempt(promise,defaultValue=null){return promise.then(args=>[null,args]).catch(ex=>(this.logError(ex),[ex,defaultValue]))}retry(fn,retries=5,interval=0,callback=null){return(...args)=>new Promise((resolve,reject)=>{function _retry(...args){Promise.resolve().then(()=>fn.apply(this,args)).then(result=>{"function"==typeof callback?Promise.resolve().then(()=>callback(result)).then(()=>{resolve(result)}).catch(ex=>{retries>=1?interval>0?setTimeout(()=>_retry.apply(this,args),interval):_retry.apply(this,args):reject(ex),retries--}):resolve(result)}).catch(ex=>{this.logRetry(ex),retries>=1&&interval>0?setTimeout(()=>_retry.apply(this,args),interval):retries>=1?_retry.apply(this,args):reject(ex),retries--})}_retry.apply(this,args)})}formatTime(time,fmt="yyyy-MM-dd hh:mm:ss"){var o={"M+":time.getMonth()+1,"d+":time.getDate(),"h+":time.getHours(),"m+":time.getMinutes(),"s+":time.getSeconds(),"q+":Math.floor((time.getMonth()+3)/3),S:time.getMilliseconds()};/(y+)/.test(fmt)&&(fmt=fmt.replace(RegExp.$1,(time.getFullYear()+"").substr(4-RegExp.$1.length)));for(let k in o)new RegExp("("+k+")").test(fmt)&&(fmt=fmt.replace(RegExp.$1,1==RegExp.$1.length?o[k]:("00"+o[k]).substr((""+o[k]).length)));return fmt}now(){return this.formatTime(new Date,"yyyy-MM-dd hh:mm:ss")}today(){return this.formatTime(new Date,"yyyy-MM-dd")}sleep(time){return new Promise(resolve=>setTimeout(resolve,time))}}(scriptName)} diff --git a/script/smzdm/smzdm_mission.lnscript b/script/smzdm/smzdm_mission.lnscript deleted file mode 100644 index 2f94612b8..000000000 --- a/script/smzdm/smzdm_mission.lnscript +++ /dev/null @@ -1,6 +0,0 @@ -# 什么值得买每日自动任务 - -http-request ^https?:\/\/zhiyou\.smzdm\.com\/user$ requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.js,tag=什么值得买_获取cookie -cron "20 0 * * *" script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_mission.js,timeout=120,tag=什么值得买_每日任务 - -hostname = zhiyou.smzdm.com \ No newline at end of file diff --git a/script/smzdm/smzdm_mission.qxrewrite b/script/smzdm/smzdm_mission.qxrewrite deleted file mode 100644 index 38dff8039..000000000 --- a/script/smzdm/smzdm_mission.qxrewrite +++ /dev/null @@ -1,6 +0,0 @@ -# 什么值得买每日自动签到 - -^https?:\/\/zhiyou\.smzdm\.com\/user$ url script-request-header https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.js -^https?:\/\/user-api\.smzdm\.com\/user_login\/normal$ url script-request-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_mission.js - -hostname = zhiyou.smzdm.com \ No newline at end of file diff --git a/script/smzdm/smzdm_mission.sgmodule b/script/smzdm/smzdm_mission.sgmodule deleted file mode 100644 index 4299bd2c6..000000000 --- a/script/smzdm/smzdm_mission.sgmodule +++ /dev/null @@ -1,10 +0,0 @@ -#!name=什么值得买 -#!desc=什么值得买每日自动任务 -#!system=ios - -[Script] -什么值得买_每日任务 = script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_mission.js,timeout=120,type=cron,cronexp=20 0 * * * -什么值得买_获取cookie = script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.js,type=http-request,requires-body=true,pattern=^https?:\/\/zhiyou\.smzdm\.com\/user$ - -[MITM] -hostname = %APPEND% zhiyou.smzdm.com \ No newline at end of file diff --git a/script/smzdm/smzdm_signin.js b/script/smzdm/smzdm_signin.js deleted file mode 100644 index 6114d2c10..000000000 --- a/script/smzdm/smzdm_signin.js +++ /dev/null @@ -1,344 +0,0 @@ -const zhiyouRegex = /^https?:\/\/zhiyou\.smzdm\.com\/user$/; -const smzdmCookieKey = 'smzdm_cookie'; -const smzdmSessionKey = 'smzdm_session'; -const scriptName = '什么值得买'; - -let magicJS = MagicJS(scriptName, "INFO"); -magicJS.barkUrl = magicJS.read('smzdm_unified_push_url') || magicJS.read('magicjs_unified_push_url'); - - -function randomStr(){ - let len = 17; - let char = '0123456789'; - let str = '' - for (i = 0; i < len; i++) { - str += char.charAt(Math.floor(Math.random() * char.length)); - } - return str; -} - -// Web端登录获取Cookie -function GetWebCookie() { - let match_str = magicJS.request.headers.Cookie.match(/sess=[^\s]*;/); - session_id = match_str != null ? match_str[0] : null; - // 获取新的session_id - if (session_id) { - // 获取持久化的session_id - old_session_id = magicJS.read(smzdmSessionKey) != null ? magicJS.read(smzdmSessionKey) : ''; - // 获取新的session_id - console.log({ 'old_session_id': old_session_id, 'new_session_id': session_id }); - // 比较差异 - if (old_session_id == session_id) { - magicJS.logInfo('网页版cookie没有变化,无需更新。'); - } - else { - // 持久化cookie - magicJS.write(smzdmSessionKey, session_id); - magicJS.write(smzdmCookieKey, magicJS.request.headers.Cookie); - magicJS.logInfo('写入cookie ' + magicJS.request.headers.Cookie); - magicJS.notify(scriptName, '', '🎈获取cookie成功!!'); - } - } - else { - magicJS.logError('没有读取到有效的Cookie信息。'); - } -} - -// Web端签到 -function WebSignin(cookie) { - return new Promise((resolve, reject) => { - let ts = Date.parse(new Date()); - let options = { - url : `https://zhiyou.smzdm.com/user/checkin/jsonp_checkin?callback=jQuery11240${randomStr()}_${ts}&_=${ts+3}`, - headers : { - 'Accept': '*/*', - 'Accept-Language': 'zh-cn', - 'Connection': 'keep-alive', - 'Host': 'zhiyou.smzdm.com', - 'Referer': 'https://www.smzdm.com/', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15', - 'Cookie': cookie - } - }; - magicJS.get(options, (err, resp, data)=>{ - if (err) { - magicJS.logWarning('Web端签到出现异常:' + err); - reject('Web:签到异常'); - } - else{ - try { - let checkin_data = /\((.*)\)/.exec(data); - if (checkin_data){ - let checkin_obj = JSON.parse(checkin_data[1]); - if (!!checkin_obj && checkin_obj.hasOwnProperty('error_code')){ - if (checkin_obj.error_code == -1){ - magicJS.logWarning(`Web端签到出现异常,网络繁忙,接口返回:${data}`); - reject( 'Web:网络繁忙'); - } - else if (checkin_obj['error_code'] == 99){ - magicJS.logWarning('Web端Cookie已过期'); - resolve([false, 'Web:Cookie过期']); - } - else if (checkin_obj['error_code'] == 0){ - magicJS.logInfo('Web:签到成功'); - resolve([true, 'Web:签到成功']); - } - else{ - magicJS.logWarning(`Web端签到出现异常,接口返回数据不合法:${data}`); - reject('Web:返回错误'); - } - } - } - else{ - magicJS.logWarning(`Web端签到出现异常,接口返回数据不存在:${data}`); - reject('Web:签到异常'); - } - } - catch (err){ - magicJS.logWarning(`Web端签到出现异常,代码执行异常:${err},接口返回:${data}`); - reject('Web:执行异常'); - } - } - }) - }) -} - -function AppSignin(cookie){ - - function GetAppSigninBody(){ - let ts = new Date().getTime(); - let token = /sess=([^;]*)/.exec(cookie)[1]; - let sign = hex_md5(`f=android&sk=1&time=${ts}&token=${token}&v=10.0&weixin=0&key=apr1$AwP!wRRT$gJ/q.X24poeBInlUJC`).toUpperCase(); - return `touchstone_event=&v=10.0&sign=${sign}&weixin=0&time=${ts}&sk=1&token=${token}&f=android&captcha=` - } - - let options = { - url: "https://user-api.smzdm.com/checkin", - headers: { - "Accept": "*/*", - "Accept-Encoding": "gzip, deflate, br", - "Accept-Language": "zh-Hans-CN;q=1, en-CN;q=0.9", - "Connection": "keep-alive", - "Content-Type": "application/x-www-form-urlencoded", - "Cookie": cookie, - "Host": "user-api.smzdm.com" - }, - body: GetAppSigninBody() - }; - return new Promise((resolve, reject) => { - magicJS.post(options, (err, resp, data)=>{ - if (err){ - magicJS.logError(`APP签到失败,请求异常:${err}`); - reject('❌APP签到失败,请求异常,请查阅日志!'); - } - else{ - try{ - magicJS.logDebug(`App签到接口返回:${data}`); - let obj = typeof data === 'string'? JSON.parse(data) : data; - if (obj.error_code === '0' && obj.error_msg === '已签到'){ - resolve('APP:重复签到'); - } - if (obj.error_code === '0' && obj.error_msg.indexOf('签到成功') >= 0){ - resolve('APP:签到成功'); - } - else{ - reject('APP:签到异常'); - } - } - catch(err){ - magicJS.logError(`App签到失败,执行异常:${err},接口响应:${data}`); - reject('❌App签到失败,执行异常,请查阅日志!'); - } - } - }) - }); -} - -// 获取用户信息,新版 -function WebGetCurrentInfoNewVersion(smzdmCookie){ - return new Promise(resolve =>{ - let options ={ - url : 'https://zhiyou.smzdm.com/user/exp/', - headers : { - 'Cookie': smzdmCookie - }, - body: '' - }; - magicJS.get(options, (err, resp, data)=>{ - if (err){ - magicJS.logError(`获取用户信息失败,异常信息:${err}`); - resolve([null,null,null,null,null,null,null]); - } - else{ - try{ - // 获取用户名 - let userName =data.match(/info-stuff-nickname.*zhiyou\.smzdm\.com\/user[^<]*>([^<]*)(.*)<\/div>/ig); - let pointDetailList = data.match(/
(.*)<\/div>/ig); - let minLength = pointTimeList.length > pointDetailList.length ? pointDetailList.length : pointTimeList.length; - let userPointList = []; - for (let i=0;i(.*)\<\/div\>/)[1], - 'detail': pointDetailList[i].match(/\
(.*)\<\/div\>/)[1] - }); - } - // 获取用户资源 - let assetsNumList = data.match(/assets-part[^<]*>(.*)(.*)(.*)(.*)(.*)(.*) { - let webGetCurrentInfo = { - url : `https://zhiyou.smzdm.com/user/info/jsonp_get_current?with_avatar_ornament=1&callback=jQuery112403507528653716241_${new Date().getTime()}&_=${new Date().getTime()}`, - headers : { - 'Accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01', - 'Accept-Language': 'zh-CN,zh;q=0.9', - 'Connection': 'keep-alive', - 'DNT': '1', - 'Host': 'zhiyou.smzdm.com', - 'Referer': 'https://zhiyou.smzdm.com/user/', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36', - 'Cookie': smzdmCookie - } - }; - magicJS.get(webGetCurrentInfo, (err, resp, data)=>{ - try{ - let obj = JSON.parse(/\((.*)\)/.exec(data)[1]); - if (obj['smzdm_id'] !== 0){ - resolve([ - obj['nickname'], // 昵称 - `https:${obj['avatar']}`, // 头像 - obj['vip_level'], // 新版VIP等级 - obj['checkin']['has_checkin'], //是否签到 - Number(obj['checkin']['daily_checkin_num']), //连续签到天数 - Number(obj['unread']['notice']['num']), // 未读消息 - Number(obj['level']), // 旧版等级 - Number(obj['exp']), // 旧版经验 - Number(obj['point']), // 积分 - Number(obj['gold']), // 金币 - Number(obj['silver']) // 碎银子 - ]); - } - else { - magicJS.logWarning(`获取用户信息异常,Cookie过期或接口变化:${data}`); - resolve([null, null, null, null, null, false, null, null]); - } - } - catch (err){ - magicJS.logError(`获取用户信息异常,代码执行异常:${err},接口返回数据:${data}`); - resolve([null, null, null, null, null, false, null, null]); - } - }) - }); -} - -;(async() =>{ - if (magicJS.isRequest && zhiyouRegex.test(magicJS.request.url) && magicJS.request.method == 'GET'){ - GetWebCookie(); - } - else{ - // 通知信息 - let title = ''; - let subTitle = ''; - let content = ''; - // 获取Cookie - let smzdmCookie = magicJS.read(smzdmCookieKey); - - if (!!smzdmCookie === false){ - magicJS.logWarning('没有读取到什么值得买有效cookie,请访问zhiyou.smzdm.com进行登录'); - magicJS.notify(scriptName, '', '❓没有获取到Web端Cookie,请先进行登录。'); - } - else{ - try{ - - // 查询签到前用户数据 - let [nickName, avatar, beforeVIPLevel, beforeHasCheckin, , beforeNotice, , ,beforePoint, beforeGold, beforeSilver] = await WebGetCurrentInfo(smzdmCookie); - if (!nickName){ - magicJS.notify(scriptName, '', '❌Cookie过期或接口变化,请尝试重新登录'); - magicJS.done(); - } - else{ - let [, , , beforeExp, , beforePrestige, ] = await WebGetCurrentInfoNewVersion(smzdmCookie); - magicJS.logInfo(`昵称:${nickName}\nWeb端签到状态:${beforeHasCheckin}\n签到前等级${beforeVIPLevel},积分${beforePoint},经验${beforeExp},金币${beforeGold},碎银子${beforeSilver}, 未读消息${beforeNotice}`); - - // Web端签到及重试 - let webCheckinRetry = magicJS.retry(WebSignin, 5, 500); - let [webCheckinErr,[webCheckinResult, webCheckinStr]] = await magicJS.attempt(webCheckinRetry(smzdmCookie), [false, 'Web端签到异常']); - if (webCheckinErr){ - magicJS.logWarning('Web端签到异常:' + webCheckinErr); - magicJS.notify(webCheckinErr); - } - else{ - subTitle = webCheckinStr; - - // APP签到 - // await magicJS.sleep(5000); - // await AppSignin(smzdmCookie).then(signinStr => { - // subTitle += ` ${signinStr}`; - // }).catch(ex =>{ - // subTitle += ` ${ex}`; - // }) - - // 查询签到后用户数据 - await magicJS.sleep(3000); - let [, , afterVIPLevel, afterHasCheckin, afterCheckinNum, afterNotice, , , afterPoint, afterGold, afterSilver] = await WebGetCurrentInfo(smzdmCookie); - let [, afteruserPointList, , afterExp, ,afterPrestige, ] = await WebGetCurrentInfoNewVersion(smzdmCookie); - magicJS.logInfo(`昵称:${nickName}\nWeb端签到状态:${afterHasCheckin}\n签到后等级${afterVIPLevel},积分${afterPoint},经验${afterExp},金币${afterGold},碎银子${afterSilver},未读消息${afterNotice}`); - - if (beforeHasCheckin && afterHasCheckin){ - webCheckinStr = 'Web端重复签到'; - } - - if (!!afterCheckinNum) content += `已连续签到${afterCheckinNum}天`; - - // 通知内容 - if (afterExp && beforeExp){ - let addPoint = afterPoint - beforePoint; - let addExp = afterExp - beforeExp; - let addGold = afterGold - beforeGold; - // let addPrestige = afterPrestige - beforePrestige; - let addSilver = afterSilver - beforeSilver; - content += !!content? '\n' : ''; - content += '积分' + afterPoint + (addPoint > 0 ? '(+' + addPoint + ')' : '') + - ' 经验' + afterExp + (addExp > 0 ? '(+' + addExp + ')' : '') + - ' 金币' + afterGold + (addGold > 0 ? '(+' + addGold + ')' : '') + '\n' + - '碎银子' + afterSilver + (addSilver > 0 ? '(+' + addSilver + ')' : '') + - // ' 威望' + afterPrestige + (addPrestige > 0 ? '(+' + addPrestige + ')' : '') + - ' 未读消息' + afterNotice; - } - title = `${scriptName} - ${nickName} V${afterVIPLevel}`; - magicJS.notify(title, subTitle, content, {'media-url': avatar}); - } - } - } - catch(err){ - magicJS.logError(`签到出现异常:${err}`); - magicJS.notify(scriptName, '', '❌签到出现异常,请查阅日志'); - } - } - } - magicJS.done(); -})(); - -// prettier-ignore -function MagicJS(scriptName="MagicJS",logLevel="INFO"){return new class{constructor(){if(this.version="2.2.3.5",this.scriptName=scriptName,this.logLevels={DEBUG:5,INFO:4,NOTIFY:3,WARNING:2,ERROR:1,CRITICAL:0,NONE:-1},this.isLoon="undefined"!=typeof $loon,this.isQuanX="undefined"!=typeof $task,this.isJSBox="undefined"!=typeof $drive,this.isNode="undefined"!=typeof module&&!this.isJSBox,this.isSurge="undefined"!=typeof $httpClient&&!this.isLoon,this.node={request:void 0,fs:void 0,data:{}},this.iOSUserAgent="Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1",this.pcUserAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36 Edg/84.0.522.59",this.logLevel=logLevel,this._barkUrl="",this._barkKey="",this.isNode){this.node.fs=require("fs"),this.node.request=require("request");try{this.node.fs.accessSync("./magic.json",this.node.fs.constants.R_OK|this.node.fs.constants.W_OK)}catch(err){this.node.fs.writeFileSync("./magic.json","{}",{encoding:"utf8"})}this.node.data=require("./magic.json")}else this.isJSBox&&($file.exists("drive://MagicJS")||$file.mkdir("drive://MagicJS"),$file.exists("drive://MagicJS/magic.json")||$file.write({data:$data({string:"{}"}),path:"drive://MagicJS/magic.json"}))}set barkUrl(url){try{let _url=url.replace(/\/+$/g,"");this._barkUrl=`${/^https?:\/\/([^/]*)/.exec(_url)[0]}/push`,this._barkKey=/\/([^\/]+)\/?$/.exec(_url)[1]}catch(err){this.logDebug("读取Bark推送链接失败。")}}set logLevel(level){this._logLevel="string"==typeof level?level.toUpperCase():"DEBUG"}get logLevel(){return this._logLevel}get isRequest(){return"undefined"!=typeof $request&&"undefined"==typeof $response}get isResponse(){return"undefined"!=typeof $response}get request(){return"undefined"!=typeof $request?$request:void 0}get response(){return"undefined"!=typeof $response?($response.hasOwnProperty("status")&&($response.statusCode=$response.status),$response.hasOwnProperty("statusCode")&&($response.status=$response.statusCode),$response):void 0}get platform(){return this.isSurge?"Surge":this.isQuanX?"Quantumult X":this.isLoon?"Loon":this.isJSBox?"JSBox":this.isNode?"Node.js":"Unknown"}read(key,session=""){let val="";this.isSurge||this.isLoon?val=$persistentStore.read(key):this.isQuanX?val=$prefs.valueForKey(key):this.isNode?val=this.node.data:this.isJSBox&&(val=$file.read("drive://MagicJS/magic.json").string);try{this.isNode&&(val=val[key]),this.isJSBox&&(val=JSON.parse(val)[key]),session&&("string"==typeof val&&(val=JSON.parse(val)),val=val&&"object"==typeof val?val[session]:null)}catch(err){this.logError(err),val=session?{}:null,this.del(key)}void 0===val&&(val=null);try{val&&"string"==typeof val&&(val=JSON.parse(val))}catch(err){}return this.logDebug(`READ DATA [${key}]${session?`[${session}]`:""}(${typeof val})\n${JSON.stringify(val)}`),val}write(key,val,session=""){let data=session?{}:"";if(session&&(this.isSurge||this.isLoon)?data=$persistentStore.read(key):session&&this.isQuanX?data=$prefs.valueForKey(key):this.isNode?data=this.node.data:this.isJSBox&&(data=JSON.parse($file.read("drive://MagicJS/magic.json").string)),session){try{"string"==typeof data&&(data=JSON.parse(data)),data="object"==typeof data&&data?data:{}}catch(err){this.logError(err),this.del(key),data={}}this.isJSBox||this.isNode?(data[key]&&"object"==typeof data[key]||(data[key]={}),data[key].hasOwnProperty(session)||(data[key][session]=null),void 0===val?delete data[key][session]:data[key][session]=val):void 0===val?delete data[session]:data[session]=val}else this.isNode||this.isJSBox?void 0===val?delete data[key]:data[key]=val:data=void 0===val?null:val;"object"==typeof data&&(data=JSON.stringify(data)),this.isSurge||this.isLoon?$persistentStore.write(data,key):this.isQuanX?$prefs.setValueForKey(data,key):this.isNode?this.node.fs.writeFileSync("./magic.json",data):this.isJSBox&&$file.write({data:$data({string:data}),path:"drive://MagicJS/magic.json"}),this.logDebug(`WRITE DATA [${key}]${session?`[${session}]`:""}(${typeof val})\n${JSON.stringify(val)}`)}del(key,session=""){this.logDebug(`DELETE KEY [${key}]${session?`[${session}]`:""}`),this.write(key,null,session)}notify(title=this.scriptName,subTitle="",body="",opts=""){let convertOptions;if(opts=(_opts=>{let newOpts={};if("string"==typeof _opts)this.isLoon?newOpts={openUrl:_opts}:this.isQuanX?newOpts={"open-url":_opts}:this.isSurge&&(newOpts={url:_opts});else if("object"==typeof _opts)if(this.isLoon)newOpts.openUrl=_opts["open-url"]?_opts["open-url"]:"",newOpts.mediaUrl=_opts["media-url"]?_opts["media-url"]:"";else if(this.isQuanX)newOpts=_opts["open-url"]||_opts["media-url"]?_opts:{};else if(this.isSurge){let openUrl=_opts["open-url"]||_opts.openUrl;newOpts=openUrl?{url:openUrl}:{}}return newOpts})(opts),1==arguments.length&&(title=this.scriptName,subTitle="",body=arguments[0]),this.logNotify(`title:${title}\nsubTitle:${subTitle}\nbody:${body}\noptions:${"object"==typeof opts?JSON.stringify(opts):opts}`),this.isSurge)$notification.post(title,subTitle,body,opts);else if(this.isLoon)opts?$notification.post(title,subTitle,body,opts):$notification.post(title,subTitle,body);else if(this.isQuanX)$notify(title,subTitle,body,opts);else if(this.isJSBox){let push={title:title,body:subTitle?`${subTitle}\n${body}`:body};$push.schedule(push)}this._barkUrl&&this._barkKey&&this.notifyBark(title,subTitle,body)}notifyDebug(title=this.scriptName,subTitle="",body="",opts=""){"DEBUG"===this.logLevel&&(1==arguments.length&&(title=this.scriptName,subTitle="",body=arguments[0]),this.notify(title,subTitle,body,opts))}notifyBark(title=this.scriptName,subTitle="",body="",opts=""){let options={url:this._barkUrl,headers:{"Content-Type":"application/json; charset=utf-8"},body:{title:title,body:subTitle?`${subTitle}\n${body}`:body,device_key:this._barkKey}};this.post(options,err=>{})}log(msg,level="INFO"){this.logLevels[this._logLevel]void 0===_options.body?"":`${encodeURIComponent(key)}=${encodeURIComponent(_options.body[key])}`).join("&");_options.url.indexOf("?")<0&&(_options.url+="?"),_options.url.lastIndexOf("&")+1!=_options.url.length&&_options.url.lastIndexOf("?")+1!=_options.url.length&&(_options.url+="&"),_options.url+=qs,delete _options.body}return this.isQuanX?(_options.hasOwnProperty("body")&&"string"!=typeof _options.body&&(_options.body=JSON.stringify(_options.body)),_options.method=method):this.isNode?(delete _options.headers["Accept-Encoding"],"object"==typeof _options.body&&("GET"===method?(_options.qs=_options.body,delete _options.body):"POST"===method&&(_options.json=!0,_options.body=_options.body))):this.isJSBox&&(_options.header=_options.headers,delete _options.headers),_options}adapterHttpResponse(resp){let _resp={body:resp.body,headers:resp.headers,json:()=>JSON.parse(_resp.body)};return resp.hasOwnProperty("statusCode")&&resp.statusCode&&(_resp.status=resp.statusCode),_resp}get(options,callback){let _options=this.adapterHttpOptions(options,"GET");this.logDebug(`HTTP GET: ${JSON.stringify(_options)}`),this.isSurge||this.isLoon?$httpClient.get(_options,callback):this.isQuanX?$task.fetch(_options).then(resp=>{resp.status=resp.statusCode,callback(null,resp,resp.body)},reason=>callback(reason.error,null,null)):this.isNode?this.node.request.get(_options,(err,resp,data)=>{resp=this.adapterHttpResponse(resp),callback(err,resp,data)}):this.isJSBox&&(_options.handler=resp=>{let err=resp.error?JSON.stringify(resp.error):void 0,data="object"==typeof resp.data?JSON.stringify(resp.data):resp.data;callback(err,resp.response,data)},$http.get(_options))}getPromise(options){return new Promise((resolve,reject)=>{magicJS.get(options,(err,resp)=>{err?reject(err):resolve(resp)})})}post(options,callback){let _options=this.adapterHttpOptions(options,"POST");if(this.logDebug(`HTTP POST: ${JSON.stringify(_options)}`),this.isSurge||this.isLoon)$httpClient.post(_options,callback);else if(this.isQuanX)$task.fetch(_options).then(resp=>{resp.status=resp.statusCode,callback(null,resp,resp.body)},reason=>{callback(reason.error,null,null)});else if(this.isNode){let resp=this.node.request.post(_options,callback);resp.status=resp.statusCode,delete resp.statusCode}else this.isJSBox&&(_options.handler=resp=>{let err=resp.error?JSON.stringify(resp.error):void 0,data="object"==typeof resp.data?JSON.stringify(resp.data):resp.data;callback(err,resp.response,data)},$http.post(_options,{}))}get http(){return{get:this.getPromise,post:this.post}}done(value={}){"undefined"!=typeof $done&&$done(value)}isToday(day){if(null==day)return!1;{let today=new Date;return"string"==typeof day&&(day=new Date(day)),today.getFullYear()==day.getFullYear()&&today.getMonth()==day.getMonth()&&today.getDay()==day.getDay()}}isNumber(val){return"NaN"!==parseFloat(val).toString()}attempt(promise,defaultValue=null){return promise.then(args=>[null,args]).catch(ex=>(this.logError(ex),[ex,defaultValue]))}retry(fn,retries=5,interval=0,callback=null){return(...args)=>new Promise((resolve,reject)=>{function _retry(...args){Promise.resolve().then(()=>fn.apply(this,args)).then(result=>{"function"==typeof callback?Promise.resolve().then(()=>callback(result)).then(()=>{resolve(result)}).catch(ex=>{retries>=1?interval>0?setTimeout(()=>_retry.apply(this,args),interval):_retry.apply(this,args):reject(ex),retries--}):resolve(result)}).catch(ex=>{this.logRetry(ex),retries>=1&&interval>0?setTimeout(()=>_retry.apply(this,args),interval):retries>=1?_retry.apply(this,args):reject(ex),retries--})}_retry.apply(this,args)})}formatTime(time,fmt="yyyy-MM-dd hh:mm:ss"){var o={"M+":time.getMonth()+1,"d+":time.getDate(),"h+":time.getHours(),"m+":time.getMinutes(),"s+":time.getSeconds(),"q+":Math.floor((time.getMonth()+3)/3),S:time.getMilliseconds()};/(y+)/.test(fmt)&&(fmt=fmt.replace(RegExp.$1,(time.getFullYear()+"").substr(4-RegExp.$1.length)));for(let k in o)new RegExp("("+k+")").test(fmt)&&(fmt=fmt.replace(RegExp.$1,1==RegExp.$1.length?o[k]:("00"+o[k]).substr((""+o[k]).length)));return fmt}now(){return this.formatTime(new Date,"yyyy-MM-dd hh:mm:ss")}today(){return this.formatTime(new Date,"yyyy-MM-dd")}sleep(time){return new Promise(resolve=>setTimeout(resolve,time))}}(scriptName)} - -function hex_md5(r){return rstr2hex(rstr_md5(str2rstr_utf8(r)))}function b64_md5(r){return rstr2b64(rstr_md5(str2rstr_utf8(r)))}function any_md5(r,t){return rstr2any(rstr_md5(str2rstr_utf8(r)),t)}function hex_hmac_md5(r,t){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(r),str2rstr_utf8(t)))}function b64_hmac_md5(r,t){return rstr2b64(rstr_hmac_md5(str2rstr_utf8(r),str2rstr_utf8(t)))}function any_hmac_md5(r,t,d){return rstr2any(rstr_hmac_md5(str2rstr_utf8(r),str2rstr_utf8(t)),d)}function md5_vm_test(){return"900150983cd24fb0d6963f7d28e17f72"==hex_md5("abc").toLowerCase()}function rstr_md5(r){return binl2rstr(binl_md5(rstr2binl(r),8*r.length))}function rstr_hmac_md5(r,t){var d=rstr2binl(r);d.length>16&&(d=binl_md5(d,8*r.length));for(var n=Array(16),_=Array(16),m=0;m<16;m++)n[m]=909522486^d[m],_[m]=1549556828^d[m];var f=binl_md5(n.concat(rstr2binl(t)),512+8*t.length);return binl2rstr(binl_md5(_.concat(f),640))}function rstr2hex(r){for(var t,d=hexcase?"0123456789ABCDEF":"0123456789abcdef",n="",_=0;_>>4&15)+d.charAt(15&t);return n}function rstr2b64(r){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d="",n=r.length,_=0;_8*r.length?d+=b64pad:d+=t.charAt(m>>>6*(3-f)&63);return d}function rstr2any(r,t){var d,n,_,m,f,h=t.length,e=Array(Math.ceil(r.length/2));for(d=0;d0||_>0)&&(f[f.length]=_);i[n]=m,e=f}var o="";for(d=i.length-1;d>=0;d--)o+=t.charAt(i[d]);return o}function str2rstr_utf8(r){for(var t,d,n="",_=-1;++_>>6&31,128|63&t):t<=65535?n+=String.fromCharCode(224|t>>>12&15,128|t>>>6&63,128|63&t):t<=2097151&&(n+=String.fromCharCode(240|t>>>18&7,128|t>>>12&63,128|t>>>6&63,128|63&t));return n}function str2rstr_utf16le(r){for(var t="",d=0;d>>8&255);return t}function str2rstr_utf16be(r){for(var t="",d=0;d>>8&255,255&r.charCodeAt(d));return t}function rstr2binl(r){for(var t=Array(r.length>>2),d=0;d>5]|=(255&r.charCodeAt(d/8))<>5]>>>d%32&255);return t}function binl_md5(r,t){r[t>>5]|=128<>>9<<4)]=t;for(var d=1732584193,n=-271733879,_=-1732584194,m=271733878,f=0;f>16)+(t>>16)+(d>>16);return n<<16|65535&d}function bit_rol(r,t){return r<>>32-t}var hexcase=0,b64pad=""; \ No newline at end of file diff --git a/script/smzdm/smzdm_signin.lnscript b/script/smzdm/smzdm_signin.lnscript deleted file mode 100644 index 7fab4fd84..000000000 --- a/script/smzdm/smzdm_signin.lnscript +++ /dev/null @@ -1,6 +0,0 @@ -# 什么值得买每日自动签到 - -http-request ^https?:\/\/zhiyou\.smzdm\.com\/user$ requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.js,tag=什么值得买_获取cookie -cron "5 0 * * *" script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.js,timeout=120,tag=什么值得买_每日任务 - -hostname = zhiyou.smzdm.com \ No newline at end of file diff --git a/script/smzdm/smzdm_signin.qxrewrite b/script/smzdm/smzdm_signin.qxrewrite deleted file mode 100644 index d9cf5b4e5..000000000 --- a/script/smzdm/smzdm_signin.qxrewrite +++ /dev/null @@ -1,6 +0,0 @@ -# 什么值得买每日自动签到 - -^https?:\/\/zhiyou\.smzdm\.com\/user$ url script-request-header https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.js -^https?:\/\/user-api\.smzdm\.com\/user_login\/normal$ url script-request-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/smzdm/smzdm_signin.js - -hostname = zhiyou.smzdm.com \ No newline at end of file