Greasy Fork

Greasy Fork is available in English.

斗鱼骆歆直播间插件(自动变色刷弹幕,一键续牌)

骆歆直播间刷好听/虚张声势专用。

当前为 2020-01-02 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         斗鱼骆歆直播间插件(自动变色刷弹幕,一键续牌)
// @namespace    https://github.com/qianjiachun
// @version      0.7
// @description  骆歆直播间刷好听/虚张声势专用。
// @author       小淳
// @match			*://*.douyu.com/0*
// @match			*://*.douyu.com/1*
// @match			*://*.douyu.com/2*
// @match			*://*.douyu.com/3*
// @match			*://*.douyu.com/4*
// @match			*://*.douyu.com/5*
// @match			*://*.douyu.com/6*
// @match			*://*.douyu.com/7*
// @match			*://*.douyu.com/8*
// @match			*://*.douyu.com/9*
// @match			*://*.douyu.com/topic/*
// @grant        none

// ==/UserScript==
let barrageColorArr = [];
let barrageArr = [];
let barrageColorLength = 0;
let barrageLength = 0;
let timer;
let barrageOffset = 0;
let barrageColorOffset = 0;
let isChangeColor = true;
let save = {};
let isMatch = false;
function addInfrastructure() {
	let style = document.createElement("style");
	style.appendChild(document.createTextNode(`
	.bloop {
		background-color: rgba(255,255,255,0.8);
		width: 100%;
		height: 200px;
		position: relative;
		bottom: 200px;
		display: none;
	}
	
	.bicon {
		display: inline-block;
		vertical-align: middle;
		margin-right: 8px;
	}
	
	.bloop__switch {
		position: absolute;
		right: 0;
		bottom: 0;
	}
	
	`));
	document.head.appendChild(style);
}


function insertModal() {
	let html = "";
	let a = document.createElement("div");
	a.className = "bloop";
	html += '<div><label>弹幕(一行一个):</label></div>';
	html += '<textarea id="bloop__textarea" rows="5" cols="50"></textarea>';
	html += '<div><label>速度(ms):</label><input id="bloop__text_speed" type="text" style="width:50px;text-align:center;" value="2000" /></div>';
	html += '<div><label><input id="bloop__checkbox_changeColor" onclick="window.changeColor()" type="checkbox" name="checkbox_changeColor" checked>自动变色</label></div>';
	html += '<div class="bloop__switch"><label><input id="bloop__checkbox_startSend" onclick="window.startSend()" type="checkbox">开始发送</label></div>';
	
	a.innerHTML = html;
	
	
	let b = document.getElementsByClassName("layout-Player-chat")[0];
	b.insertBefore(a, b.childNodes[0]);
}
function insertIcon() {
	let a = document.createElement("div");
	a.className = "bicon";
	a.innerHTML = '<a title="弹幕发送小助手" href="javascript:window.showDom();"><svg t="1577862697100" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6841" width="20" height="20"><path d="M67.596337 1024C30.325205 1024 0 993.267663 0 955.490699V429.746892L138.388048 152.983133V71.161831c0-39.232771 30.53494-71.161831 68.077494-71.161831h611.068916c37.542554 0 68.077494 31.92906 68.077494 71.161831V152.983133L1024 429.746892v526.10159A68.23788 68.23788 0 0 1 955.848482 1024z" fill="#25467A" p-id="6842"></path><path d="M830.303614 166.060723L691.890892 442.812145v525.830168h264.019277a12.793831 12.793831 0 0 0 12.793831-12.793831V442.812145z" fill="#C2DBF4" p-id="6843"></path><path d="M830.303614 71.174169v94.886554H193.696386V71.174169c0-8.697831 5.72453-15.816482 12.732144-15.816482h611.068916c7.044627 0 12.806169 7.118651 12.806168 15.816482zM55.357687 442.812145v512.690891c0 7.254361 5.477783 13.139277 12.23865 13.139277h624.26988V442.812145z" fill="#F7F7F7" p-id="6844"></path><path d="M373.624289 774.921253A69.274217 69.274217 0 0 1 304.436434 705.696386a13.842506 13.842506 0 1 1 27.672674 0 41.515181 41.515181 0 0 0 83.030362 0 13.842506 13.842506 0 1 1 27.672675 0 69.274217 69.274217 0 0 1-69.187856 69.224867z" fill="#25467A" p-id="6845"></path><path d="M235.236241 595.018024m-41.515181 0a41.515181 41.515181 0 1 0 83.030362 0 41.515181 41.515181 0 1 0-83.030362 0Z" fill="#25467A" p-id="6846"></path><path d="M512 595.018024m-41.515181 0a41.515181 41.515181 0 1 0 83.030362 0 41.515181 41.515181 0 1 0-83.030362 0Z" fill="#25467A" p-id="6847"></path><path d="M179.890892 664.218217H124.607229a27.672675 27.672675 0 1 0 0 55.345349h55.345349a27.672675 27.672675 0 1 0 0-55.345349zM622.703036 664.218217h-55.357687a27.672675 27.672675 0 0 0 0 55.345349h55.357687a27.672675 27.672675 0 1 0 0-55.345349z" fill="#95C4F3" p-id="6848"></path><path d="M830.266602 166.048386L691.878554 442.812145H55.345349l138.388049-276.763759h636.533204z" fill="#FFFFFF" p-id="6849"></path><path d="M203.566265 339.277108l46.005976-98.698795h-15.989205l7.673831-16.458024h45.438458l-7.11865 90.198362 77.379855-90.198362h45.907277L395.189976 240.578313h-16.038554L333.108434 339.277108h16.038554l-7.673831 16.458025h-49.978603l7.673832-16.458025h15.841156l46.005976-98.698795-100.11759 116.464579h-3.91094l8.956916-116.464579-46.005976 98.698795h14.595084l-7.673831 16.458025h-46.968289L187.527711 339.277108zM374.389205 339.277108l46.005976-98.698795h-14.323663l7.673831-16.458024h48.695518L454.767036 240.578313H440.443373l-46.005975 98.698795h14.323662l-7.673831 16.458025h-48.695518l7.673831-16.458025zM435.002602 339.277108l46.005976-98.698795H463.884337l7.673832-16.458024h54.284337L518.168675 240.578313h-16.346988l-46.005976 98.698795h40.713253l20.862458-44.747566h18.666409l-28.548626 61.205591h-97.354024l7.673831-16.458025zM537.044819 339.277108l46.005976-98.698795h-16.606072l7.673831-16.458024h53.741494L620.186217 240.578313h-17.087229l-46.005976 98.698795h15.273639l-7.673832 16.458025h-51.927903l7.673831-16.458025z m45.438458-53.050602l63.858121-45.648193h-15.17494l7.673831-16.458024H690.891566L683.19306 240.578313h-14.126265l-62.167903 45.648193 17.272289 53.050602h14.224964l-7.673832 16.458025h-53.901879l7.673831-16.458025h14.311325z" fill="#009BEF" p-id="6850"></path></svg></a>';
	
	let a1 = document.createElement("div");
	a1.className = "bicon";
	a1.innerHTML = '<a title="一键续牌" href="javascript:window.continueFans();"><svg t="1577980064184" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2311" width="24" height="24"><path d="M858.6 99.1h-705c-33 0-60 27-60 60v705c0 33 27 60 60 60h705c33 0 60-27 60-60v-705c0-33-27-60-60-60z m-419.1 175h142.9v-64.4h46.2v64.4h144.7v41.3H628.6v61.4h173.3v41.3c-18.6 35.7-37.7 67.1-57.2 94.2-15.8-7.3-30.4-12.8-43.8-16.4 19.5-25.9 36.5-51.9 51.1-77.8H415.8v-41.3h166.6v-61.4H439.5v-41.3z m26.2 194l24.9-29.2c32.4 18.2 62.6 38.7 90.6 61.4l-27.4 32.8c-25.9-21-55.3-42.7-88.1-65z m73.5 104l-28 33.4c-18.2-17.4-47.6-40.7-88.2-69.9l24.3-28.6c39.8 24.7 70.4 46.4 91.9 65.1z m-233.4-360l46.2 17c-36.5 71.3-68.9 130.3-97.3 176.9 21.5 0 46-0.4 73.6-1.2 14.2-25.9 29.2-54.7 45-86.3l42.6 20.1c-51.5 91.2-97.7 166-138.6 224.4 44.2-4.1 85.5-8.9 124-14.6-1.6 17.4-3 31.2-4.3 41.3-47.4 5.7-105 13.4-172.7 23.1l-9.7-44.4c25.1-21.5 55.9-63.2 92.4-125.2-37.3 2.4-67.5 4.7-90.6 6.7l-12.2-40.1c30.8-42.2 64.7-108.1 101.6-197.7z m-97.3 496.8c63.6-10.5 129.1-22.7 196.4-36.5-1.6 21.9-2.4 36.9-2.4 45-59.2 11.8-119.4 24.3-180.6 37.7l-13.4-46.2z m565.4 100.9C726.1 768 673 727.3 614.6 687.6c-36.5 57.2-102.1 99.1-197 125.9-6.9-13.8-15.4-28-25.5-42.6 99.7-27.2 162.5-65.5 188.5-114.9H413.4v-41.3h183c9.3-37.3 13.6-95.7 12.8-175.1h44.4c0 77-3.9 135.4-11.6 175.1h160.5V656H642c55.5 36.9 110.9 75.6 166 116.1l-34.1 37.7z" fill="#FD8824" p-id="2312"></path></svg></a>';
	
	let b = document.getElementsByClassName("PlayerToolbar-Wealth")[0];
	b.insertBefore(a, b.childNodes[0]);
	b.insertBefore(a1, b.childNodes[0]);
	
}


function getBarrageColorArr() {
	// 获取已解锁的弹幕颜色
	barrageColorArr.length = 0;// 清空数组
	barrageColorLength = 0;
	let a = document.getElementsByClassName("FansBarrageColor-item");
	if (a.length == 0) {
		isMatch = true;
		let b = document.getElementsByClassName("MatchSystemFansBarrageSwitcher")[0];
		if (b != undefined) {
			b.click();
			a = document.getElementsByClassName("MatchSystemFansBarrageColor-item");
		} else {
			isMatch = false;
		}
		
	} else {
		isMatch = false;
	}
	
	for (let i = 0; i < a.length; i++) {
		let itemClassName = a[i].className;
		if (itemClassName.indexOf("is-lock") == -1) {
			barrageColorArr.push(i);
			barrageColorLength++;
		}
	}
	barrageColorLength = barrageColorLength - 1;
	
}

function getBarrageArr() {
	// 获取即将发送的弹幕数组
	barrageArr.length = 0;
	barrageLength = 0;
	let a = document.getElementById("bloop__textarea").value;
	barrageArr = a.split("\n");
	barrageLength = barrageArr.length - 1;
	
}

function selectBarrageColor(index) {
	// 选择粉丝弹幕
	let a;
	if (isMatch == false) {
		a = document.getElementsByClassName("FansBarrageColor-item")[index];
	} else{
		document.getElementsByClassName("MatchSystemFansBarrageSwitcher")[0].click()
		a = document.getElementsByClassName("MatchSystemFansBarrageColor-item")[index];
	}
	
	if (a != undefined) {
		a.click();
	}
}
function sendBarrage(text) {
	// 发送弹幕
	document.getElementsByClassName("ChatSend-txt")[0].value = text;
	document.getElementsByClassName("ChatSend-button")[0].click();
}

function getSpeed() {
	return document.getElementById("bloop__text_speed").value;
}

function saveData() {
	let data = {
		text: document.getElementById("bloop__textarea").value,
		speed: getSpeed(),
		isChangeColor: isChangeColor,
	}
	
	localStorage.setItem("bloop_save", JSON.stringify(data)); // 存储弹幕列表
}



function sendGift(gid, count, rid) {
	// gid: 268是荧光棒
	// count: 数量
	// rid: 房间号
	
	return fetch("https://www.douyu.com/japi/prop/donate/mainsite/v1", {
		method: 'POST',
		mode: 'no-cors',
		credentials: 'include',
		headers: {'Content-Type': 'application/x-www-form-urlencoded'},
		body: 'propId=' + gid + '&propCount=' + count + '&roomId=' + rid + '&bizExt=%7B%22yzxq%22%3A%7B%7D%7D'
	}).then(res => {
		return res.json();
	})
}

function initFunc() {
	// 函数初始化
	// 将onclick事件绑定在这里
	window.showDom = function() {
		let a = document.getElementsByClassName("bloop")[0];
		if (a.style.display != "block") {
			a.style.display = "block";
		} else {
			a.style.display = "none";
		}
	}
	window.changeColor = function() {
		isChangeColor = document.getElementById("bloop__checkbox_changeColor").checked;
	}
	
	window.startSend = function() {
		let ischecked = document.getElementById("bloop__checkbox_startSend").checked;
		if (ischecked == true) {
			// 开始发送
			barrageOffset = 0;
			barrageColorOffset = 0;
			getBarrageArr();
			getBarrageColorArr();
			saveData();
			timer = setInterval(() => {
				if (isChangeColor == true) {
					selectBarrageColor(barrageColorOffset);
					barrageColorOffset++;
					if (barrageColorOffset > barrageColorLength) {
						barrageColorOffset = 0;
					}
				}
				sendBarrage(barrageArr[barrageOffset]);
				barrageOffset++;
				if (barrageOffset > barrageLength) {
					barrageOffset = 0;
				}
				
			}, getSpeed());
		} else{
			// 停止发送
			clearInterval(timer);
		}
	}
	
	window.continueFans = function() {
		
		fetch('https://www.douyu.com/member/cp/getFansBadgeList',{
			method: 'GET',
			mode: 'no-cors',
			cache: 'default',
			credentials: 'include',
		}).then(res => {
			return res.text();
		}).then(async (doc) => {
			doc = (new DOMParser()).parseFromString(doc, 'text/html');
			let a = doc.getElementsByClassName("fans-badge-list")[0].lastElementChild;
			let n = a.children.length;
			let alertText = "";
			for (let i = 0; i < n; i++) {
				let rid = a.children[i].getAttribute("data-fans-room"); // 获取房间号
				await sleep(200).then(() => {
					sendGift(268, 1, rid).then(data => {
						if (data.msg == "success") {
							alertText += rid + "赠送荧光棒成功\n";
							console.log(rid + "赠送一根荧光棒成功");
						} else{
							alertText += rid + "赠送失败\n";
							console.log(rid + "赠送失败");
							console.log(data);
						}
					}).catch(err => {
						alertText += rid + "赠送失败\n";
						console.log(rid + "赠送失败");
						console.log(err);
					})
				});
			}
			alert(alertText);
		})
		
		
	}
}

function initDom() {
	// Dom初始化
	addInfrastructure();
	insertModal();
	insertIcon();
	
}

function initSet() {
	// 设置初始化
	let ret = localStorage.getItem("bloop_save");
	if (ret != null) {
		let retJson = JSON.parse(ret);
		document.getElementById("bloop__textarea").value = retJson.text;
		document.getElementById("bloop__checkbox_changeColor").checked = retJson.isChangeColor;
		document.getElementById("bloop__text_speed").value = retJson.speed;
	}
	
}

(function() {
	
	let intID = setInterval(() => {
		if (typeof(document.getElementsByClassName("ChatToolBar")[0]) != "undefined") {
			setTimeout(() => {
				initFunc();
				initDom();
				initSet();
			}, 1000)
			
			
			clearInterval(intID);
		}
	},1000);
	
	
})()


function sleep(time) {
  return new Promise((resolve) => setTimeout(resolve, time));
}