// ==UserScript==
// @name BILIBILI-Beautify
// @namespace http://github.com/yuhanawa/UserScript
// @version 0.0.1.0
// @description: Beautify BILIBILI[WIP]
// @node 更新日志请见 https://github.com/yuhanawa/UserScript/blob/master/CHANGELOG.md
// @author Yuhanawa
// @supportURL http://github.com/yuhanawa/UserScript
// @license GPL-3.0
// @match *://*.bilibili.com//*
// @icon none
// @run-at document-start
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_addStyle
// @grant GM_registerMenuCommand
// @description 哔哩哔哩BILIBILI[开发中] 美化|增强|自定义背景|评论过滤等
// ==/UserScript==
function $get(k,d){return GM_getValue(k,d)}
function $set(k,v){return GM_setValue(k,v)}
function style(css){var node;"undefined"!=typeof GM_addStyle?GM_addStyle(css):((node=document.createElement("style")).appendChild(document.createTextNode(css)),document.body.appendChild(node))}
function option(name,key,options,current,index,onclick){return null!=current&&null!=index||(current=$set(key,getOptionKeyAndName(options[0]).key),index=options.indexOf(options.filter(x=>getOptionKeyAndName(x).key==current)[0])),-1!==index&&null!=index||($set(key,getOptionKeyAndName(options[0]).key),current=getOptionKeyAndName(options[index=0]).key),name+=`:${getOptionKeyAndName(options[index]).name}[${index+1}/${options.length}]<点击切换模式`,GM_registerMenuCommand(name,()=>{if(index+1>=options.length?$set(key,getOptionKeyAndName(options[0]).key):$set(key,getOptionKeyAndName(options[index+1]).key),onclick)try{onclick()}catch{}location.reload()}),index}
function onload(f){isLoaded?f():document.addEventListener("DOMContentLoaded",()=>f())}
function timeoutOnLoad(f,t){onload(()=>setTimeout(()=>f(),t))}
function intervalOnLoad(f,timeout){onload(()=>setInterval(f,timeout))}
function run(fts){void 0===fts&&(fts=features);for(const key of Object.keys(fts)){var feature=fts[key];0!=feature.match.filter(m=>"string"==typeof m?null!==window.location.href.match(m):m.test(window.location.href)).length&&addFeature(key,feature)}}
function addFeature(key,feature){console.log(feature);var name=feature.name,values=feature.values,options=Object.keys(values),key0=getOptionKeyAndName(options[0]).key;let current=$get(key,key0),index=options.indexOf(options.filter(x=>getOptionKeyAndName(x).key==current)[0]);-1!==index&&null!=index||($set(key,key0),index=0,current=key0),option(name,key,options,current,index);try{var result,value=values[options[index]];null!=value&&("function"==typeof value?"string"==typeof(result=value(feature))&&style(result):"string"==typeof value?style(value):console.error(`出现了不应该出现的类型: ${typeof value} `+value))}catch(e){console.error(e)}}
function getOptionKeyAndName(optionStr){var key=optionStr.match(/\$([^ ]+)/)?.[0];return key?{key:key.replace("$",""),name:optionStr.replace(key,"")}:{key:optionStr,name:optionStr}}isLoaded=!1,onload(()=>isLoaded=!0);
let features_bilibili_6068={
bilibili_beautify:{name:"样式美化 | 自定义背景 | 大幅度修改",match:["bilibili.com"],values:{"已开启$on":()=>("on"===$get("bilibili_eye_protection_cover","on")?style("html,:root{--bodybackground: "+(window.matchMedia("(prefers-color-scheme: dark)").matches?$get("bilibili_eye_protection_cover_dark","rgb(0 0 0 / 23%)"):$get("bilibili_eye_protection_cover_light","rgb(102 204 255 / 23%)"))+"}"):style("html,:root{--bodybackground:transparent}"),style(`html,:root{--background:${$get("bilibili_background_value","url(//s1.hdslb.com/bfs/static/stone-free/dyn-home/assets/bg.png)")}}`),":root,html{background:url(https:pixiv.re/34844544.jpg);background-attachment:fixed!important;background:var(--background);background-repeat:no-repeat repeat;background-size:100% 100%;bottom:0;--text3:var(--text2)}:root body,html body{background-color:transparent;background:var(--bodybackground);height:auto}:root body .app-v1,:root body .fixed-reply-box,:root body .visitor,html body .app-v1,html body .fixed-reply-box,html body .visitor{background-color:rgba(255,255,255,.68)!important}:root body . fixed-reply-box,:root body .left-container-under-player,:root body .right-container,:root body .visitor,html body .fixed-reply-box,html body .left-container-under-player,html body .right-container,html body .visitor{opacity:.97}:root body .act-end,:root body .activity-m-v1,html body .act-end,html body .activity-m-v1{border-radius:12px}:root body .bili-comment,:root body .browser-pc,html body .bili-comment,html body .browser-pc{background-color:rgba(255,255,255,.68)!important; border-radius:10px;padding:0;margin:0}:root body #comment,html body #comment{box-shadow:0 0 4px #f5f5f5;margin-top:2px;padding:0;border-radius:10px}:root body #comment .reply-list,html body #comment .reply-list{padding:0 18px 0 2px}:root body .left-container-under-player,html body .left-container-under-player{background-color:transparent!important}:root body #arc_toolbar_report,html body #arc_toolbar_report{margin-top:-5px;padding-top:20px;padding-left:12px;padding-right:12px;border:0;opacity:.8;background-color:rgba(255,255,255,.65)!important;border-radius:0 0 6px 6px}:root body .video-desc-container,html body .video-desc-container{padding:10px 8px 14px;margin:0;opacity:.68}:root body .video-tag-container,html body .video-tag-container{margin:0;padding:8px 2px 2px;border-style:dashed;border-width:1px 0;border-color:#e3e5e7;border-color:var(--text4)}:root body .tag-link .newchannel-link,:root body .video-tag-container .tag-panel a,html body .tag-link .newchannel-link,html body .video-tag-container .tag-panel a{background:#fff}:root body .bili-header__bar .mini-header,html body .bili-header__bar .mini-header{opacity:.96}:root body video,html body video{border-radius:4px 4px 0 0}: root body .bpx-player-video-area,html body .bpx-player-video-area{border-radius:4px 4px 0 0;background:0 0}:root body .reply-header,html body .reply-header{margin:0 0-4px 14px;padding:12px 0 0 2px}:root body .reply-box,html body .reply-box{padding-right:16px!important}:root body .danmaku-wrap>.bpx-docker,html body .danmaku-wrap>.bpx-docker{background:0 0}:root body #bilibili-player-placeholder,html body #bilibili-player-placeholder{box-shadow:0-2px 4px 1px rgba(255,255,255,.1);border-radius:4px 4px 12px 12px}:root body #bilibili-player-placeholder #bilibili-player-placeholder-top,html body #bilibili-player-placeholder #bilibili-player-placeholder-top{border-radius:4px 4px 0 0;background:0 0!important}:root body #bilibili-player-placeholder #bilibili-player-placeholder-bottom,html body #bilibili-player-placeholder #bilibili-player-placeholder-bottom{border-radius:0 0 12px 12px}"),"已关闭$off":null}},
bilibili_bilibili_remove_search:{name:"移除评论关键字搜索跳转",match:["www.bilibili.com/video","www.bilibili.com/read"],values:{"已关闭$off":null,"已开启$on":()=>{intervalOnLoad(()=>{var as=document.getElementsByClassName("jump-link search-word");for(let i=0;i<as.length;i++)as[i].parentElement.outerHTML=as[i].parentElement.outerHTML.replace(as[i].outerHTML,as[i].outerText);0<as.length&&console.log(`remove ${as.length} search icon`)},8e3)}}},
bilibili_bilibili_remove_search_icon:{name:"移除评论关键字搜索图标",match:["www.bilibili.com/video","www.bilibili.com/read"],values:{"已启用$on":()=>{intervalOnLoad(()=>{var icons=document.getElementsByClassName("icon search-word");for(let i=0;i<icons.length;i++)icons[i].remove();0<icons.length&&console.log(`remove ${icons.length} search icon`)},8e3)},"已关闭$off":null}},
bilibili_quickly_copy:{name:"视频快捷分享复制模式",match:["www.bilibili.com/video"],values:{"[标题]链接$all":feature=>{intervalOnLoad(()=>{feature.fn("[标题]链接",`【${document.querySelector("h1.video-title").innerText}】 `+location.origin+location.pathname)},1200)},BV$BV:feature=>{intervalOnLoad(()=>{feature.fn("BV",location.pathname.split("/")[2])},1200)},"链接$url":feature=>{intervalOnLoad(()=>{feature.fn("链接",""+location.origin+location.pathname)},1200)},"标题$title" :feature=>{intervalOnLoad(()=>{feature.fn("标题",""+document.querySelector("h1.video-title").innerText)},1200)},"关闭$off":null},fn:(title,text)=>{var copy_btn;-1===document.querySelector("h1.video-title").innerHTML.indexOf("🏷️")&&((copy_btn=document.createElement("span")).title="复制当前视频的"+title,copy_btn.style.cursor="pointer",copy_btn.innerText="🏷️",copy_btn.addEventListener("click",()=>navigator.clipboard.writeText(text)),document.querySelector(" h1.video-title").append(copy_btn))}},
bilibili_video_beautify:{name:"视频页样式微调",match:["www.bilibili.com/video"],values:{"已开启$on":feature=>(timeoutOnLoad(()=>{console.log(feature),window.addEventListener("scroll",()=>feature.fn())},800),'@charset "UTF-8";#app .video-container-v1{padding:0px 🔑uPjWDZ.5px }#app .video-container-v1 #viewbox_report{height:auto;padding-bottom:22px}#app .video-container-v1 #viewbox_report h1{text-wrap:wrap}#app .video-container-v1 .left-container{width:auto!important} #app .video-container-v1 .left-container #playerWrap{height:auto}#app .video-container-v1 .left-container #playerWrap #bilibili-player{width:100%!important;height:100%!important}'.replace("🔑uPjWDZ",$get("container_padding",60))),"已关闭$off":null},fn:()=>{var playerWrap=document.getElementById("playerWrap");let width=Math.floor(playerWrap.getBoundingClientRect().width);width%2!=0&&width++,playerWrap.style.width=width+"px",playerWrap.style.height=playerWrap.getBoundingClientRect().height+"px",window.removeEventListener("scroll",()=>feature.fn())}}
};
run(features_bilibili_6068);