-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
83 lines (71 loc) · 2.44 KB
/
Copy pathscript.js
File metadata and controls
83 lines (71 loc) · 2.44 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
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
function setElements(src, views, subs, date){
document.getElementById('iframe').src = src;
document.getElementById('views').textContent = views;
document.getElementById('subs').textContent = subs;
document.getElementById('date').textContent = date;
}
function getSubs(id){
var json = getJson("https://invidious.snopyta.org/api/v1/channels/" + id + "?fields=subCount&pretty=1");
if(json["subCount"] === 0)
return "0 / hidden";
return json["subCount"];
}
function setLoadingText(text){
try{
document.getElementById("loading").textContent = text;
}catch{
return;
}
}
function getParentObject(videos, id){
var obj;
videos.forEach(element => {
if(element.videoId === id){
obj = element;
}
});
return obj;
}
function getJson(url){
var httpreq = new XMLHttpRequest();
httpreq.open("GET", url, false);
httpreq.send(null);
return JSON.parse(httpreq.responseText);
}
function random(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}
function getLetter(){
var letters = "abcdefhijklmnoprstuvxyz" //gqw
return letters[random(0, letters.length - 1)]
}
function getCringeVideo(object){
var val = Object.values(object);
var length = val.length;
val.sort();
var sortedDict = {};
for (i = 0; i < length; i++)
{
sortedDict[Object.keys(object).find(key => object[key] === val[i])] = val[i]
}
return Object.keys(object).find(key => object[key] === val[0]);
}
function getVideos(){
var json = getJson("https://invidious.snopyta.org/api/v1/search/?fields=videoId,viewCount,published,authorId&q=" + getLetter() + getLetter() + "&page=20&sort_by=view_count&date=today&duration=short&type=video&pretty=1");
//pokud je json prázdný
var i = 1;
setLoadingText("Generating random video (" + i + ". try)")
while(Object.keys(json).length === 0){
json = getJson("https://invidious.snopyta.org/api/v1/search/?fields=videoId,viewCount,published,authorId&q=" + getLetter() + getLetter() + "&page=10&sort_by=view_count&date=today&duration=short&type=video&pretty=1");
setLoadingText("Generating random video (" + i + ". try)")
i++;
}
return json;
}
function setKentusValue(json){
var dict = {};
json.forEach(element => {
dict[element["videoId"]] = element["published"] * (element["viewCount"] + 1)
});
return dict;
}