优化:油猴脚本更新逻辑,一小时内不会重复更新

This commit is contained in:
ngfchl
2023-01-26 17:50:01 +08:00
parent 4872d40fc8
commit 37d4839098
2 changed files with 70 additions and 60 deletions

View File

@@ -4,60 +4,60 @@
// @description PT站点cookie等信息发送到Ptools
// @namespace http://tampermonkey.net/
// @match https://1ptba.com/userdetails.php?id=*
// @match https://52pt.site/userdetails.php?id=*
// @match https://audiences.me/userdetails.php?id=*
// @match https://byr.pt/userdetails.php?id=*
// @match https://ccfbits.org/userdetails.php?id=*
// @match https://club.hares.top/userdetails.php?id=*
// @match https://discfan.net/userdetails.php?id=*
// @match https://et8.org/userdetails.php?id=*
// @match https://filelist.io/userdetails.php?id=*
// @match https://hdatmos.club/userdetails.php?id=*
// @match https://hdchina.org/userdetails.php?id=*
// @match https://hdcity.leniter.org/userdetails.php?id=*
// @match https://hdhome.org/userdetails.php?id=*
// @match https://hdmayi.com/userdetails.php?id=*
// @match https://hdsky.me/userdetails.php?id=*
// @match https://hdtime.org/userdetails.php?id=*
// @match https://hudbt.hust.edu.cn/userdetails.php?id=*
// @match https://1ptba.com/*
// @match https://52pt.site/*
// @match https://audiences.me/*
// @match https://byr.pt/*
// @match https://ccfbits.org/*
// @match https://club.hares.top/*
// @match https://discfan.net/*
// @match https://et8.org/*
// @match https://filelist.io/*
// @match https://hdatmos.club/*
// @match https://hdchina.org/*
// @match https://hdcity.leniter.org/*
// @match https://hdhome.org/*
// @match https://hdmayi.com/*
// @match https://hdsky.me/*
// @match https://hdtime.org/*
// @match https://hudbt.hust.edu.cn/*
// @match https://iptorrents.com/t
// @match https://kp.m-team.cc/userdetails.php?id=*
// @match https://lemonhd.org/userdetails.php?id=*
// @match https://nanyangpt.com/userdetails.php?id=*
// @match https://npupt.com/userdetails.php?id=*
// @match https://ourbits.club/userdetails.php?id=*
// @match https://pt.btschool.club/userdetails.php?id=*
// @match https://pt.eastgame.org/userdetails.php?id=*
// @match https://pt.hdbd.us/userdetails.php?id=*
// @match https://pt.keepfrds.com/userdetails.php?id=*
// @match https://pterclub.com/userdetails.php?id=*
// @match https://pthome.net/userdetails.php?id=*
// @match https://springsunday.net/userdetails.php?id=*
// @match https://totheglory.im/userdetails.php?id=*
// @match https://u2.dmhy.org/userdetails.php?id=*
// @match https://www.beitai.pt/userdetails.php?id=*
// @match https://www.haidan.video/userdetails.php?id=*
// @match https://www.hdarea.co/userdetails.php?id=*
// @match https://www.hddolby.com/userdetails.php?id=*
// @match https://www.htpt.cc/userdetails.php?id=*
// @match https://www.nicept.net/userdetails.php?id=*
// @match https://www.pthome.net/userdetails.php?id=*
// @match https://kp.m-team.cc/*
// @match https://lemonhd.org/*
// @match https://nanyangpt.com/*
// @match https://npupt.com/*
// @match https://ourbits.club/*
// @match https://pt.btschool.club/*
// @match https://pt.eastgame.org/*
// @match https://pt.hdbd.us/*
// @match https://pt.keepfrds.com/*
// @match https://pterclub.com/*
// @match https://pthome.net/*
// @match https://springsunday.net/*
// @match https://totheglory.im/*
// @match https://u2.dmhy.org/*
// @match https://www.beitai.pt/*
// @match https://www.haidan.video/*
// @match https://www.hdarea.co/*
// @match https://www.hddolby.com/*
// @match https://www.htpt.cc/*
// @match https://www.nicept.net/*
// @match https://www.pthome.net/*
// @match https://www.pttime.org
// @match https://www.tjupt.org/userdetails.php?id=*
// @match https://www.tjupt.org/*
// @match https://www.torrentleech.org
// @match https://www.carpet.net/userdetails.php?id=*
// @match https://wintersakura.net/userdetails.php?id=*
// @match https://hhanclub.top/userdetails.php?id=*
// @match https://www.hdpt.xyz/userdetails.php?id=*
// @match https://ptchina.org/userdetails.php?id=*
// @match https://www.oshen.win/userdetails.php?id=*
// @match https://www.hd.ai/userdetails.php?id=*
// @match http://ihdbits.me/userdetails.php?id=*
// @match https://zmpt.cc/userdetails.php?id=*
// @match https://leaves.red/userdetails.php?id=*
// @match https://piggo.me/userdetails.php?id=*
// @version 0.0.1
// @match https://www.carpet.net/*
// @match https://wintersakura.net/*
// @match https://hhanclub.top/*
// @match https://www.hdpt.xyz/*
// @match https://ptchina.org/*
// @match https://www.oshen.win/*
// @match https://www.hd.ai/*
// @match http://ihdbits.me/*
// @match https://zmpt.cc/*
// @match https://leaves.red/*
// @match https://piggo.me/*
// @version 0.0.2
// @grant GM_xmlhttpRequest
// @grant none
// @license GPL-3.0 License
@@ -66,6 +66,7 @@
/*
日志:
2023.01.26 更新逻辑,一小时内不会重复更新
2023.01.25 完成第一版0.0.1
2023.01.24 开始编写第一版脚本
@@ -82,7 +83,9 @@ var path = "tasks/monkey_to_ptools";
(function () {
'use strict';
main();
main().then(res => {
alert('PTools提醒您你的Cookie已更新')
});
})();
async function getSite() {
@@ -109,7 +112,7 @@ async function getData() {
let user_agent = window.navigator.userAgent
let cookie = document.cookie
let re = /\d+/;
let href = document.location.search
let href = document.evaluate(site_info.uid_xpath, document).iterateNext()
let user_id = re.exec(href)[0]
return {
user_id: user_id,
@@ -124,10 +127,10 @@ async function main() {
var data = await getData();
if (data == false) return;
console.log(data)
let res = await ajax_post(data)
console.log(res)
//await sendSiteToNastools(data);
let res = await ajax_post(data).then(res => {
alert('PTools提醒您' + res.msg)
console.log(res)
})
}

View File

@@ -1235,7 +1235,15 @@ def monkey_to_ptools(request):
logger.info(url)
site_list = Site.objects.filter(url=url)
if len(site_list) == 1:
data = {'site_id': site_list.first().id}
site = site_list.first()
logger.info(f'{(datetime.now() - site.mysite.updated_at).seconds / 3600}')
if (datetime.now() - site.mysite.updated_at).seconds <= 3600:
return JsonResponse(data=CommonResponse.error(
status=StatusCodeEnum.THROTTLING_ERR,
msg=f'更新cookie还不到一个小时啦下次再更吧'
f'{3600 - (datetime.now() - site.mysite.updated_at).seconds}后可以更新!'
).to_dict(), safe=False)
data = {'site_id': site.id, 'uid_xpath': site.my_uid_rule}
# if len(my_site_list) == 1:
# data.update({
# 'my_site_id': my_site_list.first().id
@@ -1259,9 +1267,8 @@ def monkey_to_ptools(request):
try:
res_my_site = MySite.objects.update_or_create(site_id=site_id, defaults=my_site_params)
logger.info(res_my_site[1])
return JsonResponse(data=CommonResponse.success(
msg=f'{res_my_site[0].site.name} 添加成功!'
msg=f'{res_my_site[0].site.name} Cookie信息 {"添加成功!" if res_my_site[1] else "更新成功!"}'
).to_dict(), safe=False)
except:
logger.info(traceback.format_exc(3))