This repository was archived by the owner on Sep 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpopup.js
More file actions
151 lines (122 loc) · 4.93 KB
/
popup.js
File metadata and controls
151 lines (122 loc) · 4.93 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
140
141
142
143
144
145
146
147
148
149
150
151
async function getActiveTab() {
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
return tabs && tabs.length ? tabs[0] : null;
}
function isAllowedTab(tab) {
if (!tab) return false;
const url = tab.url || '';
const title = (tab.title || '').trim();
const urlOk = /^https?:\/\/checkout\.stripe\.com/.test(url);
const titleOk = title === 'Cursor';
return urlOk && titleOk;
}
async function startActivation() {
const textarea = document.getElementById('activationText');
const text = textarea ? textarea.value.trim() : '';
const statusEl = document.getElementById('activationStatus');
function showStatus(message, isError = false) {
if (statusEl) {
statusEl.textContent = message;
statusEl.style.color = isError ? '#ff9f9f' : '#a0ffa0';
statusEl.style.whiteSpace = 'pre-line';
statusEl.style.display = 'block';
}
}
function validateAndNormalize(raw) {
const lines = String(raw || '')
.split(/\r?\n/)
.map(l => l.trim())
.filter(Boolean);
if (!lines.length) {
return { ok: false, errors: ['No input provided.'] };
}
const errors = [];
const normalized = [];
lines.forEach((line, idx) => {
const n = idx + 1;
const parts = line.split('|').map(p => (p || '').trim());
if (parts.length !== 4) {
errors.push(`Line ${n}: expected format "NUMBER|MM|YYYY|CVC".`);
return;
}
let [num, mm, yyyy, cvc] = parts;
num = (num || '').replace(/\s+/g, '');
if (!/^\d{16}$/.test(num)) {
errors.push(`Line ${n}: card number must be exactly 16 digits.`);
}
if (!/^\d{2}$/.test(mm) || Number(mm) < 1 || Number(mm) > 12) {
errors.push(`Line ${n}: month must be in 01–12.`);
}
if (!/^\d{4}$/.test(yyyy)) {
errors.push(`Line ${n}: year must be 4 digits (e.g., 2030).`);
}
if (!/^\d{3}$/.test(cvc)) {
errors.push(`Line ${n}: CVC must be exactly 3 digits.`);
}
normalized.push([num, mm, yyyy, cvc].join('|'));
});
if (errors.length) {
return { ok: false, errors };
}
return { ok: true, text: normalized.join('\n') };
}
try {
const activeTab = await getActiveTab();
if (!isAllowedTab(activeTab)) {
showStatus('This is not Cursor checkout page.', true);
return;
}
const status = await chrome.tabs.sendMessage(activeTab.id, { type: 'activation-status' });
if (status && status.ok && status.running) {
showStatus('Activation already started in this tab.');
return;
}
const result = validateAndNormalize(text);
if (!result.ok) {
showStatus(result.errors.join('\n'), true);
return;
}
const response = await chrome.tabs.sendMessage(activeTab.id, { type: 'activation-begin', payload: { text: result.text } });
if (response && response.ok) {
showStatus('Activation started in this tab.');
} else {
showStatus('Failed to start activation. Is the page ready?', true);
}
} catch (e) {
console.error('Activation error:', e);
showStatus('An error occurred. Check the console and reload the page.', true);
}
}
document.getElementById('startActivation').addEventListener('click', startActivation);
document.addEventListener('DOMContentLoaded', async () => {
const startBtn = document.getElementById('startActivation');
const statusEl = document.getElementById('activationStatus');
try {
const activeTab = await getActiveTab();
const allowed = isAllowedTab(activeTab);
if (startBtn) startBtn.disabled = !allowed;
if (!allowed && statusEl) {
statusEl.textContent = 'You cannot start activation on this page. Go to Cursor Checkout Page.';
statusEl.style.color = '#ff9f9f';
statusEl.style.display = 'block';
}
} catch (_) { /* ignore */ }
const animatedText = document.querySelector('.animated-text');
if (animatedText) {
const text = animatedText.textContent;
animatedText.textContent = '';
text.split('').forEach((char, index) => {
const span = document.createElement('span');
span.textContent = char === ' ' ? '\u00A0' : char;
span.style.transitionDelay = `${index * 50}ms`;
animatedText.appendChild(span);
});
setTimeout(() => {
const spans = animatedText.querySelectorAll('span');
spans.forEach(span => {
span.style.opacity = '1';
span.style.transform = 'translateY(0) scale(1)';
});
}, 100);
}
});