-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
98 lines (79 loc) · 2.46 KB
/
content.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
var settings = {
hidewatched: false,
hidestreams: false,
}
// Read a page's GET URL variables and return them as an associative array.
function getUrlVars(link)
{
var vars = [], hash;
var hashes = link.slice(link.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
function getItems(ele, gm){
if(gm){
return ele.closest('.yt-shelf-grid-item');
}else{
return ele.closest('.item-section');
}
}
function eval_once(eval_list){
var grid_mode = $('.yt-shelf-grid-item').length;
var eval_all = eval_list === undefined;
var eval_name = eval_list && eval_list[0];
if(eval_all || eval_name == "hidewatched"){
var watched = $('.yt-lockup-thumbnail.contains-percent-duration-watched');
var select = getItems(watched, grid_mode);
if(settings.hidewatched)
select.hide();
else
select.show();
}
if(eval_all || eval_name == "hidestreams"){
var unwatched = $('.yt-lockup-thumbnail:not(.contains-percent-duration-watched)');
var select = getItems(unwatched, grid_mode).filter( function (index) {
var test = $(this).find('.yt-lockup-meta-info li:nth-child(2)').html();
return test !== undefined && test.length && test[0] == 'S';
});
if(settings.hidestreams)
select.hide();
else
select.show();
}
}
function get_unwatched(){
var unwatched = $('.yt-lockup-thumbnail:not(.contains-percent-duration-watched)');
var grid_mode = $('.yt-shelf-grid-item').length;
var select = getItems(unwatched, grid_mode).filter( function (index) {
var test = $(this).find('.yt-lockup-meta-info li:nth-child(2)').html();
return test === undefined || !test.length || test[0] != 'S';
});
var links = [];
$.each(select.find('.yt-uix-sessionlink.yt-ui-ellipsis'), function(){
links.push(getUrlVars(this.href)['v']);
});
return links;
}
$( document ).ready(function() {
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if(request.settings !== undefined){
var key = request.settings[0];
var data = request.settings[1];
settings[key] = data;
eval_once([key]);
}else if(request.collect !== undefined){
var links = get_unwatched();
sendResponse({links: links});
}
});
chrome.storage.sync.get("settings", function(items){
settings = items.settings;
eval_once();
});
});