// ==UserScript== // @name Bili Zhuli // @namespace https://greasyfork.org/users/34380 // @version 20180621 // @description Bilibili 20180621助力活动 // @match https://steamcn.com/t399231-*-1 // @match https://www.bilibili.com/blackboard/mall/activity-B1oZiV-Z7.html?uid=* // @grant GM_setValue // @grant GM_getValue // @grant GM_listValues // @grant GM_deleteValue // @run-at document-idle // @downloadURL none // ==/UserScript== (function () { 'use strict'; // Your code here... const loc_hostname = window.location.hostname; const loc_href = window.location.href; if (loc_hostname === "steamcn.com") { const scr_run = document.createElement("a"); const clear_all = document.createElement("a"); scr_run.id = "open-links"; scr_run.innerText = "打开助力链接"; scr_run.onclick = function () { openBiliLinks() }; scr_run.setAttribute("alt", "打开本页面可看到的未助力链接"); clear_all.id = "clear-links"; clear_all.innerText = "清除助力记录"; clear_all.onclick = function () { clearOpenedLinks() }; clear_all.setAttribute("alt", "记录助力过的人,每日记得手动清除,再次助力"); document.querySelector("#pgt").appendChild(scr_run); document.querySelector("#pgt").appendChild(clear_all); function openBiliLinks() { let floors = document.querySelectorAll(".t_f"); let opened_links = GM_getValue("BLZL_links", ""); if (opened_links !== "") { opened_links = opened_links.split(","); } else { opened_links = []; } for (let link of floors) { const uid = link.innerHTML.match(/activity-B1oZiV-Z7\.html\?uid=(\d+)/); const tcn = link.innerHTML.match(/http:\/\/t\.cn\/\w{7}/); if (uid && !opened_links.includes(uid[1])) { window.open("https://www.bilibili.com/blackboard/mall/activity-B1oZiV-Z7.html?uid=" + uid[1]); } else if (tcn) { window.open(tcn[0]); } } } function clearOpenedLinks() { GM_listValues().map(GM_deleteValue); } } else if (loc_hostname === "www.bilibili.com") { const uid = loc_href.match(/activity-B1oZiV-Z7\.html\?uid=(\d+)/); var mclick = new MouseEvent("click", { bubbles: true, }); setInterval(function () { const btn_loaded = document.querySelector(".zhuli_score"); if (btn_loaded) { let opened_links = GM_getValue("BLZL_links", ""); if (opened_links !== "") { opened_links = opened_links.split(","); } else { opened_links = []; } const btn_zhuli = document.querySelector("#zhuliBtn"); if (btn_zhuli) { btn_zhuli.dispatchEvent(mclick); } else if (!opened_links.includes(uid[1])) { opened_links.push(uid[1]); GM_setValue("BLZL_links", opened_links.join(",")); window.close(); } else { window.close(); } } }, 2000); } })();