// ==UserScript== // @name 在B站动态添加热门和今日新番 // @description B站动态添加热门和今日新番 // @description:en B站动态添加热门和今日新番 // @version 0.1 // @description try to take over the world! // @author chancoki // @include /https:\/\/t\.bilibili\.com\/.*/ // @icon https://www.bilibili.com/favicon.ico // @grant none // @namespace https://greasyfork.org/users/754467 // @downloadURL none // ==/UserScript== (function () { "use strict"; window.onload = () => { const body = document.body; const bili = document.querySelector(".left-panel"); const fan = document.querySelector(".right-panel"); document.querySelector(".home-content").style.width = "1300px"; bili.innerHTML = ""; bili.style.width = "332px"; fan.innerHTML = ""; fan.style.width = "305px"; const p = document.createElement("p"); const div = document.createElement("div"); const ifr = document.createElement("iframe"); ifr.className = "ifr"; ifr.noResize = true; div.className = "aView"; body.appendChild(div); body.appendChild(p); body.appendChild(ifr); let isShu = true; let isBig = true; bili.style.height = document.documentElement.clientHeight + "px"; fan.style.height = document.documentElement.clientHeight + "px"; p.innerHTML = ` `; let isAction = true; let li = ""; let flag = 1; async function a(num) { if (isAction) { isAction = false; const res = await fetch( `https://api.bilibili.com/x/web-interface/popular?ps=25&pn=${num}` ); const data = await res.json(); bili.innerHTML += send(data.data.list, li); isAction = true; } } function aView(flag) { div.style.display = "block"; div.innerHTML = flag; setTimeout(() => { div.style.display = "none"; }, 4000); } function send(data, li) { for (let i of data) { li += `
  • ${i.title}
    ${i.title}

    ${i.owner.name}

    ${setView(i.stat.view)}万观看 ${getLocalTime(i.ctime)}
    ${getVidieoTime(i.duration)}
  • `; } return li; } a(flag); const btn = document.querySelector(".c_btn1"); const up = document.querySelector(".c_up"); const cha = document.querySelector(".c_cha"); const big = document.querySelector(".c_big"); const shu = document.querySelector(".c_shu"); btn.addEventListener("click", (e) => { e.cancelBubble = true; aView("正在刷新..."); li = ""; bili.innerHTML = ""; flag = 1; a(flag); }); big.addEventListener("click", (e) => { if (isBig) { ifr.className = "ifr_b ifr"; } else { ifr.className = "ifr"; } isBig = !isBig; }); shu.addEventListener("click", (e) => { if (isShu) { ifr.className = "ifr_s ifr"; } else { ifr.className = "ifr"; } isShu = !isShu; }); up.addEventListener("click", (e) => { aView("回到开始"); bili.scrollTo({ top: 0, left: 0, behavior: "smooth", }); }); bili.addEventListener("click", (e) => { e.cancelBubble = true; if (e.target.nodeName.toLowerCase() == "img") { let query = e.target.className; ifr.src = "//player.bilibili.com/player.html?" + query; ifr.style.display = "block"; cha.style.display = "block"; big.style.display = "block"; shu.style.display = "block"; } }); cha.addEventListener("click", () => { ifr.src = ""; ifr.style.display = "none"; cha.style.display = "none"; big.style.display = "none"; shu.style.display = "none"; }); function getVidieoTime(num) { return parseInt(num / 60) + ":" + (num % 60); } function getLocalTime(nS) { let time = new Date(parseInt(nS) * 1000); let newTime = new Date() .toLocaleDateString() .replace(/\//g, "-") .substr(5, 10); let DataTime = time .toLocaleDateString() .replace(/\//g, "-") .substr(5, 10); if (newTime == DataTime) { DataTime = ""; } return DataTime + " " + time.toTimeString().substr(0, 5); } function setView(data) { return parseInt(data / 10000); } bili.addEventListener("scroll", () => { var scrollTop = bili.scrollHeight - bili.scrollTop; if (scrollTop <= document.documentElement.clientHeight + 10) { if (flag <= 9 && isAction) { flag++; aView("正在加载..."); a(flag); } else if (flag == 10) { aView("别刷了,没有了"); } } }); window.addEventListener("resize", () => { bili.style.height = document.documentElement.clientHeight + "px"; fan.style.height = document.documentElement.clientHeight + "px"; }); let fli = ""; async function a1() { const res = await fetch( `https://bangumi.bilibili.com/web_api/timeline_global` ); const data = await res.json(); fli = fsend(data.result, fli); b(); } async function b() { const res = await fetch( `https://bangumi.bilibili.com/web_api/timeline_cn` ); const data = await res.json(); fan.innerHTML = fsend(data.result, fli); } function fsend(data, li) { let seasons = data[6].seasons; let time = Date.parse(new Date()) / 1000; for (let i of seasons) { li += `
  • ${i.pub_time}

    ${i.title}

    ${i.pub_index ? i.pub_index : i.delay_reason}

  • `; } return li; } function getPage(child, height) { return 87 * child >= height ? true : false; } a1(); const fbtn = document.querySelector(".c_btn"); fbtn.addEventListener("click", (e) => { e.cancelBubble = true; fli = ""; fan.innerHTML = ""; a1(); }); document.addEventListener("scroll", () => { let page = window.pageYOffset; if (page > 60) { if ( getPage(fan.children.length, document.documentElement.clientHeight) ) { fan.style.top = "0"; } else { fan.style.top = "4px"; } } else { fan.style.top = "64px"; } }); fan.addEventListener("click", (e) => { if ( e.target.nodeName.toLowerCase() == "li" || e.target.nodeName.toLowerCase() == "img" || e.target.nodeName.toLowerCase() == "div" || e.target.nodeName.toLowerCase() == "p" ) { open(e.target.id, "_blank"); } }); }; // Your code here... })();