// ==UserScript== // @name B站每日自动助手 // @namespace https://bbs.tampermonkey.net.cn/ // @version 1.0.0 // @description 每日直播间签到+自动瓜子换硬币(可选)+每月领b币券+自动充电(可选) // @author Vikrant // @grant GM_log // @grant GM_cookie // @grant GM_notification // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM.xmlhttpRequest // @icon https://www.bilibili.com/favicon.ico // @connect api.live.bilibili.com // @connect api.bilibili.com // @connect pay.bilibili.com // @license GNU GPLv3 // @crontab * * once * * // ==/UserScript== /* ==UserConfig== setting: getCoin: title: 自动瓜子换硬币 default: false autoCharge: title: 自动充电 default: false uid: title: uid description: 要充电的up主的uid ==/UserConfig== */ return new Promise((resolve, reject) => { 'use strict'; let getCoin = GM_getValue("setting.getCoin") let autoCharge = GM_getValue("setting.autoCharge") let uid = GM_getValue("setting.uid") let autoCoin = GM_getValue("setting.autoCion") let i = 0 let count = 0 let csrf = '' GM_cookie('list', { url: 'https://api.live.bilibili.com', name: 'bili_jct' }, (cookie) => { if (cookie.length) { csrf = cookie[0].value } else { reject("csrf获取错误") } }) //直播间签到 GM_xmlhttpRequest({ url: 'https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign', method: 'GET', timeout: 10000, onload: async (xhr) => { let json = JSON.parse(xhr.responseText) let msg = json.message let code = Number(JSON.stringify(json.code)) switch (code) { case -101: GM_notification({ title: 'B站未登录!', text: '请登录后重新运行此脚本。' }) reject("未登录") case 0: GM_log('签到成功!') finish('签到') silver2coin() break case 1011040: GM_log(msg) finish('签到') silver2coin() break } }, onerror: () => { reject("签到时网络错误!") }, ontimeout: () => { reject("签到时请求超时!") } }) //自动领取B币券 GM_xmlhttpRequest({ url: 'https://api.bilibili.com/x/vip/privilege/receive', method: 'POST', data: 'type=1&csrf=' + csrf, headers: { "content-type": "application/x-www-form-urlencoded" }, timeout: 10000, onload: (xhr) => { josn = JSON.parse(xhr.responseText) msg = JSON.stringify(josn.message) if (josn.code == 0) { GM_log(msg) finish('领b币') charge(uid) } else { finish('没有b币领') finish('没领b币,不充电') } }, onerror: () => { reject("领取B币券时网络错误!") }, ontimeout: () => { reject("领取B币券时请求超时!") } }) //自动投币 if (autoCoin) { //TODO:cion } else { //finish("根据用户要求,跳过自动投币") } //自动瓜子换硬币 function silver2coin() { //GM_log('getCoin = ' + String(getCoin)) if (getCoin) { GM_xmlhttpRequest({ url: 'https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin', method: "POST", data: "platform=pc&csrf=" + csrf + "&csrf_token=" + csrf, headers: { "content-type": "application/x-www-form-urlencoded" }, timeout: 10000, onload: (xhr) => { //兑换要一定时间 setTimeout(() => { let json = JSON.parse(xhr.responseText) let msg = JSON.stringify(json.message) GM_log(msg) finish('换硬币') }, 1000); }, onerror: () => { reject("瓜子换硬币时请求错误!") }, ontimeout: () => { reject("瓜子换硬币时请求超时!") } }) } else { finish('根据用户设置,跳过换硬币') } } //自动充电 function charge(uid = 0) { GM_log('autoCharge = ' + String(autoCharge)) if (autoCharge && uid) { GM_xmlhttpRequest({ url: 'https://api.bilibili.com/x/ugcpay/web/v2/trade/elec/pay/quick', method: 'POST', data: 'bp_num=5&is_bp_remains_prior=true&up_mid=' + uid + '&otype=up&oid=' + uid + '&csrf=' + csrf, headers: { "content-type": "application/x-www-form-urlencoded", "Referer": "https://space.bilibili.com/" + uid }, timeout: 10000, onload: (xhr) => { //充电要一定时间 setTimeout(() => { let json = JSON.parse(xhr.responseText) let status = JSON.stringify(json.data.status) if (status == 4) { GM_log("充电成功!") } else { let msg = JSON.stringify(json.data.msg) GM_log(msg) } finish('充电') }, 1000); }, onerror: () => { reject("充电时请求错误!") }, ontimeout: () => { reject("充电时请求超时!") } }) } else { finish('根据用户设置,跳过充电') } } function finish(str = '') { ++count //GM_log(count + '.finish ' + str) } let scan = setInterval(() => { ++i if (count == 4) { clearInterval(scan) resolve() } else if (i >= 16) { clearInterval(scan) reject("脚本运行超时") } }, 1500); })