-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
139 lines (116 loc) · 3.5 KB
/
Copy pathcontent.js
File metadata and controls
139 lines (116 loc) · 3.5 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
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
129
130
131
132
133
134
135
136
137
138
139
console.log('Wiki page generated');
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'SHOW_WIN_OVERLAY') {
showWinOverlay(message.data);
}
});
function showWinOverlay(data) {
const style = document.createElement('style');
style.textContent = `
#wiki-congrats-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.4);
display: flex;
justify-content: center;
align-items: center;
z-index: 999999;
cursor: pointer;
}
.overlay-content {
background: white;
padding: 32px 48px;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
animation: fadeIn 0.3s ease-out;
}
.overlay-content h1 {
color: #1a1a1a;
font-size: 28px;
margin: 0 0 12px 0;
text-align: center;
font-family: 'Inter', -apple-system, sans-serif;
font-weight: 500;
letter-spacing: -0.02em;
}
.overlay-stats {
color: #666;
font-size: 15px;
text-align: center;
font-family: 'Inter', -apple-system, sans-serif;
font-weight: 400;
}
@keyframes fadeIn {
0% {
transform: translateY(-10px);
opacity: 0;
}
100% {
transform: translateY(0);
opacity: 1;
}
}
`;
document.head.appendChild(style);
const overlay = document.createElement('div');
overlay.id = 'wiki-congrats-overlay';
const timeInSeconds = Math.round(data.timeTaken / 1000);
const minutes = Math.floor(timeInSeconds / 60);
const seconds = timeInSeconds % 60;
const timeDisplay = minutes > 0 ? `${minutes}m ${seconds}s` : `${seconds}s`;
overlay.innerHTML = `
<div class="overlay-content">
<h1> YAY you made the connections !! </h1>
<div class="overlay-stats">
Clicks: ${data.clickCount} Time: ${timeDisplay}
</div>
</div>
`;
document.body.appendChild(overlay);
overlay.addEventListener('click', () => {
overlay.remove();
});
}
document.addEventListener('click', (e) => {
const link = e.target.closest('a');
if(!link) return;
const href = link.getAttribute('href');
if(!href || !href.startsWith('/wiki/')) return;
if(href.includes(':') || href.includes('#')) return;
const fullUrl = `https://en.wikipedia.org${href}`;
const articleTitle = decodeURIComponent(href.replace('/wiki/', '').replace(/_/g, ' '));
chrome.storage.local.get(['currentGame'], (result) => {
if (!result.currentGame) return;
else{
console.log("Are we adding it", result.currentGame.allUrls);
}
});
console.log("Already taken previously", );
console.log('Wikipedia link clicked:', articleTitle);
chrome.runtime.sendMessage({
type: 'WIKI_LINK_CLICKED',
data: {
url: fullUrl,
title: articleTitle,
timestamp: Date.now()
}
});
});
chrome.storage.local.get(['currentGame'], (result) => {
if (!result.currentGame) return;
const currentUrl = window.location.href;
const currentTitle = document.title.replace(' - Wikipedia', '');
if (currentTitle === result.currentGame.targetArticle) {
chrome.runtime.sendMessage({
type: 'GAME_WON',
data: {
clickCount: result.currentGame.clickCount,
timeTaken: Date.now() - result.currentGame.startTime,
path: result.currentGame.allUrls
}
});
}
});