// ==UserScript== // @name Bangumi/bgm.tv 每日番剧放送(仿B站) // @namespace http://tampermonkey.net/ // @version 1.1 // @description Bangumi每日番剧放送页面美化。使用页面:https://bgm.tv/calendar // @author Marsen // @match http*://bgm.tv/* // @match http*://bangumi.tv/* // @match http*://chii.in/* // @icon https://bgm.tv/img/favicon.ico // @grant GM_addStyle // @run-at document-start // @downloadURL none // ==/UserScript== (function () { 'use strict'; // 是否在顶部菜单添加放送按钮 const isAddCalendarBtn = true; // 全局变量 const leftBtnSvg = ` ` const rightBtnSvg = ` ` const globalCSS = ` /* 全局 */ #main { width: 990px; } ::selection { background:#d3d3d3; } /* header统计 */ #header small.blue { font-size: 16px; } /* 日历头 */ div.BgmCalendar dl dt { background: none; height: 35px; width: 330px; } div.BgmCalendar h3 { text-indent: 0; font-size: 2em; width: inherit; line-height: normal; color: #555; } div.BgmCalendar dl dt { background: #FFF !important; } /* 日历主体 */ .columns { width: 990px; overflow: hidden; } #colunmSingle { width: 2400px; /* 动画 */ transition: all 0.5s ease; } /* 每列栏目 */ div.BgmCalendar dl dd { border-left: 5px dotted #FF0F00; border-right: none; } div.BgmCalendar ul.large li.week { width: 300px; padding-right: 30px; } /* 海报 */ div.BgmCalendar ul.coverList li { height: 80px; width: 80px; border: none; border-radius: 4px; margin: 10px 0 0 10px; background-size: cover !important; background-position-x: inherit !important; background-position-y: inherit !important; background-repeat: no-repeat !important; } /* 标题 */ div.BgmCalendar ul.coverList li div.info_bg { background: none; -moz-opacity: initial; opacity: initial; color: #000 !important; font-size: 1.2em; font-weight: 600; line-height: normal; overflow: initial; width: 200px; height: inherit; bottom: initial; padding: 0 0 0 90px; } a.nav, a.nav:link, a.nav:visited, a.nav:active { color: #000; } div.BgmCalendar ul.coverList li:hover div.info_bg { height: initial; } div.BgmCalendar ul.coverList li:hover div.info { position: initial; bottom: initial; line-height: normal; } /* 副标题 原标题 */ .info_bg em { font-weight: 500; font-style: normal; font-size: 1em; color: #999; } /* 左右控制按钮 */ #leftBtn, #rightBtn { position: fixed; bottom: calc(50% - 100px); cursor: pointer; opacity: 20%; -moz-opacity: 20%; } #leftBtn { left: 0; } #rightBtn { right: 0; } #leftBtn:hover, #rightBtn:hover { background: rgb(245, 245, 245); opacity: 100%; -moz-opacity: 100%; }` // 添加全局css let d = new Date(); let today = d.getDay(); if (document.URL.endsWith("calendar")) { GM_addStyle(globalCSS); // css聚焦当天时间表 GM_addStyle("#colunmSingle {margin-left: " + (1 - today) * 330 + "px}"); } // 函数列表 // 添加今天标记 function headerAddTodayText() { let dic = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; let todayHeader = document.querySelector(".week." + dic[today] + " h3"); todayHeader.innerText += " (今天)"; todayHeader.style.color = "orange"; } // 时间表内容补全 function completeContent() { // 主标题补全(部分番剧无主标题) let mainTitles = document.querySelectorAll(".info p:nth-child(1)"); mainTitles.forEach(function (t) { if (t.innerText == "") { t.firstElementChild.innerText = t.nextElementSibling.innerText; } }); // 海报图片补全(冷门番剧无海报) let lostPosters = document.querySelectorAll(`.coverList li[style="background:url('//lain.bgm.tv/pic/cover/c/') 50% 20%"]`); lostPosters.forEach(function (t) { t.style.backgroundImage = "url('//lain.bgm.tv/img/no_icon_subject.png')"; }); } // 番剧链接新标签页打开 function addLinkTarget() { let linkList = document.querySelectorAll('.BgmCalendar a'); linkList.forEach(function (t) { t.setAttribute('target', '_blank'); }); } // 添加时间表左右控制按钮 function addControlBtn() { // 新建左右按钮 let leftBtn = document.createElement("div"); leftBtn.id = "leftBtn"; leftBtn.innerHTML = leftBtnSvg; let rightBtn = document.createElement("div"); rightBtn.id = "rightBtn"; rightBtn.innerHTML = rightBtnSvg; // 插入节点 let colunmSingle = document.getElementById("colunmSingle"); let parent = document.querySelector(".columns"); parent.insertBefore(leftBtn, colunmSingle); parent.appendChild(rightBtn, colunmSingle); // 添加动作 leftBtn.addEventListener("click", function (e) { let match = colunmSingle.style.transform.match(/-?\d+/); let move = 0; if (match != null) { move = parseInt(match[0]); } if (move <= -330) { colunmSingle.style.transform = "translateX(" + (move + 330) + "px)"; } }, false); rightBtn.addEventListener("click", function (e) { let match = colunmSingle.style.transform.match(/-?\d+/); let move = 0; if (match != null) { move = parseInt(match[0]); } if (move >= -1650) { colunmSingle.style.transform = "translateX(" + (move - 330) + "px)"; } }, false); } // 顶栏添加放送按钮 function addCalendarBtn() { // 新建左右按钮 let calendar = document.createElement("li"); calendar.innerHTML = `放送`; // 插入节点 let parent = document.querySelector("#navMenuNeue"); parent.insertBefore(calendar, parent.children[1]); } // 主逻辑 // 监听document载入,执行主逻辑 let stateCheck = setInterval(() => { if (document.readyState === 'interactive') { clearInterval(stateCheck); if (document.URL.endsWith("calendar")) { headerAddTodayText(); completeContent(); addLinkTarget(); addControlBtn(); } if (isAddCalendarBtn) { addCalendarBtn(); } } }); })();