-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
82 lines (73 loc) · 2.34 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
console.log('fpl extention running!');
let delay = 500;
setTimeout(function(){
getData('selectedPercent', 'selected_by_percent', '', '% Owned');
}, delay);
function getData(className, jsonKey, beforeText, afterText){
resp = "";
$.get('https://fantasy.premierleague.com/drf/transfers', function(data){
resp = data;
}).then(function(){
$.get('https://fantasy.premierleague.com/drf/bootstrap-static', function(allPlayers){
}).then(function(allPlayers){
$('.ism-element__data').each(function(index, tag){
player = resp.picks[index].element;
plrs = allPlayers.elements
$.each(plrs, function(index, plr){
if (plr.id == player){
$(tag).after('<div class="ism-element__data ' + className + '" style="background-color: rgba(0, 111, 55, 0.9); color: #ffffff">' + beforeText + '' + plr[jsonKey] + '' + afterText + '</div>');
}
})
})
})
})
}
chrome.runtime.onMessage.addListener(onMessage);
function onMessage(message, sender, sendResponse){
if (message.selectedPercent){
getData('selectedPercent', 'selected_by_percent', '', '% Owned');
}
else{
$('.selectedPercent').remove();
}
if (message.goalsScored){
getData('goalsScored', 'goals_scored', '', ' Goals');
}
else{
$('.goalsScored').remove();
}
if (message.cleanSheets){
getData('cleanSheets', 'clean_sheets', '', ' clean sheets');
}
else{
$('.cleanSheets').remove();
}
if (message.yellowCards){
getData('yellowCards', 'yellow_cards', '', ' bookings');
}
else{
$('.yellowCards').remove();
}
if (message.redCards){
getData('redCards', 'red_cards', '', ' red cards');
}
else{
$('.redCards').remove();
}
if (message.totalPoints){
getData('totalPoints', 'total_points', 'Total Pts: ', '');
}
else{
$('.totalPoints').remove();
}
if (message.assists){
getData('assists', 'assists', '', ' assists');
}
else{
$('.assists').remove();
}
// ---------------------------------------------------
if (message.clear){
$('.selectedPercent .goalsScored .cleanSheets .yellowCards .redCards .totalPoints').remove();
}
}