-
Notifications
You must be signed in to change notification settings - Fork 1
/
content.js
120 lines (101 loc) · 3.58 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var fa_link = document.createElement("link");
fa_link.href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css";
fa_link.type = "text/css";
fa_link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(fa_link);
var local_link = document.createElement("link");
local_link.href = "styles.css";
local_link.type = "text/css";
local_link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(local_link);
var about = document.getElementsByClassName('oajrlxb2 g5ia77u1 qu0x051f esr5mh6w e9989ue4 r7d6kgcz rq0escxv nhd2j8a9 pq6dq46d p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso i1ao9s8h esuyzwwr f1sip0of lzcic4wl l9j0dhe7 abiwlrkh p8dawk7l dwo3fsh8 ow4ym5g4 auili1gw mf7ej076 gmql0nx0 tkr6xdv7 bzsjyuwj cb02d2ww j1lvzwm4');
var title = document.getElementsByClassName("gmql0nx0 l94mrbxd p1ri9a11 lzcic4wl bp9cbjyn j83agx80");
function waitForElement(){
if(typeof about[0] !== "undefined" && typeof title[0] !== 'undefined' && about[0].getAttribute('href')!== null){
//variable exists, do what you want
var btn = document.createElement("BUTTON");
btn.id = "crush_button";
btn.classList.add('glow-on-hover');
let user_id = null;
var crush_count = 20;
var crushFullName = title[0].innerText;
var fetchcurr = about[0].getAttribute('href');
user_id = fetchcurr.substring(1, fetchcurr.length-1 );
var strings = document.getElementsByTagName('script');
var myusername = "";
for (var i = 0, l = strings.length; i < l; i++) {
var str = strings[i].innerText;
var n = str.indexOf("\"username\"");
if(n != -1){
var en = str.indexOf("\"", n+12);
myusername = str.substring(n+12, en );
break;
}
}
btn.innerHTML = "<i class=\"fa fa-heart fa-3px\"></i>";
btn.style.backgroundColor = 'white';
btn.style.color = 'black';
var port = chrome.runtime.connect({name: "knockknock"});
port.postMessage({
type: 'statCrush',
username: myusername,
crushname: user_id
});
var statCrush = 0;
port.onMessage.addListener(function(response) {
crush_count = response.crushCt;
statCrush = response.statCrush;
if (response.statCrush == 2){
btn.style.backgroundColor = '#FF69B4';
btn.style.color = 'white';
btn.innerHTML = "<i class=\"fa fa-heart fa-5px\"></i>";
}else if(response.statCrush == 1){
btn.style.backgroundColor = '#0288d1';
btn.style.color = 'white';
btn.innerHTML = '<i class=\"fa fa-heart fa-3px\"></i>';
}
});
btn.onclick = function (){
if (btn.style.backgroundColor != 'white'){
btn.style.backgroundColor = '#fce205';
btn.style.color = 'black';
chrome.runtime.sendMessage({
type: 'deleteDB',
username: myusername,
crushname: user_id
});
}
else if(crush_count < 15){
btn.innerHTML = "<i class=\"fa fa-heart fa-3px\"></i>"
btn.style.backgroundColor = '#3cc47c';
btn.style.color = 'white';
chrome.runtime.sendMessage({
type: 'addDb',
username: myusername,
crushname: user_id,
fullname: crushFullName
});
}
chrome.runtime.sendMessage({
type: 'queryDb'
});
};
// Add button styles here
btn.style.marginLeft = '40%'
btn.style.marginRight = '40%';
btn.style.marginTop = '5px';
btn.style.borderRadius = '15px';
btn.style.width = '30px'
btn.style.height = '30px';
btn.style.borderColor = 'red';
if(user_id != myusername){
let divElement = document.getElementsByClassName('bi6gxh9e aov4n071')[0];
divElement.appendChild(btn);
}
}
else{
setTimeout(waitForElement, 100);
}
return true;
}
waitForElement();