This repository was archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.js
50 lines (45 loc) · 2.06 KB
/
main.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
const axios = require('axios');
const cheerio = require('cheerio');
// Update the Match URL Don't remove this line - https://cors-anywhere.herokuapp.com/
const liveurl = 'https://cors-anywhere.herokuapp.com/https://www.espncricinfo.com/series/8048/game/1237180/delhi-capitals-vs-sunrisers-hyderabad-qualifier-2-indian-premier-league-2020-21';
function Getscore() {
// eslint-disable-next-line no-undef
const appNotice = $('.notice');
appNotice.html('<p class="has-text-centered">Fetching the Live Score 📦</p>');
axios({
method: 'get',
url: liveurl,
})
.then(
setTimeout(() => {
appNotice.empty();
}, 800),
)
.then(function(response) {
if (response.status == '200') {
const html = response.data;
const $ = cheerio.load(html);
let score = $('meta[property="og:title"]').attr('content');
console.log(score);
document.getElementById('response').innerHTML = '<div class="notification score is-link has-text-weight-bold">' + score + '</div>';
} else {
console.log(response.status);
}
})
.catch(function(error) {
if (!error.response) {
console.log('Enter a Valid URL');
} else if (error.response.status == 429) {
console.log(error.response.data);
document.getElementById('response').innerHTML = '<div class="notification is-danger">'+ error.response.data +'</div>';
} else if (error.response.status == 403) {
console.log(error.response.data);
document.getElementById('response').innerHTML = '<div class="notification is-danger">'+ error.response.data +'</div>';
} else {
console.log('Hmm Something Went Wrong or HTTP Status Code is Missing');
}
});
}
Getscore();
// https://stackoverflow.com/questions/44282721/update-changing-json-data-on-web-site-without-refreshing
setInterval(Getscore, 60 * 1000);