-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
58 lines (48 loc) · 1.55 KB
/
content.js
File metadata and controls
58 lines (48 loc) · 1.55 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
// Get all relevant elements (paragraphs, headings, and elements with paragraph class)
function getRelevantElements() {
const selector = 'p, h1, h2, h3, h4, h5, h6, .paragraph';
return document.querySelectorAll(selector);
}
// Apply settings to elements
function applySettings(settings) {
const elements = getRelevantElements();
elements.forEach(element => {
// Reset styles first
element.style.direction = '';
element.style.fontFamily = '';
// Apply based on settings
if (settings.both) {
element.style.direction = 'rtl';
element.style.fontFamily = 'Tahoma, sans-serif';
} else if (settings.rtl) {
element.style.direction = 'rtl';
} else if (settings.font) {
element.style.fontFamily = 'Tahoma, sans-serif';
}
});
}
// Load and apply settings for current domain
async function loadAndApplySettings() {
const domain = window.location.hostname;
const key = `settings_${domain}`;
chrome.storage.local.get(key, (result) => {
const settings = result[key] || { rtl: false, font: false, both: false };
applySettings(settings);
});
}
// Listen for messages from popup
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'applySettings') {
applySettings(request.settings);
}
});
// Apply settings when page loads
loadAndApplySettings();
// Observe DOM changes and reapply settings to new elements
const observer = new MutationObserver(() => {
loadAndApplySettings();
});
observer.observe(document.body, {
childList: true,
subtree: true
});