-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetShowData.js
More file actions
99 lines (78 loc) · 4.23 KB
/
getShowData.js
File metadata and controls
99 lines (78 loc) · 4.23 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var showId, showRisk, yesVotes, noVotes, riskDescription;
function getShowInfo(){
setTimeout(() => {
chrome.storage.sync.get("showTitle", ({ showTitle }) => {
const urlShowId = 'https://www.doesthedogdie.com/dddsearch?q=' + showTitle;
const fetchHeaders = {
headers : {
"Accept" : "application/json",
"X-API-KEY" : "d670056d6eae327a1c60f652a2476a86"
},
method:"GET"
};
fetch(urlShowId, fetchHeaders)
.then(data=>{return data.json()})
.then(res=>{
showId = res.items[0].id;
console.log(showId);
})
.catch(error=>console.log(error))
.then( () => {
const urlShowData = 'https://www.doesthedogdie.com/media/' + showId;
fetch(urlShowData, fetchHeaders)
.then(data=>{return data.json()})
.then(res=>{
var metricID = 0;
var current_TopicId;
const flashinglights_TopicId = 167; // Flashing Lights ID
while (metricID < res.topicItemStats.length){
current_TopicId = res.topicItemStats[metricID].TopicId;
if (current_TopicId == flashinglights_TopicId){ // if search criteria found,
if (res.topicItemStats[metricID].voteSum == null){ // make unavailable if there are no votes
throw err
}
break; // else, stop searching
}
metricID++;
if (metricID >= res.topicItemStats.length){ // if exceed length of JSON,
metricID == undefined; // remove value from metricID
}
}
document.getElementById('showTitle').innerHTML = showTitle;
yesVotes = res.topicItemStats[metricID].yesSum;
noVotes = res.topicItemStats[metricID].noSum;
if (noVotes > yesVotes){
showRisk = 0; // low risk
} else {
showRisk = 1; // risky
}
// isYes deprecated in API
//showRisk = res.topicItemStats[metricID].isYes; // 1 indicates risky
if (showRisk == 0) {
document.getElementById('showStatus').innerHTML = 'Safe!';
document.getElementById('showStatusImg').src = '\\images\\src\\check.png';
} else if (showRisk == 1) {
document.getElementById('showStatus').innerHTML = 'Unsafe!';
document.getElementById('showStatus').style.color = '#E04F5F';
document.getElementById('showStatusImg').src = '\\images\\src\\danger.png';
}
if (yesVotes > noVotes){
document.getElementById('showSum').innerHTML = `${yesVotes} / ${yesVotes + noVotes} votes`;
} else {
document.getElementById('showSum').innerHTML = `${noVotes} / ${yesVotes + noVotes} votes`;
}
riskDescription = res.topicItemStats[metricID].comment;
document.getElementById('showComment').innerHTML = riskDescription;
})
.catch(() => {
document.getElementById('showStatus').innerHTML = 'Unavailable';
document.getElementById('showStatusImg').src = '\\images\\src\\not-found.png';
document.getElementById('showStatus').style.color = '#FDB62F';
document.getElementById('showSum').innerHTML = '';
document.getElementById('showComment').innerHTML = "We don't appear to have information on this show at the moment. \n If you have watched this, please leave a review on our site!";
})
})
});
}, 500);
}
getShowInfo();