Repository navigation
Expand file tree
/
Copy pathcreate.js
More file actions
55 lines (52 loc) · 1.94 KB
/
Copy pathcreate.js
File metadata and controls
55 lines (52 loc) · 1.94 KB
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
(async () => {
const evaluateElement = async (target, videos) => {
for (let item of videos) {
if (item.src === target.dataset.videoid){
try {
if (item !== document.pictureInPictureElement) {
target.classList.add('jpsks__reel-in');
await item.requestPictureInPicture();
} else {
target.classList.remove('jpsks__reel-in');
await document.exitPictureInPicture();
}
} catch (error) {}
} else {
item.parentElement.getElementsByClassName('jpsks__kite-screen')[0]
.classList.remove('jpsks__reel-in');
}
}
}
// Set background images for icons (only once)
if (!document.getElementById('jpsks-icon-styles')) {
const iconUrl = chrome.runtime.getURL("images/icon48.png");
const exitIconUrl = chrome.runtime.getURL("images/exit48.png");
const style = document.createElement("style");
style.id = 'jpsks-icon-styles';
style.textContent = `
.jpsks__b64-icon:before {
background-image: url("${iconUrl}");
}
.jpsks__b64-icon.jpsks__reel-in:before {
background-image: url("${exitIconUrl}");
}
`;
document.head.appendChild(style);
}
// https://stackoverflow.com/questions/14377590/queryselector-and-queryselectorall-vs-getelementsbyclassname-and-getelementbyid
const videos = document.getElementsByTagName("video");
for (let item of videos) {
// Ensure parent is positioned for absolute overlay
const parent = item.parentElement;
const parentStyle = window.getComputedStyle(parent);
if (parentStyle.position === "static") {
parent.style.position = "relative";
parent.dataset.jpsksPerm = "static";
}
const div = document.createElement("div");
div.className = 'jpsks__kite-screen jpsks__b64-icon';
div.setAttribute('data-videoid', item.src);
div.onclick = (e) => evaluateElement(e.target, videos);
parent.appendChild(div);
}
})();