Add script contents.

This commit is contained in:
the1812 2018-07-16 18:58:17 +08:00
parent f8132a21f5
commit 51a44eb4c1
18 changed files with 603 additions and 2569 deletions

File diff suppressed because it is too large Load Diff

6
style/dark-styles.js Normal file
View File

@ -0,0 +1,6 @@
function darkStyle()
{
const styles = `<style id='bilibili-new-style-dark'>${getStyle("darkStyle")}</style>`;
$("#bilibili-new-style-dark").remove();
$("body").after(darkStyles);
}

1
style/dark-styles.min.js vendored Normal file
View File

@ -0,0 +1 @@
function darkStyle(){const styles=`<style id='bilibili-new-style-dark'>${getStyle("darkStyle")}</style>`;$("#bilibili-new-style-dark").remove(),$("body").after(darkStyles)}

31
style/new-styles.js Normal file
View File

@ -0,0 +1,31 @@
function newStyle()
{
waitForQuery()(
() => $(".nav-search-keyword"),
it => it.length > 0,
textBox => textBox.attr("placeholder", "搜索")
);
waitForQuery()(
() => $(".custom-scrollbar"),
it => it.length > 0,
it => it.removeClass("custom-scrollbar")
);
const navbar = document.getElementsByClassName("bili-wrapper")[0];
let stardustStyles = false;
if (navbar instanceof Element)
{
stardustStyles = parseInt(window.getComputedStyle(navbar).height) === 50;
}
let styles = "";
if (stardustStyles)
{
styles = getStyle("style");
}
else
{
styles = getStyle("oldStyle");
}
styles = `<style id='bilibili-new-style'>${styles}</style>`;
$("#bilibili-new-style").remove();
$("body").after(styles);
}

1
style/new-styles.min.js vendored Normal file
View File

@ -0,0 +1 @@
function newStyle(){waitForQuery()(()=>$(".nav-search-keyword"),it=>it.length>0,textBox=>textBox.attr("placeholder","搜索")),waitForQuery()(()=>$(".custom-scrollbar"),it=>it.length>0,it=>it.removeClass("custom-scrollbar"));const navbar=document.getElementsByClassName("bili-wrapper")[0];let stardustStyles=!1;navbar instanceof Element&&(stardustStyles=50===parseInt(window.getComputedStyle(navbar).height));let styles="";styles=`<style id='bilibili-new-style'>${styles=stardustStyles?getStyle("style"):getStyle("oldStyle")}</style>`,$("#bilibili-new-style").remove(),$("body").after(styles)}

View File

@ -0,0 +1,143 @@
.touch-video-box-wrapper
{
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
position: absolute;
top: 0px;
left: 0px;
z-index: 14;
pointer-events: none;
}
.touch-video-box
{
border-radius: 4px;
display: none;
align-items: center;
justify-content: center;
width: 50%;
height: 40%;
background: #000;
background: #000A;
backdrop-filter: blur(30px);
}
.touch-video-info
{
color: white;
font-size: 2rem;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
height: 100%;
width: 100%;
}
.touch-row
{
flex-grow: 1;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
}
.touch-info
{
display: block;
flex-grow: 1;
flex-shrink: 0;
margin-right: 1em;
margin-left: 0.2em;
color: $customStyleColor;
max-width: 15em;
}
.touch-result
{
display: block;
flex-grow: 1;
flex-shrink: 0;
font-size: 1.5rem;
}
.touch-speed
{
display: block;
flex-grow: 2;
flex-shrink: 0;
background: #444A;
padding: 0.5em;
margin-left: 1em;
border-radius: 4px;
margin-right: 0.2em;
max-width: 5em;
}
.videoshot
{
display:none;
background-image: none;
flex-grow: 0;
flex-shrink: 0;
border-radius: 4px;
width: 80px;
height: 45px;
background-size: 1000%;
margin-left: 1em;
}
div.bilibili-player-video-control
{
height: 38px !important;
align-items: center !important;
}
.bilibili-player-video-btn
{
flex-grow: 1 !important;
height: 38px !important;
display: flex !important;
align-items: center !important;
justify-content: center !important;
}
.bilibili-player-video-inputbar,
.bilibili-player-video-progress
{
flex-grow: 30 !important;
}
.bilibili-player-video-quality-menu
{
display: flex !important;
align-items: center !important;
justify-content: center !important;
}
.bilibili-player-iconfont-start,
.bilibili-player-iconfont-pause,
.bilibili-player-iconfont-volume,
.bilibili-player-iconfont-volume-max,
.bilibili-player-iconfont-volume-min,
.bilibili-player-iconfont-setting,
.bilibili-player-iconfont-danmaku,
.bilibili-player-iconfont-danmaku-off,
.bilibili-player-iconfont-repeat,
.bilibili-player-iconfont-widescreen,
.bilibili-player-iconfont-web-fullscreen,
.bilibili-player-iconfont-fullscreen,
.bilibili-player-iconfont-color
{
font-size: 2.5rem !important;
}
.bilibili-player-iconfont-next
{
font-size: 2rem !important;
}
.bpui-selectmenu-list,
.bilibili-player-video-danmaku-setting-wrap,
.bilibili-player-video-btn-setting-panel,
.bilibili-player.mode-fullscreen .bilibili-player-video-sendbar
{
left: unset !important;
bottom: 38px !important;
}
.bilibili-player-video-volumebar-wrp
{
left: unset !important;
}

View File

@ -0,0 +1,18 @@
function touchNavBar()
{
waitForQuery()(
() => $("ul.fr>li.nav-item").not(".profile-info"),
it => it.length === 6,
navItems =>
{
const navTouch = (_, nav) =>
{
const $nav = $(nav);
$nav.css("cursor", "pointer");
const a = $nav.find("a.t");
a.removeAttr("href");
};
navItems.each(navTouch);
}
);
}

1
touch/touch-navbar.min.js vendored Normal file
View File

@ -0,0 +1 @@
function touchNavBar(){waitForQuery()(()=>$("ul.fr>li.nav-item").not(".profile-info"),it=>6===it.length,navItems=>{const navTouch=(_,nav)=>{const $nav=$(nav);$nav.css("cursor","pointer");const a=$nav.find("a.t");a.removeAttr("href")};navItems.each(navTouch)})}

View File

@ -244,3 +244,243 @@ class SwipeAction
}
}
}
const touchVideoPlayer = () =>
{
waitForQuery()(
() => $(".bilibili-player-video-web-fullscreen"),
it => it.length > 0,
fullscreenButton =>
{
if (!fullscreenButton.hasClass("bilibili-player-video-btn") &&
$(".bilibili-player-video-btn-fullscreen").data("events"))
{
const clickHandler = getEventHandler(
$(".bilibili-player-video-btn-fullscreen"), "click");
fullscreenButton
.detach()
.insertAfter(".bilibili-player-video-btn-widescreen")
.addClass("bilibili-player-video-btn")
.on("click", clickHandler);
}
}
);
waitForQuery()(
() => $(".bilibili-player-iconfont,.bilibili-player-video-quality-menu"),
it => it.length > 0,
icons => icons.unbind("click")
);
waitForQuery()(
() => $(".bilibili-player-video"),
it => it.length > 0 && $("video").length > 0,
player =>
{
if ($(".touch-video-box").length === 0)
{
$(".bilibili-player-video-subtitle").before(`<div class='touch-video-box-wrapper'>
<div class='touch-video-box'>
<div class='touch-video-info'></div>
</div>
</div>`);
const swiper = new Swiper(player.get(0));
const text = document.getElementsByClassName("touch-video-info")[0];
const box = document.getElementsByClassName("touch-video-box")[0];
swiper.action.speedCancel = () =>
{
text.innerHTML = `松开手指,取消进退`;
};
swiper.action.volumeCancel = () =>
{
text.innerHTML = `松开手指,取消调整`;
};
swiper.action.onActionStart = () =>
{
box.style.display = "flex";
text.innerHTML = "";
};
const fixed = (number, precision = 1) =>
{
const str = number.toString();
const index = str.indexOf(".");
if (index !== -1)
{
if (str.length - index > precision + 1)
{
return str.substring(0, index + precision + 1);
}
else
{
return str;
}
}
else
{
return str + ".0";
}
};
const secondsToTime = sec =>
{
sec = Math.abs(sec);
const hours = Math.floor(sec / 3600);
const minutes = Math.floor((sec - hours * 3600) / 60);
const seconds = sec - hours * 3600 - minutes * 60;
let result = fixed(seconds) + "秒";
if (minutes > 0)
{
result = minutes + "分" + result;
}
if (hours > 0)
{
result = hours + "小时" + result;
}
return result;
};
const secondsToHms = sec =>
{
sec = Math.abs(sec);
const hours = Math.floor(sec / 3600);
const minutes = Math.floor((sec - hours * 3600) / 60);
const seconds = sec - hours * 3600 - minutes * 60;
let result = (seconds < 10 ? "0" : "") + fixed(seconds);
result = (minutes < 10 ? "0" : "") + minutes + ":" + result;
result = (hours < 10 ? "0" : "") + hours + ":" + result;
return result;
};
const video = $("video");
const videoDuration = video.prop("duration");
//const videoshot = new VideoShot(videoDuration);
const speedChange = speed =>
{
return sec =>
{
const current = video.prop("currentTime");
let info = `<div class='touch-row'><span class='touch-speed'>${speed}速</span><span class='touch-info'>进度: ${sec > 0 ? "+" : "-"}`;
const commonInfoPart = `</span></div><div class='touch-row'><div class='videoshot'></div><span class='touch-result'>`;
const finalTime = current + sec;
if (finalTime > videoDuration)
{
info += `${secondsToTime(videoDuration - current)}${commonInfoPart}${secondsToHms(current)}${secondsToHms(videoDuration)} (100%)`;
}
else if (finalTime < 0)
{
info += `${secondsToTime(current)}${commonInfoPart}${secondsToHms(current)}${secondsToHms(0)} (0%)`;
}
else
{
info += `${secondsToTime(sec)}${commonInfoPart}${secondsToHms(current)}${secondsToHms(finalTime)} (${fixed(100 * finalTime / videoDuration)}%)`;
}
text.innerHTML = info + `</span></div>`;
//$(".videoshot").css(videoshot.getStyle(finalTime));
};
};
swiper.action.lowSpeedBackward = speedChange("低");
swiper.action.lowSpeedForward = speedChange("低");
swiper.action.mediumSpeedBackward = speedChange("中");
swiper.action.mediumSpeedForward = speedChange("中");
swiper.action.highSpeedBackward = speedChange("高");
swiper.action.highSpeedForward = speedChange("高");
const volumeChange = speed =>
{
return volume =>
{
const current = Math.round(video.prop("volume") * 100);
let info = `<div class='touch-row'><span class='touch-speed'>${speed}速</span><span class='touch-info'>音量: ${volume > 0 ? "+" : "-"}`;
const commonInfoPart = `</span></div><div class='touch-row'><span class='touch-result'>`;
const finalVolume = current + volume;
if (finalVolume > 100)
{
info += `${100 - current}${commonInfoPart}${current} → 100`;
}
else if (finalVolume < 0)
{
info += `${current}${commonInfoPart}${current} → 0`;
}
else
{
info += `${Math.abs(volume)}${commonInfoPart}${current}${finalVolume}`;
}
text.innerHTML = info + `</span></div>`;
};
};
swiper.action.lowVolumeUp = volumeChange("低");
swiper.action.lowVolumeDown = volumeChange("低");
swiper.action.mediumVolumeUp = volumeChange("中");
swiper.action.mediumVolumeDown = volumeChange("中");
swiper.action.highVolumeUp = volumeChange("高");
swiper.action.highVolumeDown = volumeChange("高");
swiper.action.onActionEnd = action =>
{
box.style.display = "none";
text.innerHTML = "";
if (action)
{
if (action.type === "volume")
{
let volume = video.prop("volume");
volume += action.volume / 100;
if (volume < 0)
{
volume = 0;
}
else if (volume > 1)
{
volume = 1;
}
video.prop("volume", volume);
$(".bilibili-player-video-volume-num").text(Math.round(volume * 100));
$(".bpui-slider-progress").css("height", volume * 100 + "%");
$(".bpui-slider-handle").css("bottom", (35 + volume * 230) / 3 + "%");
if (volume === 0)
{
$(".icon-24soundoff").show();
$(".icon-24soundlarge").hide();
$(".icon-24soundsmall").hide();
}
else if (volume >= 0.5)
{
$(".icon-24soundoff").hide();
$(".icon-24soundlarge").show();
$(".icon-24soundsmall").hide();
}
else
{
$(".icon-24soundoff").hide();
$(".icon-24soundlarge").hide();
$(".icon-24soundsmall").show();
}
}
else if (action.type === "playback")
{
let time = video.prop("currentTime");
time += action.seconds;
if (time < 0)
{
time = 0;
}
else if (time > videoDuration)
{
time = videoDuration;
}
video.prop("currentTime", time);
}
}
};
}
}
);
if ($("#bilibili-touch-video-player").length === 0)
{
const style = getStyle("touchPlayerStyle");
const videoPlayerStyles = `<style id='bilibili-touch-video-player'>${style}</style>`;
$("body").after(videoPlayerStyles);
}
};

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
const waitForQuery = settings =>
function waitForQuery()
{
const MaxRetry = settings.maxQueryRetry;
let retry = 0;
@ -26,4 +26,44 @@ const waitForQuery = settings =>
}
};
return tryQuery;
};
}
function getStyle(name)
{
const style = GM_getResourceText(name);
function replaceCustomColor(style)
{
const foreground = (() =>
{
const regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(settings.customStyleColor);
const color = regex ? {
r: parseInt(regex[1], 16),
g: parseInt(regex[2], 16),
b: parseInt(regex[3], 16)
} : undefined;
if (color)
{
const grey = 1 - (0.299 * color.r + 0.587 * color.g + 0.114 * color.b) / 255;
if (grey < 0.35)
{
return "#000";
}
else
{
return "#fff";
}
}
else
{
return "#fff";
}
})();
settings.brightness = `${foreground === "#000" ? "100" : "0"}%`;
settings.filterBrightness = foreground === "#000" ? "0" : "100";
for (name of settings)
{
style = style.replace(`$${name}`, settings[name]);
}
return style;
}
return replaceCustomColor(style, foreground);
}

2
utils/common.min.js vendored
View File

@ -1 +1 @@
const waitForQuery=settings=>{const MaxRetry=settings.maxQueryRetry;let retry=0;const tryQuery=(query,condition,action,failed)=>{if(retry>=MaxRetry){if(failed){failed()}}else{const result=query();if(condition(result)){action(result)}else{retry++;setTimeout(()=>tryQuery(query,condition,action,failed),settings.queryInterval)}}};return tryQuery};
function waitForQuery(){const MaxRetry=settings.maxQueryRetry;let retry=0;const tryQuery=(query,condition,action,failed)=>{if(retry>=MaxRetry)failed&&failed();else{const result=query();condition(result)?action(result):(retry++,setTimeout(()=>tryQuery(query,condition,action,failed),settings.queryInterval))}};return tryQuery}function getStyle(name){const style=GM_getResourceText(name);function replaceCustomColor(style){const foreground=(()=>{const regex=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(settings.customStyleColor),color=regex?{r:parseInt(regex[1],16),g:parseInt(regex[2],16),b:parseInt(regex[3],16)}:void 0;if(color){const grey=1-(.299*color.r+.587*color.g+.114*color.b)/255;return grey<.35?"#000":"#fff"}return"#fff"})();for(name of(settings.brightness=`${"#000"===foreground?"100":"0"}%`,settings.filterBrightness="#000"===foreground?"0":"100",settings))style=style.replace(`$${name}`,settings[name]);return style}return replaceCustomColor(style,foreground)}

View File

@ -0,0 +1,15 @@
function expandDanmakuList()
{
waitForQuery()(
() => $(".bui-collapse-header"),
it => it.length > 0,
button =>
{
if (parseInt($(".bui-collapse-body").css("height")) === 0 &&
$(".bui-collapse-arrow-text").text() === "展开")
{
button.click();
}
}
);
}

1
utils/expand-danmaku.min.js vendored Normal file
View File

@ -0,0 +1 @@
function expandDanmakuList(){waitForQuery()(()=>$(".bui-collapse-header"),it=>it.length>0,button=>{0===parseInt($(".bui-collapse-body").css("height"))&&"展开"===$(".bui-collapse-arrow-text").text()&&button.click()})}

View File

@ -0,0 +1,18 @@
function removeAds()
{
waitForQuery()(
() => $("#slide_ad"),
it => it.length > 0,
it => it.css("display", "none")
);
waitForQuery()(
() => $("#home_popularize"),
it => it.length > 0,
it => it.css("display", "none")
);
waitForQuery()(
() => $(".gg-floor-module"),
it => it.length > 0,
it => it.css("display", "none")
);
};

1
utils/remove-ads.min.js vendored Normal file
View File

@ -0,0 +1 @@
function removeAds(){waitForQuery()(()=>$("#slide_ad"),it=>it.length>0,it=>it.css("display","none")),waitForQuery()(()=>$("#home_popularize"),it=>it.length>0,it=>it.css("display","none")),waitForQuery()(()=>$(".gg-floor-module"),it=>it.length>0,it=>it.css("display","none"))}

View File

@ -0,0 +1,45 @@
function watchlaterRedirect()
{
const redirectLinks = items =>
{
if (items.attr("href").indexOf("watchlater") !== 0)
{
const watchlaterList = items
.map((_, it) => "https://www.bilibili.com/" + $(it)
.attr("href")
.match(/av[\d]+/)[0]);
items.each((index, it) => $(it).attr("href", watchlaterList[index]).attr("target", "_blank"));
}
};
waitForQuery()(
() => $(".av-item>a"),
it => it.length > 0,
items => redirectLinks(items)
);
waitForQuery()(
() => $("div.watch-later-m>ul>div>li>a"),
it => it.length > 0,
items => redirectLinks(items)
);
waitForQuery()(
() => $(".read-more.mr"),
it => it.length > 0,
it => it.remove()
);
waitForQuery()(
() => $(".read-more-grp>.read-more"),
it => it.length > 0,
it => it.css({
float: "none",
width: "auto"
})
);
if (document.URL.indexOf("watchlater") !== -1 && document.URL.match(/av[\d]+/))
{
const av = document.URL.match(/av[\d]+/)[0];
if (av)
{
document.URL.replace(`https://www.bilibili.com/${av}`);
}
}
}

1
utils/watchlater.min.js vendored Normal file
View File

@ -0,0 +1 @@
function watchlaterRedirect(){const redirectLinks=items=>{if(0!==items.attr("href").indexOf("watchlater")){const watchlaterList=items.map((_,it)=>"https://www.bilibili.com/"+$(it).attr("href").match(/av[\d]+/)[0]);items.each((index,it)=>$(it).attr("href",watchlaterList[index]).attr("target","_blank"))}};if(waitForQuery()(()=>$(".av-item>a"),it=>it.length>0,items=>redirectLinks(items)),waitForQuery()(()=>$("div.watch-later-m>ul>div>li>a"),it=>it.length>0,items=>redirectLinks(items)),waitForQuery()(()=>$(".read-more.mr"),it=>it.length>0,it=>it.remove()),waitForQuery()(()=>$(".read-more-grp>.read-more"),it=>it.length>0,it=>it.css({float:"none",width:"auto"})),-1!==document.URL.indexOf("watchlater")&&document.URL.match(/av[\d]+/)){const av=document.URL.match(/av[\d]+/)[0];av&&document.URL.replace(`https://www.bilibili.com/${av}`)}}