NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name bilibili一键四连 // @namespace https://github.com/b1ackc4t // @version 0.1 // @license MIT // @description 一键进行关注点赞投币收藏,再点则取消 // @author b1ackc4t // @match https://www.bilibili.com/video/BV* // @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com // @run-at document-idle // ==/UserScript== (function () { 'use strict'; var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; var parent = document.getElementsByClassName('toolbar-left')[0]; var headobj = document.getElementsByTagName('head')[0]; var _style = document.createElement('style'); _style.innerText = '.video-toolbar-v1 .toolbar-left .share .info-text {\nwidth: 40px;}' headobj.appendChild(_style); window.addEventListener("load", () => { setInterval(() => { let ele = document.getElementById('b1ack_4c'); if (((document.querySelector('.already-btn') !== null && document.querySelector('.already-btn').innerText.includes("已关注")) || (document.querySelector('.up-card') !== null && document.querySelector('.up-card').children[0].children.length === 1)) && document.querySelector('.like').classList.contains('on')) { ele.setAttribute("class", "on"); } else { ele.setAttribute("class", ""); } }, 1500); }) var observer = new MutationObserver(function () { var collect = document.getElementsByClassName('collect')[0]; var ele = document.createElement('span'); ele.setAttribute('id', 'b1ack_4c'); parent.appendChild(ele) var svg = document.createElement('svg'); svg.setAttribute('width', 36); svg.setAttribute('height', 36); svg.setAttribute('role', 'img'); svg.setAttribute('viewBox', '0 0 24 24'); svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); svg.innerHTML = atob('PHRpdGxlIGlkPSJib2x0SWNvblRpdGxlIj5Cb2x0PC90aXRsZT4KICAgICAgICAgIDxwYXRoIGQ9Ik01IDE0bDgtMTF2N2g1bC04IDExdi03eiI+PC9wYXRoPg=='); ele.innerHTML = svg.outerHTML; var text = document.createElement('span'); text.setAttribute('class', 'info-text'); text.innerText = '一键四连'; ele.appendChild(text); ele.addEventListener('click', doubleContin); // setTimeout(() => { // if (((document.querySelector('.already-btn') !== null && // document.querySelector('.already-btn').innerText.includes("已关注")) || // document.querySelector('.up-card').children[0].children.length === 1) && // document.querySelector('.like').classList.contains('on')) { // ele.setAttribute("class", "on"); // } // }, 1000); }); observer.observe(parent, { attributes: true //configure it to listen to attribute changes }); function getCookie(objName) {//获取指定名称的cookie的值 var arrStr = document.cookie.split("; "); for (var i = 0; i < arrStr.length; i++) { var temp = arrStr[i].split("="); if (temp[0] == objName) return unescape(temp[1]); } return ""; } function doubleContin(eve) { let star = document.querySelector('.like'); if (!this.classList.contains('on')) { let evt = new MouseEvent("mouseup", { bubbles: true, cancelable: true, }); star.dispatchEvent(evt); evt = new MouseEvent("mousedown", { bubbles: true, cancelable: true, }); setTimeout(() => { star.dispatchEvent(evt); }, 500) if (document.querySelector('.up-card') !== null && document.querySelector('.up-card').children[0].children.length === 1) { let request = new XMLHttpRequest(); request.open("POST", "https://api.bilibili.com/x/relation/modify"); request.withCredentials = true; request.responseType = 'json'; request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); let data = new FormData(); let space = document.querySelector('.up-card').children[0].getAttribute("href"); let fid = /\d+/i.exec(space); data.append("fid", fid); data.append("act", 1); data.append("re_src", 129); data.append("cross_domain", "true"); data.append("csrf", getCookie('bili_jct')); let par = []; for (let pair of data.entries()) { par.push( encodeURIComponent(pair[0]) + '=' + encodeURIComponent(pair[1]) ) } request.send(par.join('&')); request.onreadystatechange = () => { console.log(request.response) } } if (document.querySelector('.follow-btn span') !== null) { document.querySelector('.follow-btn span').click(); } let tars = document.getElementsByClassName('attention'); if (tars !== null) { for (let t of tars) { let e = new MouseEvent("click", { bubbles: true, cancelable: true, }); t.dispatchEvent(e); } } eve.target.setAttribute("class", "on"); this.setAttribute("class", "on"); } else { let evt = new MouseEvent("mouseup", { bubbles: true, cancelable: true, }); star.dispatchEvent(evt); setTimeout(() => { star.click(); }, 500) if (document.querySelector('.follow_dropdown') !== null) { document.querySelector('.follow_dropdown').children[1].click(); } else { let request = new XMLHttpRequest(); request.open("POST", "https://api.bilibili.com/x/relation/modify"); request.withCredentials = true; request.responseType = 'json'; request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); let data = new FormData(); let space = document.querySelector('.up-card').children[0].getAttribute("href"); let fid = /\d+/i.exec(space); data.append("fid", fid); data.append("act", 2); data.append("re_src", 129); data.append("cross_domain", "true"); data.append("csrf", getCookie('bili_jct')); let par = []; for (let pair of data.entries()) { par.push( encodeURIComponent(pair[0]) + '=' + encodeURIComponent(pair[1]) ) } request.send(par.join('&')); request.onreadystatechange = () => { console.log(request.response) } } eve.target.setAttribute("class", ""); this.setAttribute("class", ""); } } })();