-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
128 lines (104 loc) · 4.08 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
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
121
122
123
124
125
126
127
128
// prepend to body element
// const script = document.createElement('script');
// ----------------------------------------------------------------------------------------
// ------------------- this works --------------------------------------------------------
// ----------------------------------------------------------------------------------------
// let myStyle = document.createElement('style')
// let head = document.getElementsByTagName('head')[0];
// myStyle.innerHTML = "button:hover {background-color: red !important;}";
// head.prepend(myStyle);
// console.log(head);
// // Create new link Element
//
// let link = document.createElement('link');
// // set the attributes for link element
// link.rel = 'stylesheet';
// link.type = 'text/css';
// link.href = 'styles.css';
// // Append link element to HTML head
// // script.append(link)
// head.append(style);
const body = document.querySelector('body div');
//div w/ message and question want to play that sends to snake game
const newDiv = document.createElement('div');
newDiv.style.width = '100%';
newDiv.style.height = '820px';
newDiv.style.border = '6px double darkblue';
newDiv.style.borderRadius = '25px'
newDiv.style.position = 'fixed';
newDiv.style.backgroundColor = 'black';
newDiv.style.zIndex = '9999';
newDiv.style.marginTop = '100px';
newDiv.innerText = "Why learn to code, when I already did the coding for you!? Click to play!";
newDiv.style.textAlign = 'center';
newDiv.style.paddingTop = '40px';
newDiv.style.fontSize = '35px';
newDiv.style.fontFamily = 'Garamond';
const btnContainer = document.createElement('div');
btnContainer.setAttribute('id', 'btnContainer');
btnContainer.style.display = 'flex';
btnContainer.style.zIndex = '8';
btnContainer.style.justifyContent = 'center';
btnContainer.style.gap = '50px';
btnContainer.style.backgroundColor = 'black';
btnContainer.style.marginTop = '20px';
btnContainer.style.fontSize = '20px';
btnContainer.style.fontWeight = 'bold';
const playBtn = document.createElement('button');
playBtn.classList.add('btn');
playBtn.setAttribute('id', 'playBtn');
playBtn.innerText = "Yes, I'll play";
playBtn.style.padding = '5px 0px';
playBtn.style.width = "180px";
playBtn.style.borderRadius = '50px';
playBtn.style.background = 'yellow';
playBtn.style.color = 'darkblue';
const noPlayBtn = document.createElement('button');
noPlayBtn.setAttribute('id', 'noPlayBtn');
noPlayBtn.classList.add('btn');
noPlayBtn.innerText = "Nah, I'm good.";
noPlayBtn.style.padding = '5px 0px';
noPlayBtn.style.width = "180px";
noPlayBtn.style.borderRadius = "50px";
noPlayBtn.style.backgroundColor = 'yellow';
noPlayBtn.style.color = 'darkblue';
const pacman = document.createElement('img');
const imgURL = chrome.runtime.getURL("pac-man.gif")
pacman.src = imgURL;
btnContainer.append(noPlayBtn);
btnContainer.append(playBtn);
newDiv.append(btnContainer);
newDiv.append(pacman);
body.prepend(newDiv);
noPlayBtn.addEventListener('click', function() {
newDiv.style.display = 'none'
});
playBtn.addEventListener('click', function() {
location.href = 'https://dancing-tapioca-e617ee.netlify.app/'
});
noPlayBtn.addEventListener('mouseover', function() {
if (noPlayBtn.style.transform === 'translateX(-200px)')
noPlayBtn.style.transform = 'translateX(0px)';
else noPlayBtn.style.transform = 'translateX(-200px)';
});
playBtn.addEventListener('mouseover', function() {
playBtn.style.backgroundColor = 'darkblue';
playBtn.style.color = 'yellow';
playBtn.style.cursor = 'pointer';
});
playBtn.addEventListener("mouseout", function () {
playBtn.style.backgroundColor = "yellow";
playBtn.style.color = "darkblue";
playBtn.style.cursor = 'default';
});
let x = 0;
function movePacman() {
if(x < 1800) {
x += 50;
pacman.style.transform = `translateX(${x}px)`;
} else {
x = 0;
pacman.style.transform = `translateX(${x}px)`;
}
}
setInterval(movePacman, 250);