Greasy Fork

Greasy Fork is available in English.

H2P: 斗鱼小工具

抽奖弹幕、关键词回复、抄袭弹幕、循环弹幕 ________ 黑暗模式、清爽模式、网页全屏、全屏 ________ 直播时长、真实人数、批量取关、自动签到、领取鱼塘、默认最低(高)画质、禁止滚动弹幕、自动静音、自动给有牌子的主播赠送一根荧光棒 ________ 开启快捷键

目前为 2020-05-07 提交的版本。查看 最新版本

// ==UserScript==
// @name			H2P: 斗鱼小工具
// @name:en        	Tools for Douyu written by H2P
// @name:zh         H2P: 斗鱼小工具
// @namespace		http://tampermonkey.net/
// @version			1.6.1
// @icon			http://www.douyutv.com/favicon.ico
// @description		抽奖弹幕、关键词回复、抄袭弹幕、循环弹幕 ________ 黑暗模式、清爽模式、网页全屏、全屏 ________ 直播时长、真实人数、批量取关、自动签到、领取鱼塘、默认最低(高)画质、禁止滚动弹幕、自动静音、自动给有牌子的主播赠送一根荧光棒 ________ 开启快捷键
// @description:en	lottery draw, keyword reply, copy barrage, loop barrage ________ dark mode, clear mdoe, full screen web page, full screen ________ batch cancellation of barrage, automatically check in, receive fishpond, default min(max) image quality, ban scrolling barrage, automatically mute, automatically present a fluorescent rod to anthor following ________ shortcut
// @description:zh	抽奖弹幕、关键词回复、抄袭弹幕、循环弹幕 ________ 黑暗模式、清爽模式(显示直播时长,真实人数)、网页全屏、全屏 ________ 批量取关、自动签到、领取鱼塘、默认最低(高)画质、禁止滚动弹幕、自动静音、自动给有牌子的主播赠送一根荧光棒 ________ 开启快捷键
// @author			H2P
// @compatible		chrome
// @require			https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
// @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/*
// @match			https://www.douyu.com/directory/myFollow
// @note			2019.03.18-V0.2.00 循环弹幕可以设置多条,随机发送;新增弹幕倒计时;界面美化一下?抽奖弹幕新增一种查询类型
// @note			2019.03.18-V0.3.00 界面修改;界面可隐藏;可以设置是否发送默认弹幕
// @note			2019.03.18-V0.3.01 小 BUG 修复
// @note			2019.03.19-V0.4.00 引入 JQuery 改写,还没改完;更新了弹幕抽奖元素获取(因为斗鱼改了);增加设置抽奖弹幕次数;发送弹幕时可以修改循环弹幕
// @note			2019.03.23-V0.4.01 完善了一下代码;完善了界面;修改了字体
// @note			2019.03.23-V0.5.00 添加了斗鱼清爽模式 : 隐藏部分、隐藏全部、删除元素
// @note			2019.03.23-V0.5.01 修缮清爽模式;添加自动领取观看鱼丸(不是鱼秀宝箱)
// @note			2019.03.24-V0.5.02 修缮自动领取观看鱼丸;修缮隐藏全部元素的返回按钮
// @note			2019.03.24-V0.5.03 修改介绍。。。
// @note			2019.03.26-V0.5.04 修缮自动领取观看鱼丸,如果无法领取则清除循环
// @note			2019.03.28-V0.5.05 解决 jQuery $ 冲突;清爽模式处理粉丝节
// @note			2019.03.31-V0.6.00 添加“功能自动化”设置面板
// @note			2019.03.31-V0.6.01 修改介绍
// @note			2019.04.02-V0.6.02 代码重写
// @note			2019.04.04-V0.6.03 添加抄袭弹幕;完善设置信息存储
// @note			2019.05.25-V0.6.04 完善清爽模式退出
// @note			2019.06.11-V0.6.05 更新斗鱼领取宝箱
// @note			2019.07.04-V0.7.00 聚合脚本图标;删去抽奖弹幕
// @note			2019.07.05-V0.7.01 添加抽奖弹幕;发送时间设定改为间隔时间,单位改为毫秒;修改循环弹幕会自动保存
// @note			2019.07.06-V0.7.02 小小修缮
// @note			2019.07.06-V0.7.03 发送弹幕时间在间隔内随机
// @note			2019.07.06-V0.7.04 更新介绍(我觉得我输在介绍不够长、不够骚)
// @note			2019.07.06-V0.7.05 自动领鱼丸更新;抽奖弹幕更新(感谢 beacoolguy 的反馈)
// @note			2019.07.06-V0.7.06 自动点击抽奖弹幕“一键参与”(仅限发弹幕抽奖);清爽模式屏蔽贵族弹幕
// @note			2019.07.09-V0.7.07 抽奖弹幕“一键参与”(仅限条件 : 发弹幕和关注主播);样式修改;新功能(关键词自动回复展望)
// @note			2019.07.09-V0.7.08 清爽模式针对“topic”直播间和大屏幕优化
// @note			2019.07.11-V0.7.09 添加关键词回复(目前只能设置关键词和回复,无法使用)
// @note			2019.07.14-V0.8.00 关键词回复可以使用啦!!!(最多五条关键词)
// @note			2019.07.22-V0.8.01 修复关键词回复
// @note			2019.08.02-V0.8.02 弹幕抽奖增加拥有粉丝牌的抽奖条件
// @note			2019.08.12-V0.8.03 弹幕抽奖完善拥有粉丝牌的抽奖条件;部分清爽模式修改
// @note			2019.08.13-V0.8.04 清爽模式部分隐藏修缮
// @note			2019.08.16-V0.8.05 清爽模式修缮
// @note			2019.08.17-V0.8.06 清爽模式部分隐藏修缮
// @note			2019.08.26-V0.8.07 清爽模式添加宽屏模式;ESC 快捷退出清爽模式
// @note			2019.08.26-V0.8.08 清爽模式位置更换
// @note			2019.09.05-V0.8.09 修缮关键词回复对于有粉丝牌无效的问题
// @note			2019.09.08-V0.9.00 关键词回复可以添加和删除;新一轮抽奖开启后清除上一轮抽奖弹幕内容
// @note			2019.09.10-V0.9.01 解决初始化失败的问题
// @note			2019.09.10-V0.9.02 解决关键词回复自己弹幕的问题
// @note			2019.09.10-V0.9.03 解决初始化失败的问题
// @note			2019.09.12-V0.9.04 在主播公司旁显示直播时长
// @note			2019.09.14-V1.0.00 Vue 重写自动发送弹幕和自动化配置界面;取消默认弹幕,抄袭弹幕增加抄袭间隔;取消显示直播时长
// @note			2019.09.14-V1.0.01 更新介绍
// @note			2019.09.14-V1.0.02 修复弹幕抽奖不工作;添加删除无关元素
// @note			2019.09.14-V1.0.03 修复弹幕抽奖不工作;Vue 重写清爽模式
// @note			2019.09.14-V1.0.04 修复关键词回复无法自动配置的问题;添加保留词 {showT} 用于替换主播直播时长
// @note			2019.09.15-V1.0.05 将主播直播时长保存在本地;修复 {showT} 替换失败问题
// @note			2019.09.15-V1.0.06 修复抽奖弹幕赠送 666 的问题
// @note			2019.09.16-V1.0.07 设置抄袭弹幕和循环弹幕优先级相同
// @note			2019.09.16-V1.0.08 解决 topic 房间 id 获取失败的问题
// @note			2019.09.24-V1.0.09 清除分区冠军赛;自动最低(高)画质
// @note			2019.09.24-V1.1.00 自动参与火力全开;解决自动签到、领取鱼丸一直检测的问题
// @note			2019.09.25-V1.1.01 更新自动领取鱼丸;解决处于发送等待期尝试发送弹幕的问题;领取鱼丸发送弹幕任务无法完成
// @note			2019.09.25-V1.1.02 添加在电脑面前检测
// @note			2019.09.28-V1.1.03 修复删除元素后宽屏导致礼物栏显示空白的问题
// @note			2019.10.06-V1.1.04 清爽模式增加单独处理弹幕栏;清爽信息栏还未实现
// @note			2019.10.07-V1.1.05 优化清爽模式;全屏模式、网页全屏已失效
// @note			2019.10.07-V1.1.06 解决宽屏模式白屏的问题;添加清爽模式功能;全屏模式、网页全屏在 Mac Chrome 会失效
// @note			2019.10.08-V1.1.07 优化清爽模式按键;新增删除元素解决内存溢出
// @note			2019.10.08-V1.1.08 修改介绍
// @note			2019.10.13-V1.1.09 普通直播间关灯模式优化;topic 房间清爽模式播放器和删除元素优化
// @note			2019.10.14-V1.1.10 优化 topic 房间和大屏关灯模式
// @note			2019.10.14-V1.2.01 优化脚本界面;添加脚本清爽,页面加载时即可清爽
// @note			2019.10.14-V1.2.02 修改介绍
// @note			2019.10.15-V1.2.03 修复设置版面清爽模式启动后无限触发的问题;修复脚本清爽无法启动的问题
// @note			2019.10.15-V1.2.04 优化关灯模式;针对有背景直播间优化;静音、关闭弹幕自动化
// @note			2019.10.16-V1.2.05 修改介绍
// @note			2019.10.16-V1.2.06 更新快捷键(Shift + a : 打开发送弹幕界面;Shift + s : 打开清爽模式界面;Shift + d : 打开自动设置界面)
// @note			2019.10.17-V1.2.07 修改按钮配色
// @note			2019.10.19-V1.3.01 弹幕栏清爽后显示直播间热度和直播时长;优化脚本清爽(针对有背景图片的直播间)
// @note			2019.10.19-V1.3.02 脚本清爽普通直播间白屏问题
// @note			2019.10.19-V1.3.03 脚本清爽有背景的普通直播间白屏问题;完善主播直播时间获取;弹幕栏清爽(去除标签)
// @note			2019.10.19-V1.3.04 完善弹幕栏清爽(去除背景颜色)
// @note			2019.10.20-V1.3.05 解决脚本清爽启动消除弹幕栏清爽的 BUG
// @note			2019.10.24-V1.3.06 增加显示真实人数
// @note			2019.10.24-V1.3.07 增加显示真实人数
// @note			2019.10.24-V1.3.08 修复真实人数 BUG
// @note			2019.11.11-V1.3.09 弹幕抽奖更新;真实人数更新
// @note			2019.11.13-V1.3.10 签到后关闭弹出的框;宽屏模式显示竞猜
// @note			2019.11.15-V1.3.11 修复抽奖弹幕会复制“复制”两个字的问题
// @note			2019.11.17-V1.3.12 清爽模式和宽屏模式优化
// @note			2019.11.24-V1.3.13 关灯模式优化
// @note			2019.12.10-V1.4.01 批量取关
// @note			2019.12.29-V1.4.02 清爽模式自定义;快捷键清除弹幕(Shift + c);清爽模式快捷键(Shift + u/i/o/p);礼物栏清爽优化
// @note			2020.04.16-V1.4.03 清爽模式信息栏、弹幕栏、播放器更新(有背景的直播间播放器还未更新)
// @note			2020.04.16-V1.4.04 清爽模式信息栏优化
// @note			2020.04.26-V1.4.05 代码修改
// @note			2020.04.27-V1.4.06 自动给有牌子的主播赠送一根荧光棒
// @note			2020.04.28-V1.4.07 发送弹幕部分使用原生 JS 重写
// @note			2020.04.29-V1.4.08 弹幕栏清爽模式优化
// @note			2020.04.29-V1.4.09 关灯模式改为黑暗模式
// @note			2020.04.29-V1.4.10 黑暗模式需要手动开启
// @note			2020.04.30-V1.5.01 黑暗模式优化,且可以自动开启
// @note			2020.04.30-V1.5.02 网页打开就是黑暗模式,无需加载原来的样式
// @note			2020.04.30-V1.5.03 黑暗模式优化
// @note			2020.04.30-V1.5.04 黑暗模式优化
// @note			2020.04.30-V1.5.05 脚本清爽礼物栏优化
// @note			2020.04.30-V1.5.06 修复关键词回复 BUG
// @note			2020.04.30-V1.5.07 修复抽奖弹幕 BUG
// @note			2020.05.05-V1.5.08 清爽模式优化,页面加载过程中即可隐藏元素
// @note			2020.05.05-V1.5.09 清爽模式优化
// @note			2020.05.07-V1.6.00 代码重写完毕,不依赖于 jQuery 和 Vue
// @note			2020.05.07-V1.6.01 修复抽奖弹幕提取失败的问题
// ==/UserScript==

(() => {
	'use strict';

	const $H2P = function (xpath, one = true) {
        if (one) { return document.querySelector(xpath); }
        else { return Array.from(document.querySelectorAll(xpath)); }
    }

	const isTopic = window.location.href.startsWith('https://www.douyu.com/topic/');
	const isFollowList = window.location.href.startsWith('https://www.douyu.com/directory/myFollow');
	
	localStorage.removeItem('h2p-DYScript-configPre');
	localStorage.removeItem('h2p-DYScript-config');








// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// 
// 															取消关注
// 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	if (isFollowList){
		let anchorsSelected = [];
		
		new Promise((resolve, reject) => {
			let INVL_AddBtnCancelFollow = setInterval(() => {
				if ($H2P('div#filter-tab-expandable-wrapper') && !$H2P('a#h2p-a-cancelFollow')) {
					window.clearInterval(INVL_AddBtnCancelFollow);
					INVL_AddBtnCancelFollow = null;
					resolve();
				}
			}, 500);
		})
		.then(() => {
			let a_cancelFollow = document.createElement('a');
			a_cancelFollow.id = 'h2p-a-cancelFollow';
			a_cancelFollow.className = 'layout-Module-label';
			a_cancelFollow.innerHTML = `
				<strong>取消关注</strong>
			`;
			$H2P('div#filter-tab-expandable-wrapper').append(a_cancelFollow);
		})
		.then(() => {
			$H2P('a#h2p-a-cancelFollow').addEventListener('click', () => {
				let anchorSelected = $H2P('li.layout-Cover-item div.DyLiveCover-selectArea.is-active', false);
				anchorSelected.forEach(anchor => {
					let anchorHref = anchor.nextSibling.href;
					if (!anchorHref || anchorHref.length == 0) {
						anchorHref = anchor.parentNode.href;
					}
					let anchorId = anchorHref.split('/').pop();
					anchorsSelected.push(anchorId);
				});
				console.log(anchorsSelected);
				setTO_cancelFollow();
			});
		})
		.catch(error => { console.log(error); })
		
		function setTO_cancelFollow () {
			if (anchorsSelected && anchorsSelected.length > 0) {
				for (let i = 0; i < anchorsSelected.length; i++) {
					let anchorId = anchorsSelected[i];
					setTimeout(() => {
						cancelFollow(anchorId);
					}, (i + 1) * 1000);
				}
			}
		}

		function cancelFollow (anchorId) {
			fetch(`https://www.douyu.com/room/follow/cancel_confuse/${anchorId}`, {
				method: 'POST'
			})
			.then(res => res.json())
			.then(res => {
				if (res && 'error' in res && res.error === 0) {
					console.log(`成功取消关注主播 : ${anchorId}`);
					let parentEle = $H2P(`a[href="/${anchorId}"]`).parentNode;
					// 从主播 id 找到主播信息所在 ele 的根节点
					while (!parentEle.classList.contains('layout-Cover-item') && parentEle.tagName.toLowerCase() !== 'body') {
						parentEle = parentEle.parentNode;
					}
					if (parentEle.classList.contains('layout-Cover-item') && parentEle.tagName.toLowerCase() !== 'body') {
						parentEle.remove();
					}
				} else {
					console.log(`取消关注主播 : ${anchorId} 失败`);
				}
			});
		}
		return;
	}








// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// 
// 															全局变量
// 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	// 用户拥有牌子的主播信息
	let roomOfAnchorFan = undefined;

	let userInfo = {
		nickName	: '',				// 昵称
		isAnchorFan : false,			// 是否拥有主播的粉丝牌
	};	

	let roomInfo = {
		id		: '',
		showT	: 0,
		online	: 0,
	}








// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// 
// 															主播信息获取
// 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	const LSInfo = 'h2p-DY-config-info';
	let config_info = JSON.parse(localStorage.getItem(LSInfo)) || {
		showTs: {},
	};

	// 获取 roomInfo.id
	let regNums = /\d+/;
	if (regNums.test($H2P('head > title').textContent)) {
		roomInfo.id = regNums.exec($H2P('head > title').textContent)[0];
	} else {
		roomInfo.id = regNums.exec(window.location.href)[0];
	}

	// 获取在线人数
	let urlId = isTopic ? window.location.href.split('=').pop() : window.location.pathname.split('/').pop();
	fetch(`https://bojianger.com/data/api/common/search.do?keyword=${urlId}`)
	.then(res => res.json())
	.then(res => {
		try {
			if (res.data) {
				if (res.data.online) { roomInfo.online = Number(res.data.online); }
				else if (res.data.anchorVo) { roomInfo.online = Number(res.data.anchorVo.audience_count); }
			} else {
				let res = JSON.parse(JSON.stringify(res));
				roomInfo.online = Number(res.split('online":')[1].split(',')[0]);
			}
			console.log(`Succeed getting online : ${roomInfo.online}.`);
		} catch (error) {
			console.log(error);
			console.log('Fail to get online');
		}
	});

	// 获取直播时间
	let showTs = {};
	if (Array.isArray(config_info.showTs)) {
		config_info.showTs = {};
		localStorage.setItem(LSInfo, JSON.stringify(config_info));
	} else { showTs = config_info.showTs || {}; }
	let [showT, getT] = [0, 0];
	if (showTs[roomInfo.id]) {
		showT = showTs[roomInfo.id].showT;
		getT = showTs[roomInfo.id].getT;
	}
	// 获取时间 < 6h
	if ((((new Date().getTime() / 1000) - getT) / 3600.0) < 6) {
		roomInfo.showT = showT;
		console.log(`Succeed getting anchor showTime : ${roomInfo.showT}.`);
	} else {
		fetch('https://www.douyu.com/betard/' + roomInfo.id)
		.then(res => res.json())
		.then(res => {
			try {
				if (res) {
					if (res.cache_time) {
						roomInfo.showT = Number.parseInt(res.cache_time);
					} else {
						let r = res.split('"cache_time":')[1];
						let l = r.substr(0, r.indexOf(','));
						roomInfo.showT = Number.parseInt(l);
					}
					config_info.showTs[roomInfo.id] = {
						'showT' : roomInfo.showT,
						"getT" : Number.parseInt(new Date().getTime() / 1000)
					};
					console.log(`Succeed getting anchor showTime : `);
					console.log(config_info.showTs[roomInfo.id]);
					localStorage.setItem(LSInfo, JSON.stringify(config_info));
				} else { console.log('Fail to get anchor showTime.') }
			} catch (error) {
				console.log(error);
				console.log('Fail to get anchor showTime.')
			}
		});
	}

    // 根据 cookie 获取用户昵称
	let cookies = document.cookie.split(/;\s/g);
	for (let i = 0; i < cookies.length; i++) {
		let cookie = cookies[i];
		let keyVal = cookie.split('=');
		if (keyVal && keyVal.length == 2 && keyVal[0] == 'acf_nickname') {
			userInfo.nickName = keyVal[1];
			break;
		}
	}

	// 自动获取已有徽章的主播
	new Promise((resolve, reject) => {
		let iframe = document.createElement('iframe');
		iframe.id = 'h2p-fansBadgeList';
		iframe.style = 'display: none;'
		iframe.src = '/member/cp/getFansBadgeList';
		document.body.appendChild(iframe);
		setTimeout(resolve, 250);
	})
	.then(() => {
		let iframe = $H2P('iframe#h2p-fansBadgeList');
		iframe.addEventListener('load', () => {
			// 获取有粉丝牌的主播房间号
			roomOfAnchorFan = {};
			let idoc = iframe.contentWindow.document;
			let ele_anchors = Array.from(idoc.querySelectorAll('table.aui_room_table.fans-badge-list > tbody > tr'));
			for ( let i = 0; i < ele_anchors.length; i++ ) {
				let ele = ele_anchors[i];
				let anchorURL = ele.querySelector('td:nth-child(2)').querySelector('a').getAttribute('href');
				let anchorName = ele.querySelector('td:nth-child(2)').querySelector('a').textContent;
				let anchorRoom = ele.getAttribute('data-fans-room');
				let anchorUp = Number(ele.querySelector('td:nth-child(4)').querySelector('span').textContent);
				roomOfAnchorFan[anchorRoom] = {anchorName, anchorURL, anchorUp};
			}
			console.log('有粉丝牌的主播房间号');
			console.log(roomOfAnchorFan);
			let anchorRoom= window.location.href.split('/').pop();
			userInfo.isAnchorFan = anchorRoom in roomOfAnchorFan;
			setTimeout(() => { $H2P('iframe#h2p-fansBadgeList').remove(); }, 2000)
		});
	})
	.catch(error => console.log(error));








// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// 
// 															🐯和面板初始化
// 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	let viewShow_bar	=  false;
	let viewShow_clear	=  false;
	let viewShow_config	=  false;
	let viewShow_script	=  false;

	new Promise((resolve, reject) => {
		// 创建元素样式
		let eleStyle = document.createElement('style');
		eleStyle.type = 'text/css';
		eleStyle.innerHTML = `
			#h2p-div-sign {
				width			: 18px;
				height			: 18px;
				display			: inline-block;
				vertical-align 	: middle;
			}
			#h2p-div-sign span {
				font-size		: 18px;
				cursor			: pointer;
			}

			#div-DYScript input, #div-DYScript button, #div-DYScript select {
				outline			: none;
				line-height		: 10px;
			}
			#div-DYScript {
				position 		: absolute;
				bottom 			: 1px;
				min-width 		: 335px;
				max-width 		: 335px;
				border 			: none;
				margin 			: 0 0 0 -1px;
				box-shadow		: #c7c7c7 0 -5px 5px 0;
				display         : flex;
				flex-flow       : row wrap;
				z-index 		: 999;
			}
			#div-DYScript .h2p-div-inlinepanel {
				min-width 		: 315px;
				max-width 		: 315px;
				padding 		: 10px;
				border-width	: 0 0 1px 0;
				font-family		: WeibeiSC-Bold, STKaiti;
				font-size		: 16px;
				background		: #f5f5f5;
			}

			.h2p-flex-main-center {
				height          : 22px;
				margin          : 0 0 14px 0;
				display         : flex;
				flex-flow       : row wrap;
				justify-content : center;
				align-items     : center;
			}
			.h2p-flex-main-start {
				height          : 22px;
				margin          : 0 0 15px 0;
				display         : flex;
				flex-flow		: row wrap;
				justify-content : flex-start;
				align-items     : center;
			}
			.h2p-flex-main-end {
				height          : 22px;
				margin          : 0 0 15px 0;
				display         : flex;
				flex-flow		: row wrap;
				justify-content : flex-end;
				align-items     : center;
			}

			.h2p-item-100p {
				width           : 100%;
			}
			.h2p-item-75p {
				width           : 75%;
			}
			.h2p-item-50p {
				width           : 50%;
			}
			.h2p-item-33p {
				width           : 33.33%;
			}
			.h2p-item-25p {
				width           : 25%;
			}

			#div-DYScript .h2p-div-inlinetab {
				min-width 		: 335px;
				max-width 		: 335px;
				border-top		: 1px solid #DCDCDC;
				border-radius	: 2px;
				font-family		: WeibeiSC-Bold, STKaiti;
				font-size		: 16px;
				background		: #f5f5f5;
				display         : flex;
				flex-flow       : row wrap;
			}
			#div-DYScript .h2p-div-layer {
				position	: relative;
				width		: 100%;
				height		: 24px;
			}
			#div-DYScript .h2p-div-layer-half {
				position	: absolute;
				width		: 50%;
				height		: 24px;
			}
			#div-DYScript .h2p-input-normal {
				height			: 22px;
				padding			: 0px 5px;
				border			: 1px solid #708090;
				border-radius	: 5px;
				font-size		: 13px;
			}
			#div-DYScript .h2p-input-disable {
				background		: #DCDCDC;
				cursor			: default;
			}
			#div-DYScript .h2p-input-able {
				background		: white;
				cursor			: text;
			}
			#div-DYScript .h2p-div-tab {
				width			: 33.3%;
				max-height		: 29px;
				padding			: 2px 0;
				text-align		: center;
			}
			#div-DYScript .h2p-div-tab:hover {
				cursor			: pointer;
				background		: #DDDDDD;
			}
			#div-DYScript .h2p-hover-pointer:hover {
				cursor			: pointer;
				background		: #DDDDDD;
			}
			.h2p-bg-close	{ background : #00ddbb }
			.h2p-bg-close:hover{ background : #00ccaa }
			.h2p-bg-open	{ background : #99aaff }
			.h2p-bg-open:hover	{ background : #8899cc }
		`;
		document.head.appendChild(eleStyle);

		// 弹幕框上的 🐯
		let div_sign = document.createElement('div');
		div_sign.id = 'h2p-div-sign';
		div_sign.style = 'margin: -8px 0 0 -3px;';
		div_sign.title = '斗鱼脚本';
		div_sign.innerHTML = `<span id="h2p-span-DYScript">🐯</span>`;
		
		
		// 整个面板 ===============================================================
		let div_DYScript = document.createElement('div');
		div_DYScript.id = 'div-DYScript';
		div_DYScript.style = 'display: none;';

		// 检查弹幕面板挂载点(斗鱼弹幕显示区域)是否加载完成
		// 检查弹幕图标挂载点(斗鱼弹幕输入框)是否加载完成
		let check_mountPoint_barPanel = setInterval(() => {
			if ($H2P('div.layout-Player-asideMainTop') && $H2P('div.BarrageSuperLink') && $H2P('div.ChatToolBar')) {
				window.clearInterval(check_mountPoint_barPanel);
				check_mountPoint_barPanel = null;
				setTimeout(() => {
					$H2P('div.layout-Player-asideMainTop').appendChild(div_DYScript);
					$H2P('div.ChatToolBar').appendChild(div_sign);
					resolve();
				}, 2000);
			} else if (!window.location.href.includes('douyu')) {
				window.clearInterval(check_mountPoint_barPanel);
				check_mountPoint_barPanel = null;
				document.body.appendChild(div_DYScript);
				document.body.appendChild(div_sign);
				resolve();
			}
		}, 1000);
	})
	.then(() => {
		$H2P('span#h2p-span-DYScript').addEventListener('click', () => {
			viewShow_script = !viewShow_script;
			$H2P('div#div-DYScript').style.display = viewShow_script ? '' : 'none';
		});
	})
	.then(() => {
		let div_DYScriptTab = document.createElement('div');
		div_DYScriptTab.id = 'div-DYScriptTab';
		div_DYScriptTab.className = 'h2p-div-inlinetab';
		div_DYScriptTab.style = 'order: 20;'
		div_DYScriptTab.innerHTML = `
			<div id="h2p-div-tab-bar" class="h2p-div-tab" style="background: #DDDDDD;" title="发弹幕">📢</div>
			<div id="h2p-div-tab-clear" class="h2p-div-tab" style="width: 33.4%" title="清爽模式">✡️</div>
			<div id="h2p-div-tab-config" class="h2p-div-tab" title="自动化设置">⏲️</div>
		`;
		$H2P('div#div-DYScript').appendChild(div_DYScriptTab);
	})
	.then(() => {
		$H2P('div#div-DYScriptTab').addEventListener('click', (event) => {
			$H2P('div#h2p-div-bar').style.display = 'none';
			$H2P('div#h2p-div-clear').style.display = 'none';
			$H2P('div#h2p-div-config').style.display = 'none';
			viewShow_bar = false;
			viewShow_clear = false;
			viewShow_config = false;
			Array.from(event.currentTarget.children).forEach(ele => { ele.style.backgroundColor = '#f5f5f5'; });

			// 发弹幕
			if (event.target.id === 'h2p-div-tab-bar') {
				viewShow_bar = true;
				$H2P('div#h2p-div-bar').style.display = '';
				event.target.style.backgroundColor = '#DDDDDD';
			}
			// 清爽模式
			else if (event.target.id === 'h2p-div-tab-clear') {
				viewShow_clear = true;
				$H2P('div#h2p-div-clear').style.display = '';
				event.target.style.backgroundColor = '#DDDDDD';
			}
			// 自动化设置
			else if (event.target.id === 'h2p-div-tab-config') {
				viewShow_config = true;
				$H2P('div#h2p-div-config').style.display = '';
				event.target.style.backgroundColor = '#DDDDDD';
			}
		}, false);
	});








// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// 
// 															发弹幕
// 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	const LSChat = 'h2p-DY-config-chat';
	let config_chat_pre = {
		invlStart	: 3,
		invlEnd		: 4,
		isLuck		: false,
		isKeyRe		: false,
		keyReBar	: [],
		isCopy		: false,
		copyInvl	: 0,
		isLoop		: false,
		loopBar		: [],
		isSend		: false,
	};
	let config_chat = {};
	Object.assign(config_chat, config_chat_pre);
	let config_chat_tmp = JSON.parse(localStorage.getItem(LSChat)) || {};
	Object.assign(config_chat, config_chat_tmp);
	for (let key in config_chat) { if (!(key in config_chat_pre)) { delete config_chat[key]; } }
	localStorage.removeItem(LSChat);
	localStorage.setItem(LSChat, JSON.stringify(config_chat));

	let [Chat, INVL_SendBar, INVL_ShowCD] = [undefined, undefined, undefined];

	let luckBar	= '';				// 抽奖弹幕内容
	let luckCD	= 0;				// 弹幕抽奖活动倒计时
	let luckTime = 0;				// 抽奖弹幕发送次数
	let Index_keyRe = 0;			// 关键词回复弹幕列表已经检测的位置

	// 初始化自动发弹幕界面  ===============================================================
	new Promise((resolve, reject) => {
		let eleStyle = document.createElement('style');
		eleStyle.type = 'text/css';
		eleStyle.innerHTML = `
			#h2p-div-bar input[type="checkbox"] {
				margin			: 3px;
			}
			#h2p-div-bar .h2p-input-invl {
				width			: 23px;
    			margin			: 0 5px;
			}

			#h2p-div-bar .h2p-ta-bar-loopBar {
				width			: 283px;
				height			: 73px;
				padding			: 0 5px;
				border			: 1px solid #708090;
				border-radius	: 5px;
				font-size		: 13px;
				resize			: none;
			}

			#h2p-div-bar .h2p-btn-keyRe {
				width			: 16px;
				height			: 16px;
				padding			: 0;
				margin			: 3px;
				border			: 1px solid rgb(216, 216, 216);
				border-radius	: 50%;
				background-color: white;
				text-align		: center;
			}

			#h2p-div-bar #h2p-btn-bar-send {
				line-height: 18px;
				width: 100%;
				padding: 4px 0;
				border: none;
				border-radius: 5px;
				cursor: pointer;
				transition: all 0.5s
			}

			#h2p-div-bar .h2p-btn-active {
				background: #ffbb77!important;
			}

			.sendingDisabled {}
		`;
		document.head.appendChild(eleStyle);

		let div = document.createElement('div');
		div.id = 'h2p-div-bar';
		div.className = 'h2p-div-inlinepanel';
		div.style = '';
		div.innerHTML = `
			<!-- 发送弹幕的速度 And 倒计时 -->
			<div class="h2p-flex-main-center">
				<div class="h2p-flex-main-start h2p-item-50p">
					<label>间隔</label>
					<input id="h2p-input-bar-invl-start" class="h2p-input-normal h2p-input-invl sendingDisabled" placeholder="≥3" />
					<span>~</span>
					<input id="h2p-input-bar-invl-end" class="h2p-input-normal h2p-input-invl sendingDisabled" />
					<label>秒</label>
				</div>
				<div class="h2p-flex-main-end h2p-item-50p">
					<input id="h2p-input-cd" class="h2p-input-normal h2p-input-disable" style="width: 32px;" disabled/>
				</div>
			</div>

			<!-- 是否参加弹幕抽奖 -->
			<div class="h2p-flex-main-center">
				<div class="h2p-flex-main-start h2p-item-50p">
					<input id="h2p-input-bar-isLuck" type="checkbox" />
					<label>抽奖弹幕</label>
				</div>
				<div class="h2p-flex-main-end h2p-item-50p">
					<label>抽奖发送</label>
					<input id="h2p-input-bar-luck-time-now" class="h2p-input-normal h2p-input-invl h2p-input-disable" disabled />
					<span>/</span>
					<input id="h2p-input-bar-luck-time" class="h2p-input-normal h2p-input-invl sendingDisabled" style="margin-right: 0;" placeholder="≥1" value="1" />
				</div>
			</div>

			<!-- 是否使用关键词自动回复 -->
			<div class="h2p-flex-main-center" style="margin: 0 0 8px 0;">
				<div class="h2p-flex-main-start h2p-item-50p">
					<input id="h2p-input-bar-isKeyRe" type="checkbox" />
					<label>关键词回复</label>
					<button id="h2p-btn-addKeyRe" class="h2p-btn-keyRe h2p-hover-pointer" title="添加关键词">+</button>
				</div>
				<div class="h2p-flex-main-end h2p-item-50p">
					<select id="h2p-select-keyRe" style="width: 100%; height: 24px;">
					</select>
				</div>
			</div>

			<div class="h2p-flex-main-center">
				<div class="h2p-flex-main-start h2p-item-50p">
					<button id="h2p-btn-delKeyRe" class="h2p-btn-keyRe h2p-hover-pointer" title="删除关键词">-</button>
					<input id="h2p-input-key" class="h2p-input-normal" style="width: 70%;" placeholder="关键词" />
				</div>
				<div class="h2p-flex-main-end h2p-item-50p">
					<input id="h2p-input-re" class="h2p-input-normal" style="width: 90%; padding: 0 4.2%;" placeholder="自动回复弹幕" />
				</div>
			</div>

			<!-- 是否发送抄袭弹幕 -->
			<div class="h2p-flex-main-center">
				<div class="h2p-flex-main-start h2p-item-50p">
					<input id="h2p-input-bar-isCopy" type="checkbox" />
					<label>抄袭弹幕</label>
				</div>
				<div class="h2p-flex-main-end h2p-item-50p">
					<label>抄袭间隔</label>
					<input id="h2p-input-bar-copy-invl" class="h2p-input-normal" style="margin-left: 5px; width: 48px;" placeholder="0 ~ 200" value="0"/>
				</div>
			</div>

			<!-- 是否发送循环弹幕 -->
			<div class="h2p-flex-main-center" style="height: 75px;">
				<input id="h2p-input-bar-isLoop" type="checkbox" />
				<textarea id="h2p-ta-bar-loopBar" class="h2p-ta-bar-loopBar" placeholder="循环弹幕"></textarea>
			</div>

			<!-- 开启弹幕发送按钮 -->
			<div class="h2p-flex-main-center" style="margin: 0 0 5px 0;">
				<button id="h2p-btn-bar-send" class="h2p-bg-close">发送</button>
			</div>
		`;

		let setINVL_wait_div_DYScript = setInterval(() => {
			if ($H2P('div#div-DYScript')) {
				window.clearInterval(setINVL_wait_div_DYScript);
				setINVL_wait_div_DYScript = null;
				$H2P('div#div-DYScript').appendChild(div);
				resolve();
			}
		}, 500);
	})
	// 元素绑定监听
	.then(() => {
		let eleBar = $H2P('div#h2p-div-bar');
        eleBar.addEventListener('click', (event) => {
			let target = event.target;
			if (target.id === 'h2p-input-bar-isCopy') {
				config_chat.isCopy = target.checked;
			} else if (target.id === 'h2p-input-bar-isLoop') {
                config_chat.isLoop = target.checked;
            } else if (target.id === 'h2p-input-bar-isKeyRe') {
                config_chat.isKeyRe = target.checked;
            } else if (target.id === 'h2p-input-bar-isLuck') {
                config_chat.isLuck = target.checked;
            }
            localStorage.setItem(LSChat, JSON.stringify(config_chat));
		}, false)
			
		// 间隔最小值
		let eleInvlStart = $H2P('input#h2p-input-bar-invl-start');
		eleInvlStart.addEventListener('input', () => { eleInvlStart.value = eleInvlStart.value.slice(0, 3); });
		eleInvlStart.addEventListener('keyup', () => { eleInvlStart.value = eleInvlStart.value.replace(/[^\d]/g, ''); });
		eleInvlStart.addEventListener('focusout', () => {
			eleInvlStart.value = Math.max(eleInvlStart.value, 3);
			config_chat.invlStart = eleInvlStart.value;
			localStorage.setItem(LSChat, JSON.stringify(config_chat));
		});

		// 间隔最大值
		let eleInvlEnd = $H2P('input#h2p-input-bar-invl-end');
		eleInvlEnd.addEventListener('input', () => { eleInvlEnd.value = eleInvlEnd.value.slice(0, 3); });
		eleInvlEnd.addEventListener('keyup', () => { eleInvlEnd.value = eleInvlEnd.value.replace(/[^\d]/g, ''); });
		eleInvlEnd.addEventListener('focusout', () => {
			eleInvlEnd.value = Math.max(eleInvlEnd.value, Number(eleInvlStart.value) + 1, 4);
			config_chat.invlEnd = eleInvlEnd.value;
			localStorage.setItem(LSChat, JSON.stringify(config_chat));
		});

		// 抽奖弹幕最大次数
		let eleBarLuckTime = $H2P('input#h2p-input-bar-luck-time');
		eleBarLuckTime.addEventListener('input', () => { eleBarLuckTime.value = eleBarLuckTime.value.slice(0, 2); });
		eleBarLuckTime.addEventListener('keyup', () => { eleBarLuckTime.value = eleBarLuckTime.value.replace(/[^\d]/g, ''); });
		eleBarLuckTime.addEventListener('focusout', () => {
			eleBarCopyInvl.value = Math.max(eleBarCopyInvl.value, 1);
			config_chat.luckTime = Number(eleBarLuckTime.value);
			localStorage.setItem(LSChat, JSON.stringify(config_chat));
		});

		// 添加关键词回复
		let eleAddKeyRe = $H2P('button#h2p-btn-addKeyRe');
		eleAddKeyRe.addEventListener('click', () => {
			config_chat.keyReBar.push({key: 'default', re: 'default'});
			localStorage.setItem(LSChat, JSON.stringify(config_chat));
			$H2P('select#h2p-select-keyRe').options.add(new Option('default', 'default'));
			$H2P('select#h2p-select-keyRe').selectedIndex = config_chat.keyReBar.length - 1;
			$H2P('input#h2p-input-key').value = $H2P('select#h2p-select-keyRe').selectedOptions[0].textContent;
			$H2P('input#h2p-input-re').value = $H2P('select#h2p-select-keyRe').selectedOptions[0].value;
		});

		// 删除关键词回复
		let eleDelKeyRe = $H2P('button#h2p-btn-delKeyRe');
		eleDelKeyRe.addEventListener('click', () => {
			config_chat.keyReBar.splice($H2P('select#h2p-select-keyRe').selectedIndex, 1);
			localStorage.setItem(LSChat, JSON.stringify(config_chat));
			$H2P('select#h2p-select-keyRe').options.remove($H2P('select#h2p-select-keyRe').selectedIndex);
			$H2P('input#h2p-input-key').value = $H2P('select#h2p-select-keyRe').selectedOptions[0].textContent;
			$H2P('input#h2p-input-re').value = $H2P('select#h2p-select-keyRe').selectedOptions[0].value;
		});

		// 选择关键词回复
		let eleSelectKeyRe = $H2P('select#h2p-select-keyRe');
		eleSelectKeyRe.addEventListener('change', () => {
			$H2P('input#h2p-input-key').value = $H2P('select#h2p-select-keyRe').selectedOptions[0].textContent;
			$H2P('input#h2p-input-re').value = $H2P('select#h2p-select-keyRe').selectedOptions[0].value;
		});

		// 修改关键词
		let eleKey = $H2P('input#h2p-input-key');
		eleKey.addEventListener('keyup', () => {
			config_chat.keyReBar[$H2P('select#h2p-select-keyRe').selectedIndex].key = eleKey.value;
			$H2P('select#h2p-select-keyRe').selectedOptions[0].textContent = eleKey.value;
		});
		eleKey.addEventListener('focusout', () => {
			if (!eleKey.value) {
				eleKey.value = 'default';
				config_chat.keyReBar[$H2P('select#h2p-select-keyRe').selectedIndex].key = eleKey.value;
				$H2P('select#h2p-select-keyRe').selectedOptions[0].textContent = eleKey.value;
			}
			localStorage.setItem(LSChat, JSON.stringify(config_chat));
		});

		// 修改回复
		let eleRe = $H2P('input#h2p-input-re');
		eleRe.addEventListener('keyup', () => {
			config_chat.keyReBar[$H2P('select#h2p-select-keyRe').selectedIndex].re = eleRe.value;
			$H2P('select#h2p-select-keyRe').selectedOptions[0].value = eleRe.value;
		});
		eleRe.addEventListener('focusout', () => {
			if (!eleRe.value) {
				eleRe.value = 'default';
				config_chat.keyReBar[$H2P('select#h2p-select-keyRe').selectedIndex].re = eleRe.value;
				$H2P('select#h2p-select-keyRe').selectedOptions[0].value = eleRe.value;
			}
			localStorage.setItem(LSChat, JSON.stringify(config_chat));
		});

		// 抄袭弹幕最大间隔
		let eleBarCopyInvl = $H2P('input#h2p-input-bar-copy-invl');
		eleBarCopyInvl.addEventListener('input', () => { eleBarCopyInvl.value = eleBarCopyInvl.value.slice(0, 3); });
		eleBarCopyInvl.addEventListener('keyup', () => { eleBarCopyInvl.value = eleBarCopyInvl.value.replace(/[^\d]/g, ''); });
		eleBarCopyInvl.addEventListener('focusout', () => {
			eleBarCopyInvl.value = Math.min(eleBarCopyInvl.value, 200);
			config_chat.copyInvl = Number(eleBarCopyInvl.value);
			localStorage.setItem(LSChat, JSON.stringify(config_chat));
		});

		// 循环弹幕
		let eleLoop = $H2P('textarea#h2p-ta-bar-loopBar');
        eleLoop.addEventListener('focusout', () => {
            if (eleLoop.value && eleLoop.value.replace(/\s/g, '')) {
                config_chat.loopBar = eleLoop.value.split('\n');
                localStorage.setItem(LSChat, JSON.stringify(config_chat));
            }
		});

		// 发送按钮
		let eleSend = $H2P('button#h2p-btn-bar-send');
        eleSend.addEventListener('click', () => {
			config_chat.isSend = !config_chat.isSend;
			$H2P('div#h2p-div-tab-bar').textContent = config_chat.isSend ? '🔥' : '📢';
			$H2P('input.sendingDisabled', false).forEach(ele => {
				ele.classList.toggle('h2p-input-disable');
				ele.disabled = !ele.disabled;
			})
            if (config_chat.isSend) {
                setINVL_SendBar();
                eleSend.classList.add('h2p-bg-open');
				eleSend.textContent = "发送中";
            }
            else {
                window.clearTimeout(INVL_SendBar);
                INVL_SendBar = null;
                window.clearInterval(INVL_ShowCD);
				INVL_ShowCD = null;
				$H2P('input#h2p-input-cd').value = '';
				$H2P('input#h2p-input-bar-luck-time-now').value = '';
                eleSend.classList.remove('h2p-bg-open');
                eleSend.textContent = "发送";
            }
            localStorage.setItem(LSChat, JSON.stringify(config_chat));
        }, false)
	})
	.catch(error => console.log(error))
	// 读取配置参数
    .then(() => {
		$H2P('input#h2p-input-bar-isLuck').checked = config_chat.isLuck || false;
		$H2P('input#h2p-input-bar-luck-time').value = config_chat.luckTime || 1;

        $H2P('input#h2p-input-bar-invl-start').value = config_chat.invlStart || '';
		$H2P('input#h2p-input-bar-invl-end').value = config_chat.invlEnd || '';
		
		$H2P('input#h2p-input-bar-isKeyRe').checked = config_chat.isKeyRe || false;
		if (!config_chat.keyReBar || !Array.isArray(config_chat.keyReBar)) { config_chat.keyReBar = []; }
		for (let {key, re} of config_chat.keyReBar) { $H2P('select#h2p-select-keyRe').options.add(new Option(key, re)); }

		$H2P('input#h2p-input-bar-isCopy').checked = config_chat.isCopy || false;
		$H2P('input#h2p-input-bar-copy-invl').value = config_chat.copyInvl || '',

		$H2P('input#h2p-input-bar-isLoop').checked = config_chat.isLoop || false;
		$H2P('textarea#h2p-ta-bar-loopBar').value = Array.isArray(config_chat.loopBar) ? config_chat.loopBar.join('\n') : '';
		
        if (config_chat.isSend) {
            config_chat.isSend = false;
            $H2P('button#h2p-btn-bar-send').click();
        }
        if (!Chat) { Chat = setBar(); }
	})
	.then(() => {
		if (config_chat.keyReBar && config_chat.keyReBar.length > 0) {
			$H2P('input#h2p-input-key').value = $H2P('select#h2p-select-keyRe').selectedOptions[0].textContent;
			$H2P('input#h2p-input-re').value = $H2P('select#h2p-select-keyRe').selectedOptions[0].value;
		}
	})
    .catch(error => { console.log(error); })
	
	function getBar () {
		let barrage = undefined;

		// 抽奖弹幕
		if (config_chat.isLuck && $H2P('div.LotteryDrawEnter-desc')) {
			// 计算目前倒计时
			let luckCD_now = $H2P('div.LotteryDrawEnter-desc').textContent.split(':').reduce((m, s) => Number(m) * 60 + Number(s));
			// 新一轮抽奖
			if (luckCD_now > luckCD) {
				luckBar = undefined;
				luckTime = 0;
				// 显示抽奖内容
				$H2P('div.LotteryDrawEnter-enter').click();
				try {
					// 获取抽奖弹幕条件
					let barREQM = $H2P('div.ULotteryStart-joinRule').textContent.split(':')[1];
					const REQMs = ['发弹幕', '发弹幕+关注主播'];
					// 不是赠送、礼物、福袋、数字、盛典
					let regex = /[\u8d60\u9001\u793c\u7269\u798f\u888b\d\u76db\u5178]+/g;
					if (barREQM.search(regex) < 0) {
						if (REQMs.indexOf(barREQM) > -1 || (userInfo.isAnchorFan && barREQM.includes('成为粉丝'))) {
							// 一键参与
							$H2P('div.ULotteryStart-joinBtn').click();										
							// 获取抽奖弹幕内容
							luckBar = $H2P('div.ULotteryStart-demandDanmu > span:nth-child(1)').textContent;
							luckBar = luckBar.split(' : ')[1] ? luckBar.split(' : ')[1] : luckBar.split(' : ')[0];
							if (luckBar.includes('复制')) { luckBar = luckBar.slice(0, -2); }
						}
					}
				} catch (error) { console.log(error); }
				finally { $H2P('span.LotteryContainer-close').click(); }
			}

			barrage = luckTime < config_chat.luckTime ? luckBar : undefined;
			if (barrage) {
				luckTime++;
				$H2P('input#h2p-input-bar-luck-time-now').value = luckTime;
				console.log(`抽奖弹幕 : ${barrage}`);
			}
			luckCD = luckCD_now;
		}

		// 关键词弹幕回复
		if (!barrage && config_chat.isKeyRe && Array.isArray(config_chat.keyReBar)) {
			let bars = $H2P('ul#js-barrage-list > li', false);
			for (let i = Index_keyRe; i < bars.length && !barrage; i++) {
				Index_keyRe++;
				let ele = bars[i];
				try {
					let bar_check = ele.querySelector('span[class^="Barrage-content"]').textContent.replace(/\s/g, '');
					if (ele.querySelector('span[class^="Barrage-nickName"]').title !== userInfo.nickName) {
						for (let j = 0; j < config_chat.keyReBar.length; j++) {
							let keyRe = config_chat.keyReBar[j];
							if (bar_check.includes(keyRe.key)) {
								barrage = keyRe.re;
								console.log(`关键词弹幕回复 : ${barrage}`);
								break;
							}
						}
					}
				} catch (error) { console.log(error); }
			}
			if (Index_keyRe >= bars.length) { Index_keyRe = 0; }
		}

		// 抄袭弹幕
		if (!barrage && config_chat.isCopy) {
			let bars = $H2P('ul#js-barrage-list > li', false);
			let index = 0;
			if (config_chat.copyInvl) {
				if (config_chat.copyInvl < bars.length) { index = config_chat.copyInvl; }
				else { index = bars.length - 1; }
			}
			barrage = bars[index].querySelector('span[class^="Barrage-content"]').textContent.replace(/\s/g, '');
		}

		// 循环弹幕
		if (!barrage && config_chat.isLoop && Array.isArray(config_chat.loopBar)) {
			let index = Math.floor(Math.random() * (config_chat.loopBar.length));
			barrage = config_chat.loopBar[index];
		}

		return barrage ? barrage : '';
	}

	function setINVL_SendBar () {
		let {invlStart = 2, invlEnd = 2} = config_chat;
		let [start, end] = [Number(invlStart), Number(invlEnd)];
		let invl = Math.floor(Math.random() * (end - start)) + start;
		setINVL_ShowCD(invl);
		INVL_SendBar = setTimeout(() => {
			Chat.setMsg(getBar());
			Chat.sendMsg();
			setINVL_SendBar();
		}, invl * 1000);
	}

	function setINVL_ShowCD (invl) {
		new Promise((resolve, reject) => {
			window.clearInterval(INVL_ShowCD);
			resolve(invl);
		}).then((invl)=> {
			let cd = invl + 0.3;
			INVL_ShowCD = setInterval(() => {
				cd = Math.max(Math.floor((cd - 0.1) * 10) / 10.0, 0);
				$H2P('input#h2p-input-cd').value = cd;
			}, 100);
		})
	}

	function setBar () {
		let [eleSetBar, eleSendBar] = [undefined, undefined];
		return {
			setMsg : (msg)=>{
				if (!eleSetBar && $H2P('.ChatSend-txt')) { eleSetBar = $H2P('.ChatSend-txt'); }
				if (eleSetBar) { eleSetBar.value = msg; }
			},
			sendMsg : ()=>{
				if (!eleSendBar && $H2P('.ChatSend-button')) { eleSendBar = $H2P('.ChatSend-button'); }
				if (eleSendBar && eleSetBar.value) { eleSendBar.click(); }
			}
		}
	}








// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// 
// 															清爽模式
// 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	let LSClear = 'h2p-DY-config-clear';
	let config_clear_pre = {
		isClearNav	: false,
		isClearInfo	: false,
		isClearAside: false,
		isClearGift	: false,
		isClearBar	: false,
		isClearPlay	: false,
		blackMode	: false,
		clearMode	: false,
		delEle		: false,
		wideMode	: false,
		fullMode	: false,
	};
	let config_clear = {};
	Object.assign(config_clear, config_clear_pre);
	let config_clear_tmp = JSON.parse(localStorage.getItem(LSClear)) || {};
	Object.assign(config_clear, config_clear_tmp);
	for (let key in config_clear) { if (!(key in config_clear_pre)) { delete config_clear[key]; } }
	localStorage.removeItem(LSClear);
	localStorage.setItem(LSClear, JSON.stringify(config_clear));

	if (config_clear.blackMode) { blackMode(); }
	if (config_clear.clearMode) { clearMode(); }
	new Promise((resolve, reject) => {
		// 创建元素样式  ===============================================================
		let eleStyle = document.createElement('style');
		eleStyle.type = 'text/css';
		eleStyle.innerHTML = `
			.h2p-btn {
				width			: 100%;
				height			: 100%;
				padding			: 4px 0;
				border			: none;
				border-radius	: 5px;
				margin			: 0;
				font-size		: 13px;
				cursor			: pointer;
			}
			.h2p-bg-red	{ background-color : #ff8899; }
			.h2p-bg-red:hover	{ background-color : #ff5566; }
			.h2p-top-0		{ top: 0!important; }
			.h2p-top-50		{ top: 50px!important; }
			.h2p-w-50p		{ width: 50%!important; }
			.h2p-w-96p		{ width: 96%!important; }
			.h2p-h-100p 	{ height: 100%!important; }
			#h2p-div-clear-blackMode 	{ cursor: pointer; }
			#h2p-div-clear button { height: 26px; }
		`;
		document.head.appendChild(eleStyle);
		
		// 初始化清爽模式界面  ===============================================================
		let div = document.createElement('div');
		div.id = 'h2p-div-clear';
		div.className = 'h2p-div-inlinepanel';
		div.style = 'display: none;';
		div.innerHTML = `
			<div id="h2p-div-clear-vary" class="h2p-flex-main-start h2p-item-100p" style="height: 74px;">
				<!-- 导航栏、侧边栏、删除元素 -->
				<div class="h2p-flex-main-start h2p-item-75p" style="order: 0">
					<div class="h2p-flex-main-start h2p-item-33p">
						<button id="h2p-btn-clear-nav" class="h2p-btn h2p-w-96p h2p-bg-close">导航栏</button>
					</div>
					<div class="h2p-flex-main-start h2p-item-33p">
						<button id="h2p-btn-clear-info" class="h2p-btn h2p-w-96p h2p-bg-close">信息栏</button>
					</div>
					<div class="h2p-flex-main-start h2p-item-33p">
						<button id="h2p-btn-clear-aside" class="h2p-btn h2p-w-96p h2p-bg-close">侧边栏</button>
					</div>
				</div>
				<div class="h2p-flex-main-center h2p-item-25p" style="order: 1">
					<div id="h2p-div-clear-blackMode">
						<span id="h2p-span-clear-blackMode" style="font-size: 40px;" @click="hideBM" title="黑暗模式">☀️</span>
					</div>
				</div>
				<!-- 信息栏、弹幕栏、礼物栏、鱼吧 -->
				<div class="h2p-flex-main-start h2p-item-75p" style="order: 2">
					<div class="h2p-flex-main-start h2p-item-33p">
						<button id="h2p-btn-clear-gift" class="h2p-btn h2p-w-96p h2p-bg-close">礼物栏</button>
					</div>
					<div class="h2p-flex-main-start h2p-item-33p">
						<button id="h2p-btn-clear-bar" class="h2p-btn h2p-w-96p h2p-bg-close">弹幕栏</button>
					</div>
					<div class="h2p-flex-main-start h2p-item-33p">
						<button id="h2p-btn-clear-play" class="h2p-btn h2p-w-96p h2p-bg-close">播放器</button>
					</div>
				</div>
			</div>
			<!-- 清爽模式、宽屏模式、网页全屏 -->
			<div id="h2p-div-clear-mode">
				<div class="h2p-flex-main-start h2p-item-100p">
					<div class="h2p-flex-main-start h2p-item-50p">
						<button id="h2p-btn-clear-clearMode" class="h2p-btn h2p-w-96p h2p-bg-close">清爽模式</button>
					</div>
					<div class="h2p-flex-main-start h2p-item-50p">
						<button id="h2p-btn-clear-delEle" class="h2p-btn h2p-w-96p h2p-bg-red">删除元素</button>
					</div>
				</div>
				<div class="h2p-flex-main-start h2p-item-100p">
					<div class="h2p-flex-main-start h2p-item-50p">
						<button id="h2p-btn-clear-wideMode" class="h2p-btn h2p-w-96p h2p-bg-close">宽屏模式</button>
					</div>
					<div class="h2p-flex-main-start h2p-item-50p">
						<button id="h2p-btn-clear-fullMode" class="h2p-btn h2p-w-96p h2p-bg-close">网页全屏</button>
					</div>
				</div>
			</div>
		`;

		let setINVL_wait_div_DYScript = setInterval(() => {
			if ($H2P('div#div-DYScript')) {
				window.clearInterval(setINVL_wait_div_DYScript);
				setINVL_wait_div_DYScript = null;
				$H2P('div#div-DYScript').appendChild(div);
				resolve();
			}
		}, 500);
	})
	.then(() => {
		let eleVary = $H2P('div#h2p-div-clear-vary');
		eleVary.addEventListener('click', (event) => {
			let target = event.target;
			if (target.tagName.toLowerCase() !== 'button') { return; }
			target.classList.toggle('h2p-bg-open');
			if (target.id === 'h2p-btn-clear-nav') {
				config_clear.isClearNav = !config_clear.isClearNav;
				if (config_clear.clearMode) { clearNav(); }
			}
			else if (target.id === 'h2p-btn-clear-info') {
				config_clear.isClearInfo = !config_clear.isClearInfo;
				if (config_clear.clearMode) { clearInfo(); }
			}
			else if (target.id === 'h2p-btn-clear-aside') {
				config_clear.isClearAside = !config_clear.isClearAside;
				if (config_clear.clearMode) { clearAside(); }
			}
			else if (target.id === 'h2p-btn-clear-gift') {
				config_clear.isClearGift = !config_clear.isClearGift;
				if (config_clear.clearMode) { clearGift(); }
			}
			else if (target.id === 'h2p-btn-clear-bar') {
				config_clear.isClearBar = !config_clear.isClearBar;
				if (config_clear.clearMode) { clearBar(); }
			}
			else if (target.id === 'h2p-btn-clear-play') {
				config_clear.isClearPlay = !config_clear.isClearPlay;
				if (config_clear.clearMode) { clearPlay(); }
			}
			localStorage.setItem(LSClear, JSON.stringify(config_clear));
		}, false);

		// 黑暗模式 click 监听
		let eleBM = $H2P('span#h2p-span-clear-blackMode');
		eleBM.addEventListener('click', () => {
			config_clear.blackMode = !config_clear.blackMode;
			localStorage.setItem(LSClear, JSON.stringify(config_clear));
			$H2P('span#h2p-span-clear-blackMode').textContent = config_clear.blackMode ? '🌑' : '☀️';
			blackMode();
		})

		// 清爽模式 click 监听
		let eleMode = $H2P('div#h2p-div-clear-mode');
		eleMode.addEventListener('click', (event) => {
			let target = event.target;
			if (target.tagName.toLowerCase() !== 'button') { return; }
			if (target.id === 'h2p-btn-clear-delEle') {
				$H2P('button#h2p-btn-clear-delEle').classList.toggle('h2p-bg-open');
				config_clear.delEle = !config_clear.delEle;
				localStorage.setItem(LSClear, JSON.stringify(config_clear));
				deleteElement();
				return;
			}

			target.classList.toggle('h2p-bg-open');
			if (target.id === 'h2p-btn-clear-clearMode') {
				config_clear.clearMode = !config_clear.clearMode;
				clearMode();
			} else if (target.id === 'h2p-btn-clear-wideMode') {
				config_clear.wideMode = !config_clear.wideMode;
				if (config_clear.fullMode) {
					config_clear.fullMode = false;
					$H2P('button#h2p-btn-clear-fullMode').classList.remove('h2p-bg-open');
				}
				wideMode();
			} else if (target.id === 'h2p-btn-clear-fullMode') {
				config_clear.fullMode = !config_clear.fullMode;
				if (config_clear.wideMode) {
					config_clear.wideMode = false;
					$H2P('button#h2p-btn-clear-wideMode').classList.remove('h2p-bg-open');
				}
				fullMode();
			}
			localStorage.setItem(LSClear, JSON.stringify(config_clear));
		}, false);
	})
	.then(() => {
		if (config_clear.isClearNav) { $H2P('button#h2p-btn-clear-nav').classList.add('h2p-bg-open'); }
		if (config_clear.isClearInfo) { $H2P('button#h2p-btn-clear-info').classList.add('h2p-bg-open'); }
		if (config_clear.isClearAside) { $H2P('button#h2p-btn-clear-aside').classList.add('h2p-bg-open'); }
		if (config_clear.isClearGift) { $H2P('button#h2p-btn-clear-gift').classList.add('h2p-bg-open'); }
		if (config_clear.isClearBar) { $H2P('button#h2p-btn-clear-bar').classList.add('h2p-bg-open'); }
		if (config_clear.isClearPlay) { $H2P('button#h2p-btn-clear-play').classList.add('h2p-bg-open'); }

		if (config_clear.blackMode) { $H2P('span#h2p-span-clear-blackMode').textContent = config_clear.blackMode ? '🌑' : '☀️'; }

		if (config_clear.clearMode) { $H2P('button#h2p-btn-clear-clearMode').classList.add('h2p-bg-open'); }
		if (config_clear.wideMode) { $H2P('button#h2p-btn-clear-wideMode').classList.add('h2p-bg-open'); }
		if (config_clear.fullMode) { $H2P('button#h2p-btn-clear-fullMode').classList.add('h2p-bg-open'); }
		if (config_clear.delEle) { $H2P('button#h2p-btn-clear-delEle').classList.add('h2p-bg-open'); }
	})
	.catch(error => { console.log(error); })

	new Promise((resolve, reject) => {
		// 主播热度、在线人数、直播时长
		let divBar = document.createElement('div');
		divBar.id = 'h2p-div-clear-anchorHot';
		divBar.classList = 'h2p-flex-main-start h2p-h-100p';
		divBar.style = 'padding: 3px 10px 0; margin: 0;';
		divBar.innerHTML = `
			<div class="Title-blockInline h2p-item-33p">
				<a id="a-anchorHot" class="Title-anchorHot" title="直播热度">
					<i class="Title-anchorHotIcon" style="margin-top: -4px">
						<svg style="width: 16px; height: 16px;">
							<use xlink:href="#hot_84f8212"></use>
						</svg>
					</i>
					<div class="Title-anchorText" style="margin-left: 2px;">0</div>
				</a>
			</div>
			<div class="Title-blockInline h2p-item-33p">
				<div id="div-online" title="真实人数" style="margin-top: -7px">
					<div class="Title-anchorFriendWrapper">
						<div class="Title-row-span">
							<span class="Title-row-icon">
								<svg style="width:15px; height:15px">
									<use xlink:href="#friend_b0b6380"></use>
								</svg>
							</span>
							<i class="Title-row-text" style="margin-left: 2px;">0</i>
						</div>
					</div>
				</div>
			</div>
			<div class="Title-blockInline h2p-item-33p">
				<a id="a-anchorShowT" class="Title-anchorHot" title="直播时长">
					<div class="AnchorFriendCard-avatar is-live" style="height: 19px; border: none; margin: 2px 5px 0 -4px;"></div>
					<div class="Title-anchorText" style="margin-left: 2px;">0</div>
				</a>
			</div>
		`;

		let setINVL_wait_div_announce = setInterval(() => {
			if ($H2P('div.layout-Player-asideMainTop') && $H2P('div.BarrageSuperLink') && $H2P('div.ChatToolBar')) {
				window.clearInterval(setINVL_wait_div_announce);
				setINVL_wait_div_announce = null;
				setTimeout(() => {
					$H2P('div.layout-Player-announce').appendChild(divBar);
					resolve();
				}, 2000);
			}
		}, 500);
	})
	.then(() => {
		setTO_showAnchorHot();
	})

	function blackMode () {
		console.log(`${config_clear.blackMode ? '启动' : '关闭'} : 黑暗模式`);
		if (config_clear.blackMode) {
			if ($H2P('style#h2p-style-blackMode')) { return; }
			let eleStyle = document.createElement('style');
			eleStyle.id = 'h2p-style-blackMode';
			eleStyle.innerHTML = `
				body, div.Header-wrap, main.layout-Main, div.FishpondTreasure-v4-area { background-color: #2d2e37; }
			`;
			// header 左边
			eleStyle.innerHTML += `
				div.Header-wrap { border-bottom-color: #2d2e37; }
				header#js-header div.HeaderNav a.EntryNav-desc, header#js-header ul.Header-menu > li a,
				svg.Header-icon use { color: #a7a7a7 }
			`;
			// header 右边
			eleStyle.innerHTML += `
				header#js-header div.Header-right div.Search { background-color: #444455; border: 1px solid #444455; }
				header#js-header div.Header-right div.Search svg.Header-icon,
				header#js-header div.Header-right a.public-DropMenu-link { color: #a7a7a7; }
			`;
			// 主播信息
			eleStyle.innerHTML += `
				div#js-player-title { background-color: #2d2e37; border-color: #444455; border-bottom-color: #2d2e37; }
				div.Title-roomInfo div.Title-row h3.Title-header, div.Title-roomInfo div.Title-row h2.Title-anchorNameH2,
				div.Title-roomInfo div.Title-row a.Title-anchorHot div.Title-anchorText, div.Title-roomInfo div.Title-anchorLocation span,
				div.Title-roomInfo div.Title-sharkWeight span, div.Title-roomInfo div.Title-row div.Title-blockInline span { color: #a7a7a7; }
			`;
			// 礼物栏
			eleStyle.innerHTML += `
				div#js-player-toolbar { background-color: #2d2e37; border-color: #444455; }
				div#js-player-toolbar div.PlayerToolbar-ywInfo span,
				div#js-player-toolbar div.PlayerToolbar-ycInfo span { color: #a7a7a7; }
				div#js-player-toolbar div.PlayerToolbar-Content:nth-child(2) div.PlayerToolbar-ContentCell:nth-child(1) { visibility: hidden; }
			`;
			// 弹幕栏
			eleStyle.innerHTML += `
				div#js-player-asideMain { background-color: #2d2e37; border-color: #444455; }
			`;
			// 弹幕栏 - 公告
			eleStyle.innerHTML += `
				div.layout-Player-announce { background-color: #2d2e37; border-bottom-color: #444455; }
				div.layout-Player-rank ul.ChatTabContainer-titleWraper--tabTitle li { background-color: #2d2e37; border-color: #2d2e37; }
			`;
			// 弹幕栏 - 周榜
			eleStyle.innerHTML += `div.ChatRankWeek-headerContent { background-color: #2d2e37; }`;
			// 弹幕栏 - 贵宾
			eleStyle.innerHTML += `div.NobleRank, div.NobleRankTips { background-color: #2d2e37; }`;
			// 弹幕栏 - 粉丝团
			eleStyle.innerHTML += `
				div.FansRankInfo, div.ChatTabContainer { background-color: #2d2e37; }
				div.FansRankInfo span { color: #a7a7a7; }
			`;
			// 弹幕栏 - 主体
			eleStyle.innerHTML += `
				div#js-player-barrage, div.Barrage-main { background-color: #2d2e37; }
				span.Barrage-content { color: #a7a7a7; }
				div.Barrage { border-color: #444455; }
			`;
			// 弹幕栏 - 聊天框
			eleStyle.innerHTML += `
				div.layout-Player-chat { background-color: #2d2e37; }
				div.layout-Player-chat textarea.ChatSend-txt { background-color: #2d2e37; color: #a7a7a7!important; }
			`;
			// 弹幕栏脚本面板
			eleStyle.innerHTML += `
				div#h2p-div-clear-anchorHot { background-color: #2d2e37; border-bottom: 1px solid #2d2e37}
				div#h2p-div-clear-anchorHot div.Title-anchorText,
				div#h2p-div-clear-anchorHot div.Title-blockInline:nth-child(2) span.Title-row-icon,
				div#h2p-div-clear-anchorHot div.Title-blockInline:nth-child(2) i.Title-row-text { color: #a7a7a7; }
			`;
			// 互动预言
			eleStyle.innerHTML += `
				div#guess-main-panel { background: #2d2e37; border-color: #444455; }
				div.GuessMainPanelHeader-panelLeft span.GuessMainPanelHeader-slogon { color: #a7a7a7; }
				div.GuessGameBox, div.GuessReturnYwFdSlider-numIptWrap { background: #2d2e37; border-color: #2d2e37; }
				div.GuessGameBox-header div.boxLeft, div.GuessReturnYwFdSlider-giftName { color: #a7a7a7; }
				div.GuessReturnYwFdSlider-numIptWrap, 
				input.GuessReturnYwFdSlider-numIpt { background-color: #444455; border-color: #444455; color: #a7a7a7; }
				a.GuessGuideList-itemBox { background-color: #444455; }
				h2.guessGame--ell { color: #a7a7a7; }
			`;
			// 友邻
			eleStyle.innerHTML += `
				div#js-bottom-right { background-color: #2d2e37; }
				div.AnchorFriendPane-title { border-bottom-color: #444455!important }
				div.AnchorFriendPane-title h3 { color: #a7a7a7!important; }
				div.AnchorLike-ItemBox { border-color: #444455; }
				div.AnchorFriend-footer { border-top-color: #444455; }
				div.AnchorFriend-footer a { background-color: #2d2e37; color: #a7a7a7 }
				div.GuessReturnYwFdSlider { background-color: #2d2e37; border-color: #2d2e37;}
			`;
			document.body.append(eleStyle);
		} else { $H2P('style#h2p-style-blackMode').remove(); }
	}

	function clearNav () {
		console.log(`${config_clear.isClearNav ? '启动' : '关闭'} : 清爽导航栏`);
		if (config_clear.isClearNav) {
			if ($H2P('style#h2p-style-clear-nav')) { return; }
			let eleStyle = document.createElement('style');
			eleStyle.id = 'h2p-style-clear-nav';
			// 斗鱼 logo、游戏、活动
			eleStyle.innerHTML = `
				a.Header-logo, div.public-DropMenu.Game, div.HeaderNav { display: none!important; }
			`;
			// 客户端、开播
			eleStyle.innerHTML += `
				div.Header-download-wrap, div.Header-broadcast-wrap { display: none!important; }
			`;
			// 用户头像 hover
			eleStyle.innerHTML += `
				div.UserInfo div.Task, div.UserInfo div.CloudGameLink, div.Promotion { display: none!important; }
			`;
			document.body.append(eleStyle);
		} else { $H2P('style#h2p-style-clear-nav').remove(); }
	}

	function clearInfo () {
		console.log(`${config_clear.isClearInfo ? '启动' : '关闭'} : 清爽主播信息`);
		if (config_clear.isClearInfo) {
			if ($H2P('style#h2p-style-clear-info')) { return; }
			let eleStyle = document.createElement('style');
			eleStyle.id = 'h2p-style-clear-info';
			eleStyle.innerHTML = `
				div#js-player-title { min-height: auto!important; }
				div.Title { height: 100%!important; }
			`;
			// 头像、举报、友邻
			eleStyle.innerHTML += `
				div.Title-anchorPic, div.Title-roomInfo div.Title-col.is-left > div.Title-blockInline:nth-child(2),
				div.Title-roomInfo div.Title-col.is-right > div.Title-blockInline { display: none!important; }
			`;
			// 官方称号
			eleStyle.innerHTML += `
				div.Title-roomInfo > div.Title-row:nth-child(2) > div.Title-col:nth-child(1) > div.Title-blockInline:last-child { display: none!important; }
			`;
			// 友邻、工会、体重
			eleStyle.innerHTML += `
				div.Title-roomInfo > div.Title-row:nth-child(2) > div.Title-col:nth-child(2),
				div.Title-roomInfo > div.Title-row:nth-child(3) { display: none!important; }
			`;
			document.body.append(eleStyle);
		} else { $H2P('style#h2p-style-clear-info').remove(); }
	}

	function clearAside () {
		console.log(`${config_clear.isClearAside ? '启动' : '关闭'} : 清爽侧边栏`);
		if (config_clear.isClearAside) {
			if ($H2P('style#h2p-style-clear-aside')) { return; }
			let eleStyle = document.createElement('style');
			eleStyle.id = 'h2p-style-clear-aside';
			eleStyle.innerHTML = `
				aside#js-aside { display: none!important; }
			`;
			document.body.append(eleStyle);
		} else { $H2P('style#h2p-style-clear-aside').remove(); }
	}

	function clearGift () {
		console.log(`${config_clear.isClearGift ? '启动' : '关闭'} : 清爽礼物栏`);
		if (config_clear.isClearGift) {
			if ($H2P('style#h2p-style-clear-gift')) { return; }
			let eleStyle = document.createElement('style');
			eleStyle.id = 'h2p-style-clear-gift';
			// 全民乐 PK、礼物
			eleStyle.innerHTML = `
				div.ToolbarActivityArea div.ActivityItem, div#js-player-toolbar div.PlayerToolbar-GiftWrap,
				div.ToolbarActivityArea div.BattleShipEnter, div.ToolbarActivityArea div.RomanticDateComponent { display: none!important; }
			`;
			document.body.append(eleStyle);
		} else { $H2P('style#h2p-style-clear-gift').remove(); }
	}

	function clearBar () {
		console.log(`${config_clear.isClearBar ? '启动' : '关闭'} : 清爽弹幕栏`);
		if (config_clear.isClearBar) {
			if ($H2P('style#h2p-style-clear-bar')) { return; }
			let eleStyle = document.createElement('style');
			eleStyle.id = 'h2p-style-clear-bar';
			eleStyle.innerHTML = `
				div#js-player-barrage { top: 32px!important; }
			`;
			// 公告、开通贵族公告
			eleStyle.innerHTML += `
				div.AnchorAnnounce, div.layout-Player-rankAll, div.layout-Player-rank { display: none!important; }
				div.BarrageBanner { display: none!important; }
			`;
			// 弹幕标签
			eleStyle.innerHTML += `
				.FansMedal.is-made, .RoomLevel, .shark-webp .Motor, .Barrage-noble, .Medal { display: none!important; }
				.Barrage-notice--noble { background: transparent!important; border: none; }
			`;
			// 喇叭、贵族弹幕、超链弹幕
			eleStyle.innerHTML += `
				div.Horn4Category, div.ChatNobleBarrage, div.BarrageSuperLink { display: none!important; }
			`;
			document.body.append(eleStyle);
		} else {
			$H2P('style#h2p-style-clear-bar').remove();
		}
	}

	function clearPlay () {
		console.log(`${config_clear.isClearPlay ? '启动' : '关闭'} : 清爽播放器`);
		if (config_clear.isClearPlay) {
			if ($H2P('style#h2p-style-clear-play')) { return; }
			let eleStyle = document.createElement('style');
			eleStyle.id = 'h2p-style-clear-play';
			// 悬浮广告、鱼吧
			eleStyle.innerHTML = `
				#js-room-activity, .layout-Bottom-mainEntity { display: none!important; }
			`;
			document.body.append(eleStyle);
		} else { $H2P('style#h2p-style-clear-play').remove(); }
	}

	function clearMode () {
		console.log(`${config_clear.clearMode ? '启动' : '关闭'} : 清爽模式`);
		if (config_clear.isClearNav) {
			if (config_clear.clearMode) { clearNav(); }
			else {
				config_clear.isClearNav = false;
				clearNav();
				config_clear.isClearNav = true;
			}
		}
		if (config_clear.isClearInfo) {
			if (config_clear.clearMode) { clearInfo(); }
			else {
				config_clear.isClearInfo = false;
				clearInfo();
				config_clear.isClearInfo = true;
			}
		}
		if (config_clear.isClearAside) {
			if (config_clear.clearMode) { clearAside(); }
			else {
				config_clear.isClearAside = false;
				clearAside();
				config_clear.isClearAside = true;
			}
		}
		if (config_clear.isClearGift) {
			if (config_clear.clearMode) { clearGift(); }
			else {
				config_clear.isClearGift = false;
				clearGift();
				config_clear.isClearGift = true;
			}
		}
		if (config_clear.isClearBar) {
			if (config_clear.clearMode) { clearBar(); }
			else {
				config_clear.isClearBar = false;
				clearBar();
				config_clear.isClearBar = true;
			}
		}
		if (config_clear.isClearPlay) {
			if (config_clear.clearMode) { clearPlay(); }
			else {
				config_clear.isClearPlay = false;
				clearPlay();
				config_clear.isClearPlay = true;
			}
		}
	}

	function wideMode () {
		if (config_clear.wideMode) {
			if ($H2P('div.wfs-2a8e83')) { $H2P('div.wfs-2a8e83').click(); }
			else {
				let start = new Date().getTime();
				let setINVL_waitWideCoin = setInterval(() => {
					if ($H2P('div.wfs-2a8e83')) {
						window.clearInterval(setINVL_waitWideCoin);
						setINVL_waitWideCoin = null;
						$H2P('div.wfs-2a8e83').click();
					} else {
						// 等待最长 2min
						if ((new Date().getTime() - start) / 1000 > 120) {
							window.clearInterval(setINVL_waitWideCoin);
							setINVL_waitWideCoin = null;
						}
					}
				}, 500);
			}
		} else {
			$H2P('div.wfs-exit-180268').click();
		}
	}

	function fullMode () {
		if (config_clear.fullMode) {
			if ($H2P('div.fs-781153')) { $H2P('div.fs-781153').click(); }
			else {
				let start = new Date().getTime();
				let setINVL_waitFullCoin = setInterval(() => {
					if ($H2P('div.fs-781153')) {
						window.clearInterval(setINVL_waitFullCoin);
						setINVL_waitFullCoin = null;
						$H2P('div.fs-781153').click();
					} else {
						// 等待最长 2min
						if ((new Date().getTime() - start) / 1000 > 120) {
							window.clearInterval(setINVL_waitFullCoin);
							setINVL_waitFullCoin = null;
						}
					}
				}, 500);
			}
		} else {
			$H2P('div.fs-exit-b6e6a7').click();
		}
	}

	function deleteElement () {
		if ($H2P('div#js-room-activity')) { $H2P('div#js-room-activity').remove(); }
		if ($H2P('div.layout-Bottom-mainEntity')) { $H2P('div.layout-Bottom-mainEntity').remove(); }
	}

	function setTO_showAnchorHot () {
		return setTimeout(() => {
			let anchorHot = Number($H2P('a.Title-anchorHot > div.Title-anchorText').textContent) || 0;
			let str_anchorHot = '' + anchorHot;
			if (anchorHot > 9999) { str_anchorHot = parseInt(anchorHot/10000) + 'w'; }
			$H2P('a#a-anchorHot > div.Title-anchorText').textContent = str_anchorHot;
			
			if (roomInfo.showT > 0) {
				let showT = Number.parseInt((new Date().getTime() / 1000) - roomInfo.showT) / 3600.0;
				let h = Number.parseInt(showT);
				let m = Number.parseInt((showT - h) * 60);
				let s = Number.parseInt(((showT - h) * 60 - m) * 60);
				// 设置直播时长
				setInterval(() => {
					s += 1;
					if (s >= 60) { m += 1; s = 0; }
					if (m >= 60) { h += 1; m = 0; }
					let strShowT = `${h}:`;
					if (m >= 10) { strShowT += m + ':'; }
					else { strShowT += '0' + m + ':'; }
					if (s >= 10) { strShowT += s; }
					else { strShowT += '0' + s; }
					$H2P('a#a-anchorShowT > div.Title-anchorText').textContent = strShowT;
				}, 1000);
			}
			// 直播热度和在线人数
			setInterval(() => {
				let anchorHot = Number($H2P('a.Title-anchorHot div.Title-anchorText').textContent) || 0;
				if (anchorHot > 9999) { anchorHot = Number.parseInt(anchorHot / 10000) + 'w'; }
				if ($H2P('a#a-anchorHot > div.Title-anchorText')) { $H2P('a#a-anchorHot > div.Title-anchorText').textContent = anchorHot; }

				let online = roomInfo.online;
				if (online > 9999) { online = Number.parseInt(online / 10000) + 'w'; }
				$H2P('div#div-online i.Title-row-text').textContent = online;
			}, 5000);
		}, 200);
	}








// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// 
// 																快捷键设置
// 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	document.addEventListener('keydown', (e) => {
		// ESC 按键
		if (e.which === 27) {
			if (config_clear.wideMode) $H2P('button#h2p-btn-clear-wideMode').click();
			else if (config_clear.fullMode) $H2P('button#h2p-btn-clear-fullMode').click();
		}
		let myKeyCode = { 'a':65, 's':83, 'c': 67, 'd':68, 'u': 85, 'i': 73, 'o': 79, 'p': 80, }
		// shift a
		if (e.shiftKey && e.which == myKeyCode.a) {
			if ($H2P('span#h2p-span-DYScript')) {
				if (!viewShow_script) {
					$H2P('span#h2p-span-DYScript').click();
					$H2P('div#h2p-div-tab-bar').click();
				} else {
					if ( viewShow_bar ) { $H2P('span#h2p-span-DYScript').click(); }
					else { $H2P('div#h2p-div-tab-bar').click(); }
				}
			}
		}
		else if (e.shiftKey && e.which == myKeyCode.s) {
			if ($H2P('span#h2p-span-DYScript')) {
				if (!viewShow_script) {
					$H2P('span#h2p-span-DYScript').click();
					$H2P('div#h2p-div-tab-clear').click();
				} else {
					if (viewShow_clear) { $H2P('span#h2p-span-DYScript').click(); }
					else { $H2P('div#h2p-div-tab-clear').click(); }
				}
			}
		}
		else if (e.shiftKey && e.which == myKeyCode.d) {
			if ($H2P('span#h2p-span-DYScript')) {
				if (!viewShow_script) {
					$H2P('span#h2p-span-DYScript').click();
					$H2P('div#h2p-div-tab-config').click();
				} else {
					if (viewShow_config) { $H2P('span#h2p-span-DYScript').click(); }
					else { $H2P('div#h2p-div-tab-config').click(); }
				}
			}
		}
		// 清爽模式快捷键
		else if (e.shiftKey && e.which == myKeyCode.u) { $H2P('button#h2p-btn-clear-clearMode').click(); }
		else if (e.shiftKey && e.which == myKeyCode.i) { $H2P('span#h2p-span-clear-blackMode').click(); }
		else if (e.shiftKey && e.which == myKeyCode.o) { $H2P('button#h2p-btn-clear-wideMode').click(); }
		else if (e.shiftKey && e.which == myKeyCode.p) { $H2P('button#h2p-btn-clear-fullMode').click(); }
		// 清空弹幕
		else if (e.shiftKey && e.which == myKeyCode.c) { $H2P('a.Barrage-toolbarClear').click(); }
	});








	
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// 
// 																自动化设置
// 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	// 自动领取观看鱼丸
	let auto_getFB = () => {
		let INVL_autoGetFB = setInterval(() => {
			// 观看鱼丸元素存在并且有未领取的鱼丸
			if ( $H2P('div.FishpondTreasure-num.is-entrance') && $H2P('div.FishpondTreasure-num.is-entrance').textContent.length > 0 ) {
				// 打开领取鱼丸界面
				$H2P('div.FishpondTreasure-icon').click();

				// 每日活跃、每周活跃
				$H2P('span[class^="FTP-btn"]', false).forEach( (span) => {
					span.click();
					$H2P('div.FTP-singleTask-btn.is-finished', false).forEach( ele => ele.click());
				});
				// 鱼塘
				$H2P('div.FTP-bubble-progressText.is-complete', false).forEach( ele => ele.click());

				$H2P('span.FTP-close').click();
			}
		}, 5000);
	};

	// 默认画质
	let auto_showDef = () => {
		let INVL_checkDefIconReady = setInterval(() => {
			if ($H2P('div.rate-5c068c')) {
				window.clearInterval(INVL_checkDefIconReady);
				INVL_checkDefIconReady = null;
				console(`启动完毕 : ${config_tool.isShow0 ? '最低' : '最高'}画质`);
				if (config_tool.isShow0) { $H2P('div.tip-e3420a > ul > li:last').click(); }
				else if (config_tool.isShow9) { $H2P('div.tip-e3420a > ul > li:first').click();					 }
			}
		}, 500);
	}

	// 禁止弹幕
	let auto_hideBar = () => {
		let INVL_checkDefIconReady = setInterval(() => {
			if ($H2P('div[class="showdanmu-42b0ac removed-9d4c42"]')) {
				window.clearInterval(INVL_checkDefIconReady);
				INVL_checkDefIconReady = null;
			} else if ($H2P('div[class="showdanmu-42b0ac"]')) {
				$H2P('div[class="showdanmu-42b0ac"]').click();
				window.clearInterval(INVL_checkDefIconReady);
				INVL_checkDefIconReady = null;
				console.log('启动完毕 : 禁止弹幕');
			}
		}, 500);
	}

	// 静音
	let auto_hideSound = () => {
		let INVL_checkDefIconReady = setInterval(() => {
			if ($H2P('div[class="volume-silent-3eb726"]')) {
				window.clearInterval(INVL_checkDefIconReady);
				INVL_checkDefIconReady = null;
			} else if ( $H2P('div[class="volume-8e2726"]')) {
				window.clearInterval(INVL_checkDefIconReady);
				INVL_checkDefIconReady = null;
				console.log('启动完毕 : 静音');
			}
		}, 500);
	}

	// 自动签到
	let auto_signIn = () => {
		let INVL_checkSignInIconReady = setInterval(() => {
			if ($H2P('div.RoomLevelDetail-level.RoomLevelDetail-level--no')) {
				window.clearInterval(INVL_checkSignInIconReady);
				INVL_checkSignInIconReady = null;
				console.log('启动完毕 : 签到');
				$H2P('div.RoomLevelDetail-level.RoomLevelDetail-level--no').click();
				setTimeout(() => {
					// 关闭签到弹出的框
					$H2P('div.SSR-D-close').click();
				}, 200);
			}
		}, 500);
	}

	// 自动赠送荧光棒
	let auto_anchorUp = () => {
		function donateYGB(roomId){
			let formData = new FormData();
			formData.append("propId", "268");
			formData.append("propCount", 1);
			formData.append("roomId", roomId);
			fetch('https://www.douyu.com/japi/prop/donate/mainsite/v1', {
				method: 'POST',
				body: formData
			}).then(res => res.json())
			.then(res => {
				if (res && 'error' in res && res.error === 0) {
					console.log('成功赠送主播 : '+ roomId + ' 一个荧光棒');
					roomOfAnchorFan[roomId].anchorUp += 1;
				} else {
					console.log('赠送' + roomId + '失败 : ' + res.msg);
				}
			});
		}

		let INVL_anchorUp = setInterval(() => {
			if (roomOfAnchorFan) {
				let roomIds = Object.keys(roomOfAnchorFan);
				for (let i = 0; i < roomIds.length; i++) {
					let roomId = roomIds[i];
					if (roomOfAnchorFan[roomId].anchorUp === 0) { setTimeout(() => { donateYGB(roomId); }, (i+1) * 2000); }
				}
				window.clearInterval(INVL_anchorUp);
				INVL_anchorUp = null;
				console.log('启动完毕 : 赠送荧光棒');
			}
		}, 1000);
	}

	// 检测是否出现 在电脑面前检测
	setInterval(() => {
		if ($H2P('div.btn2-869c8d')) {
			$H2P('div.btn2-869c8d', false).forEach(ele => { ele.click() });
		}
	}, 10000);
	// 检测是否出现 重新加载
	setInterval(() => {
		if ($H2P('div.reload-0876b5') && $H2P('div.reload-0876b5').style.display != 'none') {
			$H2P('div.reload-0876b5', false).forEach(ele => { ele.click(); });
		}
	}, 10000);








// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// 
// 															脚本自动化配置界面
// 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	const LSConfig = 'h2p-DY-config-tool';
	let config_tool_pre = {
		show0		: false,
		show9		: false,
		hideBar		: false,
		hideSound	: false,
		getFB		: false,
		signIn		: false,
		anchorUp    : false,
	};
	let config_tool = {};
	Object.assign(config_tool, config_tool_pre);
	let config_tool_tmp = JSON.parse(localStorage.getItem(LSConfig)) || {};
	Object.assign(config_tool, config_tool_tmp);
	for (let key in config_tool) { if (!(key in config_tool_pre)) { delete config_tool[key]; } }
	localStorage.removeItem(LSConfig);
	localStorage.setItem(LSConfig, JSON.stringify(config_tool));

	new Promise((resolve, reject) => {
		// 创建元素样式  ===============================================================
		let eleStyle = document.createElement('style');
		eleStyle.type = 'text/css';
		eleStyle.innerHTML = `
			#h2p-div-config button { height: 25px; }
		`;
		document.head.appendChild(eleStyle);

		// 初始化配置界面  ===============================================================
		let div = document.createElement('div');
		div.id = 'h2p-div-config';
		div.className = 'h2p-div-inlinepanel';
		div.style = 'display: none;';
		div.innerHTML = `
			<div class="h2p-flex-main-start h2p-item-100p">
				<div class="h2p-flex-main-start h2p-item-50p">
					<button class="h2p-btn h2p-w-96p h2p-bg-close">关闭状态</button>
				</div>
				<div class="h2p-flex-main-end h2p-item-50p">
					<button class="h2p-btn h2p-w-96p h2p-bg-open">开启状态</button>
				</div>
			</div>

			<hr style="margin: 6px -9px 12px; border: 1px solid #DCDCDC;">

			<div class="h2p-flex-main-start h2p-item-100p">
				<!-- 画质选项 -->
				<div class="h2p-flex-main-start h2p-item-50p">
					<div class="h2p-flex-main-start h2p-item-50p">
						<button id="h2p-btn-config-show0" class="h2p-btn h2p-w-96p h2p-bg-close">最低画质</button>
					</div>
					<div class="h2p-flex-main-start h2p-item-50p">
						<button id="h2p-btn-config-show9" class="h2p-btn h2p-w-96p h2p-bg-close">最高画质</button>
					</div>
				</div>

				<div class="h2p-flex-main-end h2p-item-50p">
					<div class="h2p-flex-main-end h2p-item-50p">
						<button id="h2p-btn-config-hideBar" class="h2p-btn h2p-w-96p h2p-bg-close">关闭弹幕</button>
					</div>
					<div class="h2p-flex-main-end h2p-item-50p">
						<button id="h2p-btn-config-hideSound" class="h2p-btn h2p-w-96p h2p-bg-close">静音</button>
					</div>
				</div>
			</div>

			<div class="h2p-flex-main-start h2p-item-100p">
				<div class="h2p-flex-main-start h2p-item-50p">
					<div class="h2p-flex-main-start h2p-item-50p">
						<!-- 是否自动领取鱼丸 -->
						<button id="h2p-btn-config-getFB" class="h2p-btn h2p-w-96p h2p-bg-close" @click="click_autoGetFB">领取鱼丸</button>
					</div>
					<div class="h2p-flex-main-start h2p-item-50p">
						<!-- 是否自动签到 -->
						<button id="h2p-btn-config-signIn" class="h2p-btn h2p-w-96p h2p-bg-close" style="float: right" @click="click_autoSignIn">签到</button>
					</div>
				</div>
					
				<div class="h2p-flex-main-end h2p-item-50p">
					<div class="h2p-flex-main-end h2p-item-50p">
						<!-- 赠送荧光棒 -->
						<button id="h2p-btn-config-anchorUp" class="h2p-btn h2p-w-96p h2p-bg-close" @click="click_autoAnchorUp">赠送荧光棒</button>
					</div>
					<div class="h2p-flex-main-end h2p-item-50p">
						<!--  -->
					</div>
				</div>
			</div>
		`;

		let setINVL_wait_div_DYScript = setInterval(() => {
			if ($H2P('div#div-DYScript')) {
				window.clearInterval(setINVL_wait_div_DYScript);
				setINVL_wait_div_DYScript = null;
				$H2P('div#div-DYScript').appendChild(div);
				setTimeout(resolve, 250);
			}
		}, 500);
	})
	.then(() => {
		let eleConfig = $H2P('div#h2p-div-config');
		eleConfig.addEventListener('click', (event) => {
			let target = event.target;
			if (target.tagName.toLowerCase() !== 'button') { return; }
			target.classList.toggle('h2p-bg-open');
			if (target.id === 'h2p-btn-config-show0') { 
				config_tool.show0 = !config_tool.show0;
				config_tool.show9 = false;
				$H2P('button#h2p-btn-config-show9').classList.remove('h2p-bg-open');
			} else if (target.id === 'h2p-btn-config-show9') { 
				config_tool.show0 = false;
				$H2P('button#h2p-btn-config-show0').classList.remove('h2p-bg-open');
				config_tool.show9 = !config_tool.show9;
			} else if (target.id === 'h2p-btn-config-hideBar') { 
				config_tool.hideBar = !config_tool.hideBar;
			} else if (target.id === 'h2p-btn-config-hideSound') { 
				config_tool.hideSound = !config_tool.hideSound;
			} else if (target.id === 'h2p-btn-config-getFB') { 
				config_tool.getFB = !config_tool.getFB;
			} else if (target.id === 'h2p-btn-config-signIn') { 
				config_tool.signIn = !config_tool.signIn;
			} else if (target.id === 'h2p-btn-config-anchorUp') { 
				config_tool.anchorUp = !config_tool.anchorUp;
			}
			localStorage.setItem(LSConfig, JSON.stringify(config_tool));
		}, false);
	})
	.then(() => {
		if (config_tool.show0) {
			$H2P('button#h2p-btn-config-show0').classList.add('h2p-bg-open');
			console.log('启动 : 最低画质');
			auto_showDef();
		}
		if (config_tool.show9) {
			$H2P('button#h2p-btn-config-show9').classList.add('h2p-bg-open');
			console.log('启动 : 最高画质');
			auto_showDef();
		}
		if (config_tool.hideBar) {
			$H2P('button#h2p-btn-config-hideBar').classList.add('h2p-bg-open');
			console.log('启动 : 自动禁止弹幕');
			auto_hideBar();
		}
		if (config_tool.hideSound) {
			$H2P('button#h2p-btn-config-hideSound').classList.add('h2p-bg-open');
			console.log('启动 : 自动静音');
			auto_hideSound();
		}
		if (config_tool.getFB) {
			$H2P('button#h2p-btn-config-getFB').classList.add('h2p-bg-open');
			console.log('启动 : 自动领取观看鱼丸');
			auto_getFB();
		}
		if (config_tool.signIn) {
			$H2P('button#h2p-btn-config-signIn').classList.add('h2p-bg-open');
			console.log('启动 : 自动签到');
			auto_signIn();
		}
		if (config_tool.anchorUp) {
			$H2P('button#h2p-btn-config-anchorUp').classList.add('h2p-bg-open');
			console.log('启动 : 自动赠送荧光棒');
			auto_anchorUp();
		}
	})
	.catch(error => { console.log(error); })
})();