Skip to content

Instantly share code, notes, and snippets.

@CroMarmot
Last active February 16, 2023 23:57
Show Gist options
  • Save CroMarmot/c315dad2de516c1fbf2945a5fe454d47 to your computer and use it in GitHub Desktop.
Save CroMarmot/c315dad2de516c1fbf2945a5fe454d47 to your computer and use it in GitHub Desktop.
douyu_ygb.js
// ==UserScript==
// @name 斗鱼自动送荧光棒
// @namespace http://tampermonkey.net/
// @version 0.1
// @description douyu斗鱼自动荧光棒,配置房间id
// @author cromarmot
// @match *://douyu.com/*
// @match *://www.douyu.com/*
// @exclude *://douyu.com/?*
// @icon https://www.douyu.com/favicon.ico
// @run-at document-end
// ==/UserScript==
const cookies = document.cookie;
// 可配多个主播房间号 每个房间每次送1个
const roomarr = [4238637/*8777*/,544091];
function send_ygb(roomid) {
let myHeaders = new Headers();
myHeaders.append("cookie", cookies);
myHeaders.append("referer", "https://www.douyu.com/"+roomid);
let requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://www.douyu.com/japi/prop/backpack/web/v1?rid="+roomid, requestOptions)
.then(response => response.json()).then(function(json){
console.log(`roomid = ${roomid} 礼物种数: ${json.data.list.length}` );
if (json.data.list.length > 0) {
send_gifts(json.data.list, roomid);
}
})
}
function send_gifts(gifts, roomid) {
for (const gift of gifts) {
if (gift.id == 268) {
let myHeaders = new Headers();
myHeaders.append("cookie", cookies);
myHeaders.append("referer", "https://www.douyu.com/"+roomid);
let urlencoded = new URLSearchParams();
urlencoded.append("propId", "268");
console.log('荧光棒个数:',gift.count);
urlencoded.append("propCount", 1); // 送1个, // gift.count);
urlencoded.append("roomId", roomid);
urlencoded.append("bizExt", "{\"yzxq\":{}}");
let requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};
fetch("https://www.douyu.com/japi/prop/donate/mainsite/v1", requestOptions)
.then(response => response.text())
.then(console.log)
.catch(console.error);
}
}
}
(function() {
'use strict';
console.log('script loaded');
roomarr.map(roomid => send_ygb(roomid));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment