|
发表于
2022-1-9 19:09:03
|
显示全部楼层
// ==UserScript==
// @name 弹幕
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.bilibili.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js
// @grant none
// ==/UserScript==
/* globals jQuery, $, waitForKeyElements */
//弹幕数组数据350条
var data = [
"1",
"2",
"3",
"4",
"5",
];
var data2 = [
"a",
"b",
"c",
"d",
"e",
];
//下拉框
let triple1=document.createElement("button");
triple1.innerHTML='<div id="dg" style="position: fixed ! important; left: 0px; top: 240px"><select id="id001" style="width: 55px;padding:3px;background-color: #00A1D6;bd;color: #fff;-webkit-border-radius: 5px;border-radius: 5px;-khtml-border-radius: 5px;text-align: center;vertical-align: middle;border: 1px solid transparent;font-weight: 900;font-size:100%"><option value="1">普通</option><option value="2" >面试</option></select></div>'
//开始
let triple2=document.createElement("button");
triple2.innerHTML='<div id="dg" style="position: fixed ! important; left: 0px; top: 150px"><button id="id002" type="button" style="width: 46px;padding:3px;background-color: #00A1D6;bd;color: #fff;-webkit-border-radius: 5px;border-radius: 5px;-khtml-border-radius: 5px;text-align: center;vertical-align: middle;border: 1px solid transparent;font-weight: 900;font-size:110%">开始</button></div>'
//停止
let triple3=document.createElement("button");
triple3.innerHTML='<div id="dg" style="position: fixed ! important; left: 0px; top: 180px"><button id="id003" type="button" style="width: 46px;padding:3px;background-color: #00A1D6;bd;color: #fff;-webkit-border-radius: 5px;border-radius: 5px;-khtml-border-radius: 5px;text-align: center;vertical-align: middle;border: 1px solid transparent;font-weight: 900;font-size:110%">停止</button></div>'
//长期
let triple4=document.createElement("button");
triple4.innerHTML='<div id="dg" style="position: fixed ! important; left: 0px; top: 210px"><button id="id004" type="button" style="width: 46px;padding:3px;background-color: #00A1D6;bd;color: #fff;-webkit-border-radius: 5px;border-radius: 5px;-khtml-border-radius: 5px;text-align: center;vertical-align: middle;border: 1px solid transparent;font-weight: 900;font-size:110%">长期</button></div>'
var flag=true;
var num = 1;
function countNum() {
if(flag){
flag = false;
var a = Math.floor(Math.random()*(4 + 1 - 0));
let t=document.getElementsByClassName("bilibili-player-video-danmaku-input")[0];
let evt = document.createEvent('HTMLEvents');
evt.initEvent('input', true, true);
//
var myselect=document.getElementById("id001");
var index=myselect.selectedIndex;
if (myselect.options[index].value==1){
t.value=data[a];
}else if(myselect.options[index].value==2){
t.value=data2[a];
}
t.dispatchEvent(evt);
evt.initEvent('keydown', true, false)
evt = Object.assign(evt, {
ctrlKey: false,
metaKey: false,
altKey: false,
which: 13,
keyCode: 13,
key: 'Enter',
code: 'Enter'
})
t.focus()
t.dispatchEvent(evt)
setTimeout(function() {
flag = true;
}, 5000);
}
console.log('刷了多少条: ' + num);
num++
}
//开始按钮
triple2.onclick=function(){
countNum();
var ia=0;
var timer = setInterval(function() {
if(flag){
flag = false;
var a = Math.floor(Math.random()*(4 + 1 - 0));
let t=document.getElementsByClassName("bilibili-player-video-danmaku-input")[0];
let evt = document.createEvent('HTMLEvents');
evt.initEvent('input', true, true);
//
var myselect=document.getElementById("id001");
var index=myselect.selectedIndex;
if (myselect.options[index].value==1){
t.value=data[a];
}else if(myselect.options[index].value==2){
t.value=data2[a];
}
t.dispatchEvent(evt);
evt.initEvent('keydown', true, false)
evt = Object.assign(evt, {
ctrlKey: false,
metaKey: false,
altKey: false,
which: 13,
keyCode: 13,
key: 'Enter',
code: 'Enter'
})
t.focus()
t.dispatchEvent(evt)
setTimeout(function() {
flag = true;
}, 5000);
}
console.log('刷了多少条: ' + num);
num++
setTimeout(function() {
var m=document.getElementsByClassName("bilibili-player-video-danmaku-input")[0];
console.log(m.value);
if(m.value ==data[a]){
console.log("自己停止");
clearInterval(timer);//跳出setInterval定时器
}
},3000)
triple3.onclick=function(){
//停止
console.log("已经停止");
clearInterval(timer);//跳出setInterval定时器
}
},7000)
}
//长期
triple4.onclick=function(){
//countNum();
var ia=0;
var timer = setInterval(function() {
var a = Math.floor(Math.random()*(4 + 1 - 0));
let t=document.getElementsByClassName("bilibili-player-video-danmaku-input")[0];
let evt = document.createEvent('HTMLEvents');
evt.initEvent('input', true, true);
//
var myselect=document.getElementById("id001");
var index=myselect.selectedIndex;
if (myselect.options[index].value==1){
t.value=data[a];
}else if(myselect.options[index].value==2){
t.value=data2[a];
}
t.dispatchEvent(evt);
evt.initEvent('keydown', true, false)
evt = Object.assign(evt, {
ctrlKey: false,
metaKey: false,
altKey: false,
which: 13,
keyCode: 13,
key: 'Enter',
code: 'Enter'
})
t.focus()
t.dispatchEvent(evt)
console.log('刷了多少条: ' + num);
num++
setTimeout(function() {
var m=document.getElementsByClassName("bilibili-player-video-danmaku-input")[0];
console.log(m.value);
if(m.value ==data[a]){
console.log("自己停止");
clearInterval(timer);//跳出setInterval定时器
}
},3000)
triple2.onclick=function(){
//停止
console.log("已经停止");
clearInterval(timer);//跳出setInterval定时器
}
},20000 * (ia+1))
}
//定时器延迟显示两个按钮
setTimeout(function() {
document.body.append(triple1);
document.body.append(triple2);
document.body.append(triple3);
document.body.append(triple4);
},3000)
//开始按键
triple2.onmouseover=function(){
//鼠标移入按钮颜色
triple2.style.backgroundColor='#1A73E8';
}
triple2.onmouseout=function(){
//鼠标移出按钮颜色
triple2.style.backgroundColor='#00A1D6';
}
//停止按键
triple3.onmouseover=function(){
//鼠标移入按钮颜色
triple3.style.backgroundColor='#1A73E8';
}
triple3.onmouseout=function(){
//鼠标移出按钮颜色
triple3.style.backgroundColor='#00A1D6';
}
//长期按键
triple4.onmouseover=function(){
//鼠标移入按钮颜色
triple4.style.backgroundColor='#1A73E8';
}
triple4.onmouseout=function(){
//鼠标移出按钮颜色
triple4.style.backgroundColor='#00A1D6';
}
//下拉框
triple1.onmouseover=function(){
//鼠标移入按钮颜色
triple1.style.backgroundColor='#1A73E8';
}
triple1.onmouseout=function(){
//鼠标移出按钮颜色
triple1.style.backgroundColor='#00A1D6';
} |
|