-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
145 lines (127 loc) · 4.89 KB
/
Copy pathscript.js
File metadata and controls
145 lines (127 loc) · 4.89 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
// Matrix Rain Effect
const canvas = document.getElementById('matrix-canvas');
const ctx = canvas.getContext('2d');
const chars = 'あいうえおかきくけこさしすせそたちつてとはひふへほまみむめもやゆよらりるれろわをんゃゅょっハヒフヘホマミムメモヤユヨラリルレロワヲンアイウエオカキクケコサシスセソタチツテトナニヌネノ';
const charArray = chars.split('');
const fontSize = 16;
let drops = [], columns = 0;
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
columns = Math.floor(canvas.width / fontSize);
drops = new Array(columns).fill(1);
}
function draw() {
ctx.fillStyle = 'rgba(0,0,0,0.04)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.font = fontSize + 'px "Noto Sans JP", "Yu Gothic", "Meiryo", "MS Gothic", sans-serif';
ctx.shadowColor = '#ff0000';
ctx.shadowBlur = 2;
ctx.fillStyle = 'rgba(255,50,120,0.8)';
for (let i = 0; i < columns; i++) {
const text = charArray[Math.floor(Math.random() * charArray.length)];
ctx.fillText(text, i * fontSize, drops[i] * fontSize);
if (drops[i] * fontSize > canvas.height && Math.random() > 0.975) drops[i] = 0;
drops[i]++;
}
ctx.shadowBlur = 0;
}
function animate() {
draw();
requestAnimationFrame(animate);
}
let resizeTimeout;
window.addEventListener('resize', () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(resizeCanvas, 200);
});
function isValidLink(input) {
try {
// Add protocol if missing
const withProtocol = input.startsWith('http://') || input.startsWith('https://')
? input
: `https://${input}`;
const url = new URL(withProtocol);
return /^[a-z0-9.-]+\.[a-z]{2,}$/i.test(url.hostname);
} catch (_) {
return false;
}
}
document.addEventListener('DOMContentLoaded', () => {
const greetingText = document.getElementById('greetingText');
const searchBox = document.getElementById('searchBox');
const engineToggle = document.getElementById('engineToggle');
const engineIcon = document.getElementById('engineIcon');
let currentEngine = 'google';
searchBox.focus();
chrome.storage.sync.get(['customName'], (result) => {
const name = result.customName || 'Guest';
greetingText.textContent = `Hello, ${name}`;
});
// Toggle search engine
engineToggle.addEventListener('click', () => {
currentEngine = currentEngine === 'google' ? 'youtube' : 'google';
engineIcon.src = `icons/${currentEngine}.png`;
});
// Perform search
searchBox.addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
const query = this.value.trim();
if (isValidLink(query)) {
const url = query.startsWith('http://') || query.startsWith('https://')
? query
: `http://${query}`;
window.location.href = url;
} else if (query) {
const baseUrl = currentEngine === 'google'
? 'https://www.google.com/search?q='
: 'https://www.youtube.com/results?search_query=';
window.location.href = baseUrl + encodeURIComponent(query);
this.value = '';
}
}
});
// Settings modal
const settingsBtn = document.getElementById('settingsBtn');
const settingsModal = document.getElementById('settingsModal');
const nameInput = document.getElementById('nameInput');
const titleInput = document.getElementById('titleInput');
const saveSettingsBtn = document.getElementById('saveSettingsBtn');
// Load saved values
chrome.storage.sync.get(['customName', 'customTitle'], (result) => {
const name = result.customName || 'Guest';
const title = result.customTitle || 'New Tab';
greetingText.textContent = `Hello, ${name}`;
document.title = title;
});
// Open modal and populate values
settingsBtn.addEventListener('click', () => {
settingsModal.style.display = 'flex';
chrome.storage.sync.get(['customName', 'customTitle'], (result) => {
nameInput.value = result.customName || '';
titleInput.value = result.customTitle || '';
});
});
// Save settings
saveSettingsBtn.addEventListener('click', () => {
const name = nameInput.value.trim();
const title = titleInput.value.trim();
chrome.storage.sync.set({
customName: name,
customTitle: title
}, () => {
greetingText.textContent = `Hello, ${name || 'Guest'}`;
document.title = title || 'New Tab';
settingsModal.style.display = 'none';
});
});
// Close modal when clicking outside
window.addEventListener('click', (e) => {
if (e.target === settingsModal) {
settingsModal.style.display = 'none';
}
});
// Init
resizeCanvas();
requestAnimationFrame(animate);
});