-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent.js
More file actions
156 lines (142 loc) · 5.02 KB
/
Copy pathcontent.js
File metadata and controls
156 lines (142 loc) · 5.02 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
function applyStyles(settings) {
const isFontActive = settings.setFont !== false;
const isExpandedActive = settings.expandedMode || false;
const isRtlFixActive = settings.fixRtl || false; // Added
const customUrl = settings.customFontUrl || "";
const fontStylesId = "gemini-vazirmatn-font-styles";
let fontStyleElement = document.getElementById(fontStylesId);
if (isFontActive) {
if (!fontStyleElement) {
fontStyleElement = document.createElement("style");
fontStyleElement.id = fontStylesId;
document.head.appendChild(fontStyleElement);
}
let fontImport = "";
let fontName = "'Vazirmatn', 'Segoe UI', Tahoma, sans-serif";
if (customUrl.startsWith("https://fonts.googleapis.com/css2")) {
try {
const urlParams = new URLSearchParams(customUrl.split("?")[1]);
const familiesParam = urlParams.get("family");
if (familiesParam) {
const mainFamily = familiesParam.split(":")[0].replace(/\+/g, " ");
fontName = `'${mainFamily}', 'Segoe UI', Tahoma, sans-serif`;
}
} catch (e) {
console.error("Could not parse custom font URL:", e);
}
fontImport = `@import url('${customUrl}');\n`;
} else {
fontImport = `
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap');
`;
}
fontStyleElement.textContent = `
${fontImport}
body, p, h1, h2, h3, h4, h5, h6, div, span, a, li, td, th, input, textarea, button {
font-family: ${fontName} !important;
}
*:lang(fa) {
font-family: ${fontName} !important;
}
`;
} else {
if (fontStyleElement) {
fontStyleElement.remove();
}
}
const widthStylesId = "gemini-expanded-width-styles";
let widthStyleElement = document.getElementById(widthStylesId);
if (isExpandedActive) {
if (!widthStyleElement) {
widthStyleElement = document.createElement("style");
widthStyleElement.id = widthStylesId;
document.head.appendChild(widthStyleElement);
}
widthStyleElement.textContent = `
.conversation-container {
max-width: 90% !important;
width: 90% !important;
}
.input-area-container {
max-width: 90% !important;
width: 90% !important;
}
user-query {
max-width: 100% !important;
}
.user-query-bubble-with-background,
.response-container .response-text-container {
max-width: 100% !important;
}
`;
} else {
if (widthStyleElement) {
widthStyleElement.remove();
}
}
// --- Added RTL Fix Engine Section ---
const rtlStylesId = "gemini-rtl-fix-styles";
let rtlStyleElement = document.getElementById(rtlStylesId);
if (isRtlFixActive) {
if (!rtlStyleElement) {
rtlStyleElement = document.createElement("style");
rtlStyleElement.id = rtlStylesId;
document.head.appendChild(rtlStyleElement);
}
// Forces the browser to evaluate the textual direction dynamically based on content string characteristics.
// Targets the main response text contents and the textarea user input block.
rtlStyleElement.textContent = `
.user-query-bubble-with-background,
.response-container .response-text-container,
.rich-textarea,
textarea,
p,
li {
direction: attr(dir, auto) !important;
unicode-bidi: plaintext !important;
text-align: start !important;
}
`;
} else {
if (rtlStyleElement) {
rtlStyleElement.remove();
}
}
}
function applyNotebooksInputHide() {
const isNotebooks = window.location.href.toLowerCase().includes("notebooks");
const styleId = "gemini-notebooks-hide-input";
let styleEl = document.getElementById(styleId);
if (isNotebooks) {
if (!styleEl) {
styleEl = document.createElement("style");
styleEl.id = styleId;
document.head.appendChild(styleEl);
}
styleEl.textContent = `.input-area-container { display: none !important; }`;
} else {
if (styleEl) styleEl.remove();
}
}
// Ensure "fixRtl" is initialized during initialization phase
chrome.storage.sync.get(
["setFont", "expandedMode", "fixRtl", "customFontUrl"],
(settings) => {
applyStyles(settings);
applyNotebooksInputHide();
},
);
window.addEventListener("popstate", applyNotebooksInputHide);
window.addEventListener("hashchange", applyNotebooksInputHide);
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "update_styles") {
chrome.storage.sync.get(
["setFont", "expandedMode", "fixRtl", "customFontUrl"],
(settings) => {
applyStyles(settings);
applyNotebooksInputHide();
},
);
}
});