-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
58 lines (47 loc) · 1.61 KB
/
Copy pathcontent.js
File metadata and controls
58 lines (47 loc) · 1.61 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
56
57
58
function injectSearchBox() {
if (document.getElementById("watch-later-search-box")) return;
const container = document.querySelector("#primary");
if (!container) return;
const input = document.createElement("input");
input.type = "text";
input.placeholder = "Filter Watch Later…";
input.id = "watch-later-search-box";
Object.assign(input.style, {
padding: "8px",
width: "100%",
marginBottom: "10px",
fontSize: "16px",
borderRadius: "4px",
border: "1px solid #ccc",
backgroundColor: "#121212",
color: "#fff"
});
container.prepend(input);
input.addEventListener("input", () => {
filterVideos(input.value);
});
}
function filterVideos(keyword) {
keyword = keyword.toLowerCase();
const videoCards = document.querySelectorAll("ytd-playlist-video-renderer");
videoCards.forEach(card => {
const titleNode = card.querySelector("#video-title");
const fullTitle = titleNode?.textContent?.trim().toLowerCase() || "";
const shouldShow = fullTitle.includes(keyword);
card.style.display = shouldShow ? "" : "none";
});
}
// Retry logic until DOM stabilizes
function waitForVideosAndInjectBox() {
const tryInject = () => {
const listReady = document.querySelectorAll("ytd-playlist-video-renderer").length > 5;
const containerReady = document.querySelector("#primary");
if (listReady && containerReady) {
injectSearchBox();
clearInterval(retryInterval);
}
};
const retryInterval = setInterval(tryInject, 500);
}
// Inject on YouTube page load
waitForVideosAndInjectBox();