-
Notifications
You must be signed in to change notification settings - Fork 0
/
kinobot-show-timestamps.js
99 lines (86 loc) · 4.31 KB
/
kinobot-show-timestamps.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// ==UserScript==
// @name Kinobot Show Timestamps Near Number
// @version 1.5.0
// @description Display timestamps before the subtitle number.
// @author seaque
// @license MIT
// @namespace https://github.com/seaque/tampermonkey-scripts
// @downloadURL https://github.com/seaque/tampermonkey-scripts/raw/main/kinobot-show-timestamps.js
// @match *://*.kino.caretas.club/movie/*
// @match *://*.kino.caretas.club/episode/*
// @icon data:image/svg+xml,<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 112.16 122.88"><defs><style>.cls-1{fill: whitesmoke;}</style></defs><title>film-camera</title><path class="cls-1" d="M14.76,47.89H71.34a9.56,9.56,0,0,1,9.54,9.53V93a9.58,9.58,0,0,1-9.54,9.54H53.86l12.7,20.37H54.73L40.89,104.27l-14,18.61h-12l12.62-20.37H14.76A9.57,9.57,0,0,1,5.22,93V57.42a9.56,9.56,0,0,1,9.54-9.53Zm.24-38a15,15,0,1,1-15,15,15,15,0,0,1,15-15ZM5.27,24.93A3.05,3.05,0,1,1,8.32,28a3,3,0,0,1-3.05-3.05Zm9.81,9.66a3.06,3.06,0,1,1,3-3.06,3.05,3.05,0,0,1-3,3.06Zm9.66-9.82a3.06,3.06,0,1,1-3-3.05,3.06,3.06,0,0,1,3,3.05Zm-9.82-9.66a3.06,3.06,0,1,1-3.05,3.06,3.06,3.06,0,0,1,3.05-3.06ZM61.06,0A19.89,19.89,0,1,1,41.17,19.89,19.88,19.88,0,0,1,61.06,0Zm-.12,5.8a4.44,4.44,0,1,1-4.44,4.44A4.44,4.44,0,0,1,60.94,5.8ZM46.88,20.08a4.45,4.45,0,1,1,4.44,4.44,4.44,4.44,0,0,1-4.44-4.44ZM61.17,34.14a4.44,4.44,0,1,1,4.44-4.44,4.44,4.44,0,0,1-4.44,4.44Zm14-14.28a4.44,4.44,0,1,1-4.44-4.45,4.44,4.44,0,0,1,4.44,4.45ZM86.3,91V60.38l25.86-15.24v61.51L86.3,91Z"/></svg>
// @grant GM_addStyle
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
const addFunction = () => {
var scriptElement = document.createElement('script');
scriptElement.innerHTML =
`const copyTimeToClipboard = (element, index) => {
let name = document.getElementsByTagName('h1')[0].textContent;
let time = document.querySelectorAll(element)[index].innerText;
navigator.clipboard.writeText('!req ' + name + '[' + time + ']');
};`
document.body.appendChild(scriptElement);
};
const getSubElements = () => {
const sub_elements = document.querySelectorAll(`li[id^="sub"]`);
const timestamps = [];
let timestamp_value;
let timestamp_trimmed;
// This breaks if the movie is longer than 9 hours. Find some other hobby.
sub_elements.forEach(element => {
timestamp_value = element.getAttribute("title");
timestamp_trimmed = timestamp_value.substr(0, 7).replace(/^0+:?0?/, '');
timestamps.push(timestamp_trimmed);
});
return timestamps;
};
const timestampDiv = () => {
var div = document.createElement("div");
div.setAttribute("class","sub-ts");
GM_addStyle(`
.sub-ts
{
margin-right: 10px;
display: inline-block;
outline: 0;
cursor: pointer;
border-radius: 5px;
border: 2px solid #770919;
color: #FFFFFF;
background-color: #770919;
}
.sub-ts:hover
{
background: 0 0;
}
@media screen and (max-width: 600px) {
.contenedor #reqButton {
width: 2rem;
height: 2rem;
}
.contenedor input[id^='lines'] {
width: 2rem;
margin-left: 0;
}
.subtitle_list #sub_list {
margin-left: -15px;
margin-right: 0px;
}
}
`)
return div;
};
const appendTimestamps = (div, elements) => {
var contenedor = document.querySelectorAll(".contenedor > li");
for (let i = 0; i < contenedor.length; i++) {
div.innerHTML =
`<button class="sub-ts" title="Copy to Clipboard" onclick="copyTimeToClipboard('.sub-ts', '${i}')"> ${elements[i]} </button>`;
contenedor[i].insertAdjacentHTML("afterbegin", div.innerHTML);
}
};
addFunction();
appendTimestamps(timestampDiv(), getSubElements());
})();