-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontent.js
More file actions
122 lines (108 loc) · 3.68 KB
/
Copy pathcontent.js
File metadata and controls
122 lines (108 loc) · 3.68 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
const saveSettings = (widthValue) => {
try {
browser.storage.local.set({ width: widthValue }).then(() => {
console.debug(`WideGPT: Settings saved - width: ${widthValue}%`);
});
} catch (error) {
console.error("WideGPT: Error saving settings:", error);
}
};
// Load settings from browser storage
const loadSettings = () => {
try {
const result = browser.storage.local.get("width").then((result) => {
const widthValue = result.width || 95; // Default to 95% if not set
console.debug(`WideGPT: Settings loaded - width: ${widthValue}%`);
return widthValue;
});
return result;
} catch (error) {
console.error("WideGPT: Error loading settings:", error);
return 95; // Default width in case of error
}
};
// Function to attach or update a dynamic style rule
const attachOrUpdateStyleRule = (css, id = "dynamic-style") => {
// Check if a style element with the given ID already exists
let style = document.getElementById(id);
if (!style) {
// Create a new style element if it doesn't exist
style = document.createElement("style");
style.type = "text/css";
style.id = id;
document.head.appendChild(style);
}
// Update the CSS content
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.textContent = css;
}
};
// Function to dynamically update the CSS rules
const adjustMaxWidth = (width = 100) => {
console.debug(`WideGPT.adjustMaxWidth() called with width: ${width}%`);
// Dynamically create CSS rules using the specified width
const css = `
@media (min-width: 1280px) {
.xl\\:max-w-\\[48rem\\] {
max-width: ${width}% !important;
}
.xl\\:px-5 {
padding-left: 1.25rem;
padding-right: 1.25rem;
max-width: ${width}% !important;
}
}
@media (min-width: 768px) {
.md\\:max-w-3xl {
max-width: ${width}% !important;
}
}
@container (width >= 64rem) {
.\\@\\[64rem\\]\\:\\[--thread-content-max-width\\:48rem\\] {
--thread-content-max-width: ${width}% !important;
}
}
@container (width >= 34rem) {
.\\@\\[34rem\\]\\:\\[--thread-content-max-width\\:40rem\\] {
--thread-content-max-width: ${width}% !important;
}
}
.thread-lg\\:\\[--thread-content-max-width\\:48rem\\] {
--thread-content-max-width: ${width}% !important;
}
div[class*="--thread-content-max-width"] {
--thread-content-max-width: ${width}% !important;
}
/* Override table container margins added by ChatGPT */
div[class^='_tableContainer'] {
--thread-gutter-size: unset !important;
width: unset !important;
}
/* Ensure table wrapper matches selected width */
div[class^='_tableWrapper'] {
min-width: fit-content !important;
max-width: ${width}% !important;
}
`;
attachOrUpdateStyleRule(css);
};
// Initial call with default width
loadSettings().then((widthValue) => {
const widthInput = document.getElementById("widthinput");
if (widthInput) {
widthInput.value = widthValue; // Set the input field to the loaded value
}
adjustMaxWidth(widthValue);
});
// Add an event listener to the width input field
const widthInput = document.getElementById("widthinput");
if (widthInput) {
widthInput.addEventListener("input", () => {
const widthValue = widthInput.value;
console.debug(`WideGPT: Width input changed to: ${widthValue}%`);
adjustMaxWidth(widthValue);
saveSettings(widthValue);
});
}