|
| 1 | +/** |
| 2 | + * Cookie 心跳 |
| 3 | + * 尝试每2小时运行一次本脚本来保持Cookie的活性 (效果待验证) |
| 4 | + */ |
| 5 | + |
| 6 | +const cookieName = '腾讯视频' |
| 7 | +const cookieKey = 'chavy_cookie_videoqq' |
| 8 | +const chavy = init() |
| 9 | +const cookieVal = chavy.getdata(cookieKey) |
| 10 | + |
| 11 | +keep() |
| 12 | + |
| 13 | +function keep() { |
| 14 | + const timestamp = Date.parse(new Date()) |
| 15 | + let url = { url: `https://vip.video.qq.com/fcgi-bin/comm_cgi?name=spp_PropertyNum&cmd=1&growth_value=1&otype=json&_=${timestamp}`, headers: { Cookie: cookieVal } } |
| 16 | + url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15' |
| 17 | + chavy.get(url, (error, response, data) => { |
| 18 | + chavy.log(`[${cookieName} 心跳], data: ${data}`) |
| 19 | + }) |
| 20 | + chavy.done() |
| 21 | +} |
| 22 | + |
| 23 | +function init() { |
| 24 | + isSurge = () => { |
| 25 | + return undefined === this.$httpClient ? false : true |
| 26 | + } |
| 27 | + isQuanX = () => { |
| 28 | + return undefined === this.$task ? false : true |
| 29 | + } |
| 30 | + getdata = (key) => { |
| 31 | + if (isSurge()) return $persistentStore.read(key) |
| 32 | + if (isQuanX()) return $prefs.valueForKey(key) |
| 33 | + } |
| 34 | + setdata = (key, val) => { |
| 35 | + if (isSurge()) return $persistentStore.write(key, val) |
| 36 | + if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 37 | + } |
| 38 | + msg = (title, subtitle, body) => { |
| 39 | + if (isSurge()) $notification.post(title, subtitle, body) |
| 40 | + if (isQuanX()) $notify(title, subtitle, body) |
| 41 | + } |
| 42 | + log = (message) => console.log(message) |
| 43 | + get = (url, cb) => { |
| 44 | + if (isSurge()) { |
| 45 | + $httpClient.get(url, cb) |
| 46 | + } |
| 47 | + if (isQuanX()) { |
| 48 | + url.method = 'GET' |
| 49 | + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 50 | + } |
| 51 | + } |
| 52 | + post = (url, cb) => { |
| 53 | + if (isSurge()) { |
| 54 | + $httpClient.post(url, cb) |
| 55 | + } |
| 56 | + if (isQuanX()) { |
| 57 | + url.method = 'POST' |
| 58 | + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 59 | + } |
| 60 | + } |
| 61 | + done = (value = {}) => { |
| 62 | + $done(value) |
| 63 | + } |
| 64 | + return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 65 | +} |
0 commit comments