diff --git a/Script/TikTok.js b/Script/TikTok.js index bef8b5e58fdd180a3f6866fa3585abfcb8fd0ea6..cf922b2b83b017bb84570da687500c092520c456 100644 --- a/Script/TikTok.js +++ b/Script/TikTok.js @@ -27,8 +27,8 @@ class Widget extends DJG { this.version = "V3.5"; this.logo = 'https://s1.ax1x.com/2022/07/10/jrjmuj.png' this.argData = { - url: 'https://v.douyin.com/ePRqdq1/', - newurl: 'https://www.iesdouyin.com/web/api/v2/user/info/?sec_uid=MS4wLjABAAAAAsK0BANoLrNmDyek-W6s1s2DO8jNCW3Xywpl6NOuVgf7LIlE-OcsZc8gf8dfIkeL&did=MS4wLjABAAAAB5InKo1kS25fp5_jxtIt1UPQ4kDrWAFiLWgfVu2RkDdoTW3p9Db10gaXFbaeFi0i&iid=MS4wLjABAAAA7p_gWw1FQyqLje4bidmdzpeNASfbpoFLYsFQ8ubydyrpVJVCcVHrsOk5nDxlhdj5&with_sec_did=1&timestamp=1621482478&utm_source=copy&utm_campaign=client_share&utm_medium=android&' + url: 'https://v.douyin.com/rmPc2QR/', + newurl: '' } this.Run(); @@ -49,17 +49,18 @@ class Widget extends DJG { } try{ const data = await this.httpGet(this.settings.newurl); + await this.updateKeychainInfo(data) await this.infoNotify(data); switch (this.widgetFamily) { case 'small': - await this.renderSmall(widget, data); - break; + await this.renderSmall(widget, data); + break; case 'medium': - await this.renderMedium(widget, data); - break; + await this.renderMedium(widget, data); + break; default: - await this.largeWidget(widget, data); - break; + await this.largeWidget(widget, data); + break; } }catch(e){ this.ERROR.push({error:e.toString()}); @@ -79,11 +80,23 @@ class Widget extends DJG { this.settings.newurl = newurl this.saveSettings(false); } - - //消息提醒 - async infoNotify(content) { - const optionStatus = this.settings.optionStatus || [true, false]; - if(!optionStatus[0] && !optionStatus[1]) return ; + + judgeTime(date) { + var today = new Date(); + today.setHours(0); + today.setMinutes(0); + today.setSeconds(0); + today.setMilliseconds(0); + var otime = today.getTime()//今天0点 + + var offset= date-otime + var isToday = offset/1000/60/60 + if (isToday > 0 && isToday <= 24) { return "today" } + else if (isToday < 0 && isToday >= -24) { return "yesterday" } + else{ return "other" } + } + + updateKeychainInfo(content) { let name = content["user_info"]["nickname"] let id = content["user_info"]["short_id"] let douyin_info = {} @@ -94,70 +107,176 @@ class Widget extends DJG { douyin_info[name + '的喜欢'] = content["user_info"]["favoriting_count"] douyin_info[name + '的粉丝数'] = content["user_info"]["follower_count"] douyin_info[name + '的获赞数'] = content["user_info"]["total_favorited"] + douyin_info['cacheDate'] = content["extra"]["now"] let cache = Keychain.contains(id) var newdata = JSON.stringify(douyin_info) if (cache == false) { - Keychain.set(id, newdata) + Keychain.set(id, newdata) } else { - let olddata = Keychain.get(id); - if (olddata == newdata) { + let olddata = Keychain.get(id) + if (this.judgeTime(olddata['cacheDate']) == 'other') { + Keychain.set(id, newdata) + } + } + } + + //消息提醒 + async infoNotify(content) { + const optionStatus = this.settings.optionStatus || [true, false]; + if (!optionStatus[0] && !optionStatus[1]) return; + + let id = content["user_info"]["short_id"] + + let cache = Keychain.contains(id) + + if (cache == true) { + let name = content["user_info"]["nickname"] + let douyin_info = {} + douyin_info[name + '的昵称'] = content["user_info"]["nickname"] + douyin_info[name + '的ID'] = content["user_info"]["short_id"] + douyin_info[name + '的关注数'] = content["user_info"]["following_count"] + douyin_info[name + '的作品数'] = content["user_info"]["aweme_count"] + douyin_info[name + '的喜欢'] = content["user_info"]["favoriting_count"] + douyin_info[name + '的粉丝数'] = content["user_info"]["follower_count"] + douyin_info[name + '的获赞数'] = content["user_info"]["total_favorited"] + + let olddata = Keychain.get(id); + let oldjson = JSON.parse(olddata) + let newjson = JSON.stringify(douyin_info) + if (this.judgeTime(oldjson['cacheDate']) == 'yesterday') { + let gz = oldjson[name + '的关注数']; + let like = oldjson[name + '的喜欢']; + let work = oldjson[name + '的作品数']; + let zan = oldjson[name + '的获赞数']; + let fan = oldjson[name + '的粉丝数']; + let gz1 = newjson[name + '的关注数']; + let like1 = newjson[name + '的喜欢']; + let work1 = newjson[name + '的作品数']; + let zan1 = newjson[name + '的获赞数']; + let fan1 = newjson[name + '的粉丝数']; + let bd = {} + bd['关注新增'] = (gz1 - gz); + bd['喜欢新增'] = (like1 - like); + bd['作品新增'] = (work1 - work); + bd['获赞新增'] = (zan1 - zan); + bd['粉丝新增'] = (fan1 - fan); + let mail_msg1 + if (bd['关注新增'] > 0) { + mail_msg1 = "新关注了" + bd['关注新增'] + "个人;" + } else if (bd['关注新增'] < 0) { + mail_msg1 = "取关了" + Math.abs((bd['关注新增'])) + '个人;' + } else { + mail_msg1 = ''; + } + let mail_msg2 + if (bd['喜欢新增'] > 0) { + mail_msg2 = '喜欢了' + bd['喜欢新增'] + '个作品;' + } else if (bd['喜欢新增'] < 0) { + mail_msg2 = '取消喜欢了' + Math.abs(bd['喜欢新增']) + '个作品;' + } else { + mail_msg2 = '' + } + let mail_msg3 + if (bd['作品新增'] > 0) { + mail_msg3 = "发布了" + bd['作品新增'] + '个新作品;' + } else if (bd['作品新增'] < 0) { + mail_msg3 = "删除了" + Math.abs(bd['作品新增']) + '个作品;' + } else { + mail_msg3 = '' + } + let mail_msg4 + if (bd['获赞新增'] > 0) { + mail_msg4 = '作品多了' + bd['获赞新增'] + '个赞;' + } else if (bd['获赞新增'] < 0) { + mail_msg4 = '作品少了' + Math.abs(bd['获赞新增']) + '个赞;' } else { - let oldjson = JSON.parse(olddata) - let newjson = JSON.parse(newdata) - let gz = oldjson[name + '的关注数']; let like = oldjson[name + '的喜欢']; - let work = oldjson[name + '的作品数']; let zan = oldjson[name + '的获赞数']; - let fan = oldjson[name + '的粉丝数']; let gz1 = newjson[name + '的关注数']; - let like1 = newjson[name + '的喜欢']; let work1 = newjson[name + '的作品数']; - let zan1 = newjson[name + '的获赞数']; let fan1 = newjson[name + '的粉丝数']; - let bd = {} - bd['关注新增'] = (gz1 - gz); bd['喜欢新增'] = (like1 - like); - bd['作品新增'] = (work1 - work); bd['获赞新增'] = (zan1 - zan); - bd['粉丝新增'] = (fan1 - fan); - let mail_msg1 - if (bd['关注新增'] > 0) { mail_msg1 = name + "新关注了" + bd['关注新增'] + "个人;" } - else if(bd['关注新增'] < 0){ mail_msg1 = name + "取关了" + Math.abs((bd['关注新增'])) + '个人;' } - else { mail_msg1 = ''; } - let mail_msg2 - if (bd['喜欢新增'] > 0) { mail_msg2 = name + '喜欢了' + bd['喜欢新增'] + '个作品;'} - else if(bd['喜欢新增'] < 0){ mail_msg2 = name + '取消喜欢了' + Math.abs(bd['喜欢新增']) + '个作品;'} - else { mail_msg2 = ''} - let mail_msg3 - if (bd['作品新增'] > 0) { mail_msg3 = name + "发布了" + bd['作品新增'] + '个新作品;'} - else if(bd['作品新增'] < 0){ mail_msg3 = name + "删除了" + Math.abs(bd['作品新增']) + '个作品;'} - else { mail_msg3 = ''} - let mail_msg4 - if (bd['获赞新增'] > 0) { mail_msg4 = name + '的作品多了' + bd['获赞新增'] + '个赞;'} - else if(bd['获赞新增'] < 0){ mail_msg4 = name + '的作品少了' + Math.abs(bd['获赞新增']) + '个赞;'} - else { mail_msg4 = ''} - let mail_msg5 - if (bd['粉丝新增'] > 0) { mail_msg5 = name + '多了' + bd['粉丝新增'] + '个粉丝;'} - else if(bd['粉丝新增'] < 0){ mail_msg5 = name + '少了' + Math.abs(bd['粉丝新增']) + '个粉丝;'} - else { mail_msg5 = ''} - Keychain.set(id, newdata) - let mail_msg = mail_msg1 + mail_msg2 + mail_msg3 + mail_msg4 + mail_msg5 - name = name + "的抖音有了新动态" - optionStatus[1] ? - this.notify(name,mail_msg) : this.notify(name,mail_msg,false) - }} + mail_msg4 = '' + } + let mail_msg5 + if (bd['粉丝新增'] > 0) { + mail_msg5 = '多了' + bd['粉丝新增'] + '个粉丝;' + } else if (bd['粉丝新增'] < 0) { + mail_msg5 = '少了' + Math.abs(bd['粉丝新增']) + '个粉丝;' + } else { + mail_msg5 = '' + } + let mail_msg = mail_msg1 + mail_msg2 + mail_msg3 + mail_msg4 + mail_msg5 + name = "今日抖音新动态" + optionStatus[1] ? + this.notify(name, mail_msg) : this.notify(name, mail_msg, false) + } + } } + // 小组件 async renderSmall(w, content){ w.addSpacer(10) const title = w.addStack() const img = await this.getImageByUrl(this.logo); this.addImage(title, img, {w:16, h:16}); - this.addText(title, ' '+content["user_info"]["nickname"], 15) - w.addSpacer(30) - const following_count = ' 关注 ' + this.numFormatr(content["user_info"]["following_count"],1,false) - this.addText(w, following_count, 15, {opacity:0.9}) - w.addSpacer(8) - const follower_count = ' 粉丝 ' + this.numFormatr(content["user_info"]["follower_count"],1,false) - this.addText(w, follower_count, 15, {opacity:0.9}) - w.addSpacer(8) - const total_favorited = ' 获赞 ' + this.numFormatr(content["user_info"]["total_favorited"],1,false) - this.addText(w, total_favorited, 15, {opacity:0.9}) - w.addSpacer(13) + title.addSpacer(5) + this.addText(title, content["user_info"]["nickname"], 15, {font:'semibold', lineLimit:5}) + title.addSpacer(10) + w.addSpacer(20) + + + let id = content["user_info"]["short_id"] + let name = content["user_info"]["nickname"] + let total_favorited = content["user_info"]["total_favorited"]; + let aweme_count = content["user_info"]["aweme_count"]; + let follower_count = content["user_info"]["follower_count"]; + let cache = Keychain.contains(id) + if (cache == true) { + let olddata = Keychain.get(id); + let oldjson = JSON.parse(olddata); + if (this.judgeTime(olddata['cacheDate'] == 'yesterday')) { + let aweme = oldjson[name + '的作品数']; + let zan = oldjson[name + '的获赞数']; + let fan = oldjson[name + '的粉丝数']; + + let zanDif = (total_favorited - zan); + let awemeDif = (aweme_count - aweme); + let followerDif = (follower_count - fan); + + + let a = w.addStack() + this.addText(a, ' 获赞 ' + total_favorited, 13, {opacity:0.9}) + if (zanDif > 0) { + this.addText(a, '↑' + Math.abs(zanDif), 11, {opacity:0.8, color:'981729'}) + } else if (zanDif < 0) { + this.addText(a, '↓' + Math.abs(zanDif), 11, {opacity:0.8, color:'326F60'}) + } + w.addSpacer(5) + + let b = w.addStack() + this.addText(b, ' 作品 ' + aweme_count, 13, {opacity:0.9}) + if (awemeDif > 0) { + this.addText(b, '↑' + Math.abs(awemeDif), 11, {opacity:0.8, color:'981729'}) + } else if (awemeDif < 0) { + this.addText(b, '↓' + Math.abs(awemeDif), 11, {opacity:0.8, color:'326F60'}) + } + w.addSpacer(5) + + + let c = w.addStack() + this.addText(c, ' 粉丝 ' + follower_count, 13, {opacity:0.9}) + if (followerDif > 0) { + this.addText(c, '↑' + Math.abs(followerDif), 11, {opacity:0.8, color:'981729'}) + } else if (followerDif < 0) { + this.addText(c, '↓' + Math.abs(followerDif), 11, {opacity:0.8, color:'326F60'}) + } + w.addSpacer(10) + return + } + } + + this.addText(w, ' 获赞 ' + total_favorited, 13, {opacity:0.9}) + w.addSpacer(5) + this.addText(w, ' 关注 ' + aweme_count, 13, {opacity:0.9}) + w.addSpacer(5) + this.addText(w, ' 粉丝 ' + follower_count, 13, {opacity:0.9}) + w.addSpacer(10) } // 中组件 async renderMedium(w, content){ @@ -171,16 +290,11 @@ class Widget extends DJG { this.addImage(left, img, {w:65, h:65}, {corner:32.5}) top.addSpacer(10) - let right=top.addStack() - right.layoutVertically() - - let aa = right.addStack() + let aa = top.addStack() const imgLogo = await this.getImageByUrl(this.logo) this.addImage(aa, imgLogo, {w:18, h:18}, {corner:4}) aa.addSpacer(5) - this.addText(aa, content["user_info"]["nickname"], 16, {font:'semibold'}) - right.addSpacer(5) - this.addText(right, content["user_info"]["signature"], 14, {opacity:0.9}) + this.addText(aa, content["user_info"]["nickname"], 16, {font:'semibold', lineLimit:5}) w.addSpacer(10) await this.setBottomr(w, content) } @@ -188,39 +302,77 @@ class Widget extends DJG { async largeWidget(w, content) { let img_user = content["user_info"]["avatar_larger"]['url_list'][0] const userImg = await this.getImageByUrl(img_user) - this.addImage(w, userImg, {w:90, h:90}, {corner:45, align:'center'}) + this.addImage(w, userImg, {w:180, h:180}, {corner:90, align:'center'}) w.addSpacer(13) const title = w.addStack() title.addSpacer() const icon = await this.getImageByUrl(this.logo); this.addImage(title, icon, {w:19, h:19}); - this.addText(title, ' '+content["user_info"]["nickname"], 18, {font:'semibold'}) + this.addText(title, ' '+content["user_info"]["nickname"], 18, {font:'semibold', lineLimit:5}) title.addSpacer() w.addSpacer(10) - this.addText(w, content["user_info"]["signature"], 15, {opacity:0.9, align:'center', lineLimit:5}) w.addSpacer(20) - await this.setBottomr(w, content) } async setBottomr(w, content){ let bottom = w.addStack(); bottom.addSpacer(); - const title = ["获赞", "关注", "粉丝"]; - const total_favorited = this.numFormatr(content["user_info"]["total_favorited"],1,false); - const following_count = this.numFormatr(content["user_info"]["following_count"],1,false); - const follower_count = this.numFormatr(content["user_info"]["follower_count"],1,false); - const DYnums = [total_favorited, following_count, follower_count]; + + var total_favorited = content["user_info"]["total_favorited"]; + var aweme_count = content["user_info"]["aweme_count"]; + var follower_count = content["user_info"]["follower_count"]; + const title = ["获赞", "作品", "粉丝"]; + const DYnums = [total_favorited, aweme_count, follower_count]; + var DYnumsDif = []; + + let id = content["user_info"]["short_id"] + let name = content["user_info"]["nickname"] + let cache = Keychain.contains(id) + if (cache == true) { + let olddata = Keychain.get(id); + let oldjson = JSON.parse(olddata); + if (this.judgeTime(olddata['cacheDate'] == 'yesterday')) { + let aweme = oldjson[name + '的作品数']; + let zan = oldjson[name + '的获赞数']; + let fan = oldjson[name + '的粉丝数']; + + let zanDif = (total_favorited - zan); + let awemeDif = (aweme_count - aweme); + let followerDif = (follower_count - fan); + DYnumsDif = [zanDif, awemeDif, followerDif]; + } + } + + for(let i = 0; i < 3; i++){ let bottomLeft = bottom.addStack() bottomLeft.layoutVertically() let a = bottomLeft.addStack() a.addSpacer() - this.addText(a, title[i], 14, {opacity:0.8}) + + var num = DYnums[i] + if (DYnumsDif.length != 0) { + + var dif = DYnumsDif[i] + if (dif > 0) { + let numWithDif = a.addStack() + this.addText(numWithDif, title[i], 14, {opacity:0.8}) + this.addText(numWithDif, '↑' + Math.abs(dif), 12, {opacity:0.8, color:'981729'}) + } else if (dif < 0) { + let numWithDif = a.addStack() + this.addText(numWithDif, title[i], 14, {opacity:0.8}) + this.addText(numWithDif, '↓' + Math.abs(dif), 12, {opacity:0.8, color:'326F60'}) + } else { + this.addText(a, title[i], 14, {opacity:0.8}) + } + } else { + this.addText(a, title[i], 14, {opacity:0.8}) + } + a.addSpacer() let b = bottomLeft.addStack() b.addSpacer() - this.addText(b, DYnums[i], 14, {opacity:0.8}) b.addSpacer() if(i != 2){