-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent.js
More file actions
191 lines (172 loc) · 6.2 KB
/
Copy pathcontent.js
File metadata and controls
191 lines (172 loc) · 6.2 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Function to apply accessibility changes
function applyAccessibility(disability) {
console.log('Applying accessibility for:', disability);
const existingStyle = document.getElementById('accessibility-style');
if (existingStyle) existingStyle.remove();
// Reset styles
document.body.style.zoom = '';
document.body.style.fontSize = '';
document.body.style.backgroundColor = '';
document.body.style.color = '';
document.body.classList.remove('default-contrast', 'high-contrast');
if (disability === 'vision') {
const style = document.createElement('style');
style.id = 'accessibility-style';
style.textContent = `
body {
font-size: 36px !important;
color: #000 !important;
font-family: Arial, sans-serif !important;
line-height: 1.8 !important;
letter-spacing: 0.5px !important;
}
body.default-contrast {
background-color: #fff !important;
}
body.high-contrast {
background-color: #ff0 !important;
}
a, button, input, select {
font-size: 36px !important;
padding: 10px !important;
border: 2px solid #000 !important;
color: #000 !important;
}
body.default-contrast a, body.default-contrast button, body.default-contrast input, body.default-contrast select {
background-color: #fff !important;
}
body.high-contrast a, body.high-contrast button, body.high-contrast input, body.high-contrast select {
background-color: #ff0 !important;
}
img, video {
display: none !important;
}
:hover {
background-color: #e0e0e0 !important;
}
aside, .sidebar, .ad, [class*="ad"], [id*="ad"], nav:not(:first-child) {
display: none !important;
}
`;
document.head.appendChild(style);
document.body.classList.add('default-contrast');
document.body.style.zoom = '150%';
// Add key handler for 'r' to read text as a bonus feature
document.removeEventListener('keydown', visionKeyHandler);
document.addEventListener('keydown', visionKeyHandler);
console.log('Vision settings applied');
} else if (disability === 'motor') {
document.removeEventListener('keydown', scrollHandler);
document.addEventListener('keydown', scrollHandler);
console.log('Motor settings applied');
} else if (disability === 'colorblind') {
const style = document.createElement('style');
style.id = 'accessibility-style';
style.textContent =
`<style>
body {
padding: 10px;
width: 250px;
}
button {
margin: 5px 0;
padding: 5px;
width: 100%;
border: 2px solid #000 !important; /* Asigură contrast pentru butoane */
}
label {
display: block;
margin-top: 10px;
}
html {
filter: invert(100%) hue-rotate(180deg) !important; /* Ajustare colorblind */
}
a, button {
border: 2px solid #000 !important; /* Elemente interactive clare */
}
:focus {
outline: 3px solid #00f !important; /* Evidențiere la focus */
}
</style>
`
;
document.head.appendChild(style);
console.log('Colorblind mode applied');
}
}
// Scroll handler for motor disability
function scrollHandler(e) {
if (e.key === 'n') window.scrollBy(0, 100);
}
// Vision key handler (bonus: press 'r' to read selected text)
function visionKeyHandler(e) {
if (e.key === 'r') {
const selectedText = window.getSelection().toString();
if (selectedText) {
const utterance = new SpeechSynthesisUtterance(selectedText);
utterance.rate = 0.9;
window.speechSynthesis.speak(utterance);
console.log('Reading aloud:', selectedText);
}
}
}
// Handle messages from popup
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'updateAccessibility') {
applyAccessibility(message.disability);
} else if (message.action === 'speakText') {
const utterance = new SpeechSynthesisUtterance(message.text);
utterance.rate = 0.9;
window.speechSynthesis.speak(utterance);
console.log('Speaking:', message.text);
} else if (message.action === 'toggleContrast') {
if (document.body.classList.contains('high-contrast')) {
document.body.classList.remove('high-contrast');
document.body.classList.add('default-contrast');
console.log('Switched to default contrast');
} else {
document.body.classList.remove('default-contrast');
document.body.classList.add('high-contrast');
console.log('Switched to high-contrast yellow');
}
} else if (message.action === 'toggleZoom') {
document.body.style.zoom = document.body.style.zoom === '150%' ? '' : '150%';
console.log('Zoom set to:', document.body.style.zoom || '100%');
}
});
// Apply settings on page load
window.addEventListener('load', () => {
chrome.storage.sync.get(['userDisability'], (result) => {
if (result.userDisability && result.userDisability !== 'none') {
console.log('Initial load - disability:', result.userDisability);
applyAccessibility(result.userDisability);
}
});
});
function injectAdhdVideo() {
// Evită dublarea
if (document.getElementById('adhd-relax-video')) return;
const iframe = document.createElement('iframe');
iframe.src = 'https://www.youtube.com/embed/u7kdVe8q5zs?autoplay=1&mute=1&loop=1&playlist=u7kdVe8q5zs';
iframe.id = 'adhd-relax-video';
Object.assign(iframe.style, {
position: 'fixed',
bottom: '10px',
left: '10px',
width: '400px',
height: '200px',
zIndex: '999999',
border: '3px solid #222',
borderRadius: '12px',
boxShadow: '0 0 10px rgba(0,0,0,0.5)',
});
document.body.appendChild(iframe);
}
function removeAdhdVideo() {
const existing = document.getElementById('adhd-relax-video');
if (existing) existing.remove();
}
chrome.runtime.onMessage.addListener((message) => {
if (message.action === 'injectAdhdVideo') injectAdhdVideo();
if (message.action === 'removeAdhdVideo') removeAdhdVideo();
});