// ==UserScript==
// @name bilibili弹幕定位
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 在进度条上定位弹幕
// @author mscststs
// @match www.bilibili.com/video/*
// @grant non
// ==/UserScript==
(function () {
'use strict';
var danmu = [];
var ava = 0;
var result = [];
var good_count = 0;
function search(tkey){
result = [];
$.each(danmu,function(i,a){
if(a.text.indexOf(tkey)>=0){
result.push(a);
}
});
if(result.length>0){
ava = 1;
}else{
ava = 0;
}
info("搜索完毕,共找到"+result.length+"条弹幕");
}
function pushArray(obj){
danmu.push(obj);
}
function ArraySort(){
danmu.sort(function(a,b){
return a.time-b.time;
});
init();
//数据初始化完毕,do something here
}
function saveXml(xml){
$(xml).find("d").each(function(i)
{
var vas = $(this).attr("p").split(',');
var time = vas[0];
var dmid = vas[7];
var text = $(this).text();
var odanmu = new Object();
odanmu.time = time;
odanmu.dmid = dmid;
odanmu.text = text;
pushArray(odanmu);
});
ArraySort();
}
function StandardTaxRate()
{
$.ajax({
url: "https://comment.bilibili.com/"+cid+".xml",
dataType: 'xml',
type: 'GET',
timeout: 2000,
error: function(xml)
{
alert("初始化失败");
},
success: function(xml)
{
saveXml(xml);
}
});
}
StandardTaxRate();
function info(text){
$("#helper_info").text(text);
}
function creatPanal(){
$(".player-wrapper").prepend('<div id="helper_tools"></div>');
$("#helper_tools").css({
"position":"fixed",
"background-color":"rgba(255,255,255,0.7)",
"left":"5px",
"top":"200px",
"width":"120px",
"height":"300px",
"z-index":"10000",
"box-shadow":"0px 0px 6px rgba(0,0,0,0.6)"
});
}
function creatTool(){
$("#helper_tools").append('<div id="helper_message"></div>');
$("#helper_message").css({
"position":"absolute",
"line-height":"20px",
"left":"0px",
"top":"0px",
"color":"white",
"font-family":"console",
"font-size":"15px",
"padding":"5px",
"width":"110px",
"height":"40px",
"background-color":"#ffafc9"
});
$("#helper_message").text("弹幕扫描完毕 就是这样~喵");
$("#helper_tools").append('<input type="text" id="helper_input" placeholder="这里填关键字!">');
$("#helper_tools").append('<button type="button" class="b-btn" id="helper_love">爱一下</button>');
$("#helper_tools").append('<button type="button" class="b-btn" id="helper_eval">邪恶一下</button>');
$("#helper_tools").append('<div id="helper_info"></div>');
$("#helper_input").css({
"position":"absolute",
"left":"0px",
"top":"50px",
"font-family":"console",
"font-size":"16px",
"width":"118px",
"height":"25px"
});
$("#helper_info").css({
"position":"absolute",
"left":"0px",
"line-height":"20px",
"top":"80px",
"color":"white",
"font-family":"console",
"font-size":"15px",
"padding":"5px",
"width":"110px",
"height":"140px",
"background-color":"#ffafc9"
});
$("#helper_love").css({
"position":"absolute",
"left":"2px",
"top":"235px",
"font-family":"console",
"font-size":"18px",
"width":"116px",
"height":"30px",
"background-color":"white",
"color":"#f25d8e",
"border":"1px solid #f25d8e"
});
$("#helper_love").hover(function(){
$("#helper_love").css({"background-color":"#f25d8e","color":"white"});
},function(){
$("#helper_love").css({"background-color":"white","color":"#f25d8e"});
});
$("#helper_eval").css({
"position":"absolute",
"left":"2px",
"top":"267px",
"font-family":"console",
"font-size":"18px",
"width":"116px",
"height":"30px"
});
info("先输入关键词,再进行操作。一次举报大量弹幕可能会导致封号!");
}
function mark(){
$(".helper").remove();
var pro = $(".bilibili-player-video-progress-buffer");
var atime = $("span.bilibili-player-video-time-total").text().split(":");
var altime = atime[0]*60+atime[1];
var pwidth = pro.css("width")-30;
var pheight = pro.css("height");
$.each(result,function(i,a){
var le = (a.time+25)/altime*100*100;
le = le*0.93+2;
if(le>60){
le=le+1;
}
// console.log(le);
var $div = $('<div class="helper"></div>');
$div.css({
"position":"absolute",
"width":"1px",
"height":pheight,
"left":le+"%",
"background-color":"red",
"padding":"0",
"margin":"0",
"z-index":"100"
});
pro.append($div);
});
}
function eval_send(dmid) {
$.ajax({
//提交数据的类型 POST GET
type: "POST",
//提交的网址
url: "https://api.bilibili.com/x/dm/report/add",
//提交的数据
data: {cid:cid,
dmid:dmid,
reason:1,
content:""},
//返回数据的格式
datatype: "JSONP",//"xml", "html", "script", "json", "jsonp", "text".
//在请求之前调用的函数
//beforeSend:function(){$("#msg").html("logining");},
//成功返回之后调用的函数
success: function (data) {
},
xhrFields: {
withCredentials: true
},
crossDomain: true,
complete: function () {
//HideLoading();
},
//调用出错执行的函数
error: function () {
//请求出错处理
}
});
}
function init(){
creatPanal();
creatTool();
$("#helper_love").click(function(){
if(ava==1){
good_count = 0;
}else{
search("空降");
}
mark();
});
$(document).on("click","button#helper_eval",function(){
//alert("hello");
if(ava==1){
good_count = 0;
$.each(result,function(i,a){
//console.log(a.dmid);
eval_send(a.dmid);
good_count++;
});
info("处理完毕:"+good_count+" / "+result.length);
}
});
$("#helper_input").bind("input propertychange",function(){
var tkey = $(this).val();
//console.log(tkey);
if(tkey.length>0){
search(tkey);
}else{
ava = 0;
info("先输入关键词,再进行操作。一次举报大量弹幕可能会导致封号!");
}
});
}
})();