-
Notifications
You must be signed in to change notification settings - Fork 0
/
myscript.js
49 lines (38 loc) · 1.17 KB
/
myscript.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
console.log('Start Youtube Filter EXT');
//Helper functions
function getDataFromGridItem(item) {
const user = item.querySelector('.yt-lockup-byline a').innerText;
const title = item.querySelector('.yt-lockup-title a').innerText;
const data = {
user: user,
title: title,
dom: item
};
return data;
}
chrome.storage.sync.get({
keep: []
}, storedData => {
//Get all item into data array
const DOMItems = document.querySelectorAll('.yt-shelf-grid-item');
const data = [...DOMItems].map(item => {
return getDataFromGridItem(item);
});
storedData.keep.forEach(sortedItem => {
//Filter out NBA items
const onlyTitle = data.filter(item => {
if (item.user === sortedItem.channel) {
return true;
}
return false;
});
//Keep only title with TOP
const notTOP = onlyTitle.filter(item => {
const upperTitle = item.title.toUpperCase();
return !upperTitle.includes(sortedItem.tag.toUpperCase());
});
for(const item of notTOP) {
item.dom.style.display = 'none';
}
});
});