You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
216 lines
15 KiB
216 lines
15 KiB
4 years ago
|
/*
|
||
|
原作者:Sunert
|
||
|
改写为判断文章id,重复的自动缩减,v2p变量名为:zqwz (把zqwzbody内容复制新建一个)
|
||
|
json格式输出变量为:output_json
|
||
|
*/
|
||
|
|
||
|
const $ = new Env("中青阅读快速删重")
|
||
|
//const notify = $.isNode() ? require('./sendNotify') : '';
|
||
|
let ReadArr = [], timebodyVal ="",YouthBodys="",outBody="",newread="";
|
||
|
let YouthBody = $.getdata('zqwz')||$.getdata('zqwzbody');
|
||
|
let smallzq = $.getdata('zqcut')||"false";
|
||
|
let indexLast = $.getdata('zqindex');
|
||
|
let artsnum = 0, videosnum = 0;
|
||
|
let videoscore = 0,readscore = 0;
|
||
|
let artArr = [], delbody = 0;
|
||
|
|
||
|
|
||
|
if (isGetbody = typeof $request !==`undefined`) {
|
||
|
Getbody();
|
||
|
$.done()
|
||
|
}
|
||
|
let lastIndex = $.getdata('zqindex')
|
||
|
if (!$.isNode() && !YouthBody == true) {
|
||
|
$.log("您未获取阅读请求,请求阅读后获取")
|
||
|
$.msg($.name, "您未获取阅读请求,请求阅读后获取", "", {
|
||
|
'open-url': "https://kandian.youth.cn/u/UnEWm"
|
||
|
})
|
||
|
$.done()
|
||
|
} else if (!$.isNode() && YouthBody.indexOf("&") == -1) {
|
||
|
|
||
|
ReadArr.push(YouthBody);
|
||
|
} else if (!$.isNode() && YouthBody.indexOf("&") > -1) {
|
||
|
$.log("v2p模式,读取变量zqwz");
|
||
|
YouthBodys = YouthBody.split("&")
|
||
|
}
|
||
|
Object.keys(YouthBodys).forEach((item) => {
|
||
|
if (YouthBodys[item]) {
|
||
|
ReadArr.push(YouthBodys[item])
|
||
|
}
|
||
|
})
|
||
|
|
||
|
timeZone = new Date().getTimezoneOffset() / 60;
|
||
|
timestamp = Date.now() + (8 + timeZone) * 60 * 60 * 1000;
|
||
|
bjTime = new Date(timestamp).toLocaleString('zh', {
|
||
|
hour12: false,
|
||
|
timeZoneName: 'long'
|
||
|
});
|
||
|
console.log(`\n === 脚本执行 ${bjTime} ===\n`);
|
||
|
$.log("******** 您共获取" + ReadArr.length + "次阅读请求,任务开始 *******")
|
||
|
|
||
|
!(async() => {
|
||
|
|
||
|
if (!ReadArr[0]) {
|
||
|
console.log($.name, '【提示】请把抓包的请求体填入Github 的 Secrets 中,请以&隔开')
|
||
|
return;
|
||
|
}
|
||
|
if (!$.isNode()) {
|
||
|
$.begin = indexLast ? parseInt(indexLast) : 1;
|
||
|
if ($.begin + 1 < ReadArr.length) {
|
||
|
$.log("\n上次运行到第" + $.begin + "次终止,本次从" + (parseInt($.begin) + 1) + "次开始");
|
||
|
} else {
|
||
|
$.log("由于上次缩减剩余请求数已小于总请求数,本次从头开始");
|
||
|
indexLast = 0,
|
||
|
$.begin = 0
|
||
|
}
|
||
|
} else {
|
||
|
indexLast = 0,
|
||
|
$.begin = 0
|
||
|
}
|
||
|
if (smallzq == "true") {
|
||
|
$.log(" 请注意缩减请求开关已打开‼️\n 如不需要 请强制停止\n 关闭Boxjs缩减请求开关")
|
||
|
};
|
||
|
$.index = 0,readtimes="";
|
||
|
for (var i = indexLast ? indexLast : 0; i < ReadArr.length; i++) {
|
||
|
if (ReadArr[i]) {
|
||
|
articlebody = ReadArr[i];
|
||
|
$.index = $.index + 1;
|
||
|
$.log(`-------------------------\n开始中青看点第${$.index}次阅读\n`);
|
||
|
await bodyInfo();
|
||
|
}
|
||
|
};
|
||
|
$.log("\n……………………………………………………………………\n\n本次共删除" + delbody + "个请求,剩余" + (ReadArr.length - delbody) + "个请求");
|
||
|
$.msg($.name, "本次共删除" + delbody + "个重复请求,剩余" + (ReadArr.length - delbody) + "个请求");
|
||
|
|
||
|
//-------------------------------------
|
||
|
console.log("开始导出json格式:");
|
||
|
//先清空
|
||
|
$.setdata("", 'output_json');
|
||
|
ReadArr=[];
|
||
|
YouthBody = $.getdata('zqwz');
|
||
|
if (!$.isNode() && YouthBody.indexOf("&") == -1) {
|
||
|
|
||
|
ReadArr.push(YouthBody);
|
||
|
} else if (!$.isNode() && YouthBody.indexOf("&") > -1) {
|
||
|
//$.log("v2p模式,读取变量zqwz");
|
||
|
YouthBodys = YouthBody.split("&")
|
||
|
}
|
||
|
Object.keys(YouthBodys).forEach((item) => {
|
||
|
if (YouthBodys[item]) {
|
||
|
ReadArr.push(YouthBodys[item])
|
||
|
}
|
||
|
})
|
||
|
console.log(`导出数量:${ReadArr.length}`);
|
||
|
for (let k=0;k<ReadArr.length;k++){
|
||
|
newread=`"${ReadArr[k]}",`;
|
||
|
if (k==0){
|
||
|
$.setdata(newread, 'output_json');
|
||
|
}else{
|
||
|
outBody = $.getdata('output_json');
|
||
|
$.setdata(outBody +"\n"+newread,'output_json');
|
||
|
}
|
||
|
}
|
||
|
console.log("导出完成,变量名:output_json");
|
||
|
|
||
|
|
||
|
})()
|
||
|
.catch((e) => $.logErr(e))
|
||
|
.finally(() => $.done())
|
||
|
|
||
|
function bodyInfo() {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
//var xx=batHost('article/info.json?' + articlebody);
|
||
|
$.get(batHost('article/detail.json?' + articlebody), async(error, resp, data) => {
|
||
|
let bodyobj = JSON.parse(data);
|
||
|
//$.log(JSON.stringify(bodyobj,null,2))
|
||
|
$.begin = $.begin + 1;
|
||
|
let res = $.begin % ReadArr.length;
|
||
|
$.setdata(res + "", 'zqindex');
|
||
|
try {
|
||
|
if (bodyobj.error_code == "200007"&&!$.isNode()) {
|
||
|
await removebody();
|
||
|
delbody += 1;
|
||
|
$.log(bodyobj.message+"已自动删除");
|
||
|
} else if (bodyobj.error_code == 0) {
|
||
|
acticid = bodyobj.media_id.match(/\d+/)[0];
|
||
|
catname=bodyobj.catname;//fenlei
|
||
|
desc=bodyobj.description;
|
||
|
//artdesc = bodyobj.account_name
|
||
|
author = bodyobj.account_name
|
||
|
ctype = bodyobj.ctype != 3 ? "阅读资讯" : "观看视频";
|
||
|
if (artArr.indexOf(acticid) == -1) {
|
||
|
artArr.unshift(acticid);
|
||
|
$.log("文章:" + acticid + " ----- " + desc +" -- " + author + "\n")
|
||
|
//DD = 18000+Math.floor(6000 * Math.random());
|
||
|
await $.wait(1000);
|
||
|
|
||
|
//await $.wait(DD);
|
||
|
//await AutoRead();
|
||
|
} else if (artArr.indexOf(acticid) > -1&&!$.isNode()) {
|
||
|
await removebody();
|
||
|
$.log("文章ID:" + acticid + " 请求重复,已自动删除")
|
||
|
delbody += 1;
|
||
|
await $.wait(1000)
|
||
|
}
|
||
|
}
|
||
|
} catch (e) {
|
||
|
$.log('获取文章请求失败' + e)
|
||
|
} finally {
|
||
|
resolve()
|
||
|
}
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
|
||
|
function removebody() {
|
||
|
if (articlebody !== ReadArr[0]) {
|
||
|
smallbody = $.getdata('zqwz').replace("&" + articlebody, "");
|
||
|
} else {
|
||
|
smallbody = $.getdata('zqwz').replace(articlebody + "&", "")
|
||
|
}
|
||
|
$.setdata(smallbody, 'zqwz')
|
||
|
}
|
||
|
|
||
|
function batHost(api, body) {
|
||
|
return {
|
||
|
url: 'https://kandian.wkandian.com/v5/' + api,
|
||
|
headers: {
|
||
|
'User-Agent': 'okhttp/3.12.2',
|
||
|
'Host': 'kandian.wkandian.com',
|
||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||
|
'device-platform':'android'
|
||
|
},
|
||
|
body: body
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
function Getbody() {
|
||
|
if ($request && $request.method != `OPTIONS` && $request.url.match(/\/article\/info/)) {
|
||
|
bodyVal = $request.url.split("?")[1];
|
||
|
if (YouthBody) {
|
||
|
if (YouthBody.indexOf(bodyVal) > -1) {
|
||
|
$.log("此阅读请求已存在,本次跳过")
|
||
|
} else if (YouthBody.indexOf(bodyVal) == -1) {
|
||
|
YouthBodys = YouthBody + "&" + bodyVal;
|
||
|
$.setdata(YouthBodys, 'zqwz');
|
||
|
$.log(`${$.name}获取阅读: 成功, YouthBodys: ${bodyVal}`);
|
||
|
bodys = YouthBodys.split("&")
|
||
|
$.msg($.name, "获取第" + bodys.length + "个阅读请求: 成功🎉", ``)
|
||
|
}
|
||
|
} else {
|
||
|
$.setdata(bodyVal, 'zqwz');
|
||
|
$.log(`${$.name}获取阅读: 成功, YouthBodys: ${bodyVal}`);
|
||
|
$.msg($.name, `获取第一个阅读请求: 成功🎉`, ``)
|
||
|
}
|
||
|
} else if ($request && $request.method != `OPTIONS` && $request.url.match(/\/v5\/user\/stay/)) {
|
||
|
const timebodyVal = $request.body;
|
||
|
if (timebodyVal) $.setdata(timebodyVal, 'zq_timebody');
|
||
|
$.log(`${$.name}获取阅读时长: 成功, timebodyVal: ${timebodyVal}`);
|
||
|
$.msg($.name, `获取阅读时长: 成功🎉`, ``)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.
|