B站三连
// ==UserScript==
// @name B站三连
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.1
// @description try to take over the world!
// @author 张仨
// @match https://www.bilibili.com/video/*
// @grant none
// @run-at document-end
// ==/UserScript==
(function () {
'use strict';
let triple = document.createElement("div");
triple.style.width = "46%";
triple.innerHTML = `
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="container">
<i class="fa fa-heartbeat" aria-hidden="true"></i>
<span>一键三连</span>
</div>
<style>
.container{
display: flex;
color: #505050;
cursor: pointer;
align-items: center;
}
.container:hover{
color: #00b5e5;
}
.container i{
font-size: 26px;
margin-left: 6px;
margin-left: 26px;
}
.container span{
font-size: 14px;
margin-left: 6px;
}
</style>`
triple.onclick = function () {
//三连代码
let httpRequest = new XMLHttpRequest();
httpRequest.open('POST', 'https://api.bilibili.com/x/web-interface/archive/like/triple');
httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpRequest.withCredentials = true;//设置跨域发送
let aid = window.__INITIAL_STATE__.aid;
let sKey = "bili_jct";
let csrf = decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[-.+*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
httpRequest.send('aid=' + aid + '&csrf=' + csrf);
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
var json = JSON.parse(httpRequest.responseText);
console.log(json);
if (json.code == 0) {
var r = confirm("三连成功,是否刷新网页!");
if (r == true) {
location.reload();
}
} else {
alert("三连失败/(ㄒoㄒ)/~~");
}
}
};
};
let ops = document.querySelector('#arc_toolbar_report .ops');
ops.addEventListener("DOMNodeInserted", function (event) {
ops.parentElement.appendChild(triple);
});
})();