-
Notifications
You must be signed in to change notification settings - Fork 0
/
ani-gamer__show-cover.js
84 lines (77 loc) · 2.71 KB
/
ani-gamer__show-cover.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// ==UserScript==
// @name 顯示動畫瘋封面 & 視覺圖
// @namespace https://github.com/zica87/self-made-userscipts
// @version 1.2.2
// @description 在動畫瘋網站顯示該集封面 & 視覺圖
// @author zica
// @match https://ani.gamer.com.tw/animeVideo.php?sn=*
// @grant GM_registerMenuCommand
// @license GPL-2.0
// ==/UserScript==
(function () {
"use strict";
GM_registerMenuCommand("顯示大視覺圖", display_visual);
// 把下面一行的兩個斜線刪掉並存檔,即可自動顯示大視覺圖
// display_visual();
// 顯示視覺圖
function display_visual() {
const visual = document.createElement("img");
visual.src = get_visual_url();
Object.assign(visual.style, {
maxHeight: "40rem",
float: "right",
margin: "10px 10px auto 10px",
});
document.getElementsByClassName("anime-title")[0].prepend(visual);
document.getElementsByClassName("anime-ad")[0].style.position =
"static";
}
// 顯示封面
const cover = document.createElement("img");
Object.assign(cover.style, {
width: "100%",
maxWidth: "initial",
height: "100%",
objectFit: "contain",
});
let old_URL = undefined;
const observer = new MutationObserver((records, observerInstance) => {
const paid_or_age_restriction =
document.getElementsByClassName("video-verify").length !== 0;
const agreeScreen = paid_or_age_restriction
? document.getElementsByClassName("video-verify")[0]
: document.getElementsByClassName("video-cover-ncc")[0];
if (!agreeScreen || window.location.href === old_URL) {
return;
}
old_URL = window.location.href;
cover.src = get_cover_url();
cover.onclick = () => {
cover.remove();
if (paid_or_age_restriction) {
agreeScreen.style.display = "flex";
} else {
const agreeButton = document.getElementById("adult");
agreeButton.click();
}
};
agreeScreen.before(cover);
agreeScreen.style.display = "none";
});
observer.observe(document.getElementById("video-container"), {
childList: true,
subtree: true,
});
function get_cover_url() {
const accurate = document
.getElementById("ani_video_html5_api")
.getAttribute("poster");
if (accurate.length !== 0) {
return accurate;
}
return get_visual_url();
}
function get_visual_url() {
return document.getElementsByName("thumbnail")[0].content;
}
})();