Skip to content

Commit 2b95f69

Browse files
committed
Almost completed text decoration
1 parent 037b2a6 commit 2b95f69

File tree

6 files changed

+107
-9
lines changed

6 files changed

+107
-9
lines changed

_locales/en/messages.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
"popupTextShadowActivation": {
2121
"message": "Activate text shadow"
2222
},
23+
"popupTextDecorationActivation": {
24+
"message": "Activate text decoration"
25+
},
26+
"popupTextDecorationTypeFieldName": {
27+
"message": "Decoration type"
28+
},
29+
"popupDecorationColorFieldName": {
30+
"message": "Decoration color"
31+
},
2332
"popupNewCustomUrl": {
2433
"message": "New custom url"
2534
},

background.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ async function restoreOptions(tab) {
3131
storage.customOptions.forEach((element) => {
3232
if (matchRuleShort(url, element.url)) { // Compare custom setting's hostname with the tab's
3333
injected = true;
34-
css = '::selection { background: ' + element.background + ' !important; color: ' + element.color + ((element.shadowActivated) ? ' !important; text-shadow: ' + element.shadowColor + ' 0px 0px ' + element.shadowBlur + 'px !important' : '') + '}';
34+
css = '::selection { background: ' + element.background + ' !important; color: ' + element.color + ' !important;' + ((element.shadowActivated) ? 'text-shadow: ' + element.shadowColor + ' 0px 0px ' + element.shadowBlur + 'px !important;' : '') + ((element.decorationActivated) ? 'text-decoration: ' + element.decorationType + ' ' + element.decorationColor + ' !important;' : '') + '}';
3535
}
3636
});
3737
}
3838
if (!injected && storage.witness) { // If url didn't match any custom settings and the user already defined some settings (avoid injecting undefined values into CSS)
39-
css = '::selection { background: ' + storage.background_color + ' !important; color: ' + storage.color + ((storage.shadowActivated) ? ' !important; text-shadow: ' + storage.shadowColor + ' 0px 0px ' + storage.shadowBlur + 'px !important' : '') + '}';
39+
css = '::selection { background: ' + storage.background_color + ' !important; color: ' + storage.color + ' !important;' + ((storage.shadowActivated) ? 'text-shadow: ' + storage.shadowColor + ' 0px 0px ' + storage.shadowBlur + 'px !important;' : '') + ((storage.decorationActivated) ? 'text-decoration: ' + storage.decorationType + ' ' + storage.decorationColor + ' !important;' : '') + '}';
4040
}
4141
browser.scripting.insertCSS({
4242
target: {
@@ -113,17 +113,32 @@ chrome.runtime.onInstalled.addListener(async details => {
113113
shadowActivated: false,
114114
shadowColor: "#007EF3FF",
115115
shadowBlur: "0",
116+
decorationActivated: false,
117+
decorationType: "none",
118+
decorationColor: "#007EF3FF",
116119
witness: true
117120
});
118121
break;
119122
case "update":
120123
var storage = await browser.storage.local.get(); // Get settings
124+
if (!storage.hasOwnProperty('decorationActivated')) {
125+
browser.storage.local.set({ // Set basic settings
126+
decorationActivated: false,
127+
decorationType: "none",
128+
decorationColor: "#007EF3FF"
129+
});
130+
}
121131
if (storage.customOptions) { // If custom settings are defined
122132
var customs = storage.customOptions;
123133
customs.forEach((element) => {
124134
try {
125135
let cururl = new URL(element.url);
126136
element.url = cururl.host;
137+
if (!element.hasOwnProperty('decorationActivated')) {
138+
element.decorationActivated = false;
139+
element.decorationType = "none";
140+
element.decorationColor = "#007EF3FF";
141+
}
127142
} catch (error) {
128143

129144
}

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "__MSG_appName__",
44
"author": "Pythack",
55
"default_locale": "en",
6-
"version": "1.8.3",
6+
"version": "2.0.0",
77
"description": "__MSG_appDesc__",
88
"background": {
99
"service_worker": "./background.js"

popup.css

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ input {
6666
width: 70%;
6767
}
6868

69-
#activate_textShadow {
69+
input[type="checkbox"] {
7070
background: rgba(12, 12, 13, 0.1);
7171
border: 1px rgba(12, 12, 13, 0.3);
7272
height: 16px;
7373
margin: 4px;
7474
width: 16px;
7575
}
7676

77-
#activate_textShadow:checked {
77+
input[type="checkbox"]:checked {
7878
background: #0060df;
7979
}
8080

@@ -86,6 +86,14 @@ input {
8686
width: 100%;
8787
}
8888

89+
#textDecorationOptions {
90+
display: none;
91+
justify-content: center;
92+
align-items: center;
93+
flex-direction: column;
94+
width: 100%;
95+
}
96+
8997
#url_div {
9098
display: none;
9199
}
@@ -236,7 +244,7 @@ input[type="url"]:placeholder-shown:focus {
236244
box-shadow: 0 0 15px rgb(200, 200, 200);
237245
}
238246

239-
#formdivtxtsh {
247+
#formdivtxtdec {
240248
margin-bottom: 3cm;
241249
}
242250

popup.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h1 id="title">__MSG_appName__</h1>
2222
<label>__MSG_popupColorFieldName__: </label><br>
2323
<input id="color" value="#007EF3FF" data-jscolor="{}"><br>
2424
<label>__MSG_popupBackgroundColorFieldName__: </label><br>
25-
<input id="background_color" value="#007EF380" data-jscolor="{}">
25+
<input id="background_color" value="#007EF333" data-jscolor="{}">
2626
</div>
2727
<br><br>
2828
<div id="formdivtxtsh" class="formdivel">
@@ -34,6 +34,21 @@ <h1 id="title">__MSG_appName__</h1>
3434
<label>__MSG_popupTextShadowBlurFieldName__: </label><input type="number" placeholder="15" min="0" id="shadow-blur">
3535
</div>
3636
</div>
37+
<br><br>
38+
<div id="formdivtxtdec" class="formdivel">
39+
<input id="activate_textDecoration" name="activate_textDecoration" type="checkbox"><label for="activate_textDecoration">__MSG_popupTextDecorationActivation__</label><br>
40+
<div id="textDecorationOptions">
41+
<label>__MSG_popupTextDecorationTypeFieldName__: </label><br>
42+
<select class="" id="decoration_select" name="">
43+
<option value="underline">Underline</option>
44+
<option value="line-through">Strike through</option>
45+
<option value="blink">Blink</option>
46+
</select>
47+
<br>
48+
<label>__MSG_popupDecorationColorFieldName__: </label><br>
49+
<input id="decoration-color" value="#007EF333" data-jscolor="{}">
50+
</div>
51+
</div>
3752
<div id="formdivprv" class="formdivel">
3853
<label>__MSG_popupPreview__: </label><br/><p id="preview">Lorem ipsum</p>
3954
<button type="submit" id="save_btn">__MSG_popupSave__</button>

popup.js

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ function onError(error) {
4141
}
4242

4343
class Custom_option {
44-
constructor(url, background, color, shadowActivated, shadowColor, shadowBlur) {
44+
constructor(url, background, color, shadowActivated, shadowColor, shadowBlur, decorationActivated, decorationType, decorationColor) {
4545
this.url = url;
4646
this.color = color;
4747
this.background = background;
4848
this.shadowActivated = shadowActivated;
4949
this.shadowColor = shadowColor;
5050
this.shadowBlur = shadowBlur;
51+
this.decorationActivated = decorationActivated;
52+
this.decorationType = decorationType;
53+
this.decorationColor = decorationColor;
5154
}
5255
};
5356

@@ -56,7 +59,7 @@ function addCustom() {
5659
getting.then(result => {
5760
var custom_url = document.querySelector("#add_url").value; // Get new custom url
5861
document.querySelector("#add_url").value = "";
59-
var customSettings = new Custom_option(custom_url, document.querySelector("#background_color").value || "#007EF3", document.querySelector("#color").value || "white", document.querySelector("input#activate_textShadow").checked || false, document.querySelector("#shadow-color").value || "none", document.querySelector("#shadow-blur").value || "0"); // Create new element with currently displayed settings
62+
var customSettings = new Custom_option(custom_url, document.querySelector("#background_color").value || "#007EF3", document.querySelector("#color").value || "white", document.querySelector("input#activate_textShadow").checked || false, document.querySelector("#shadow-color").value || "none", document.querySelector("#shadow-blur").value || "0", document.querySelector("input#activate_textDecoration").checked || false, document.querySelector("#decoration_select").value || "none", document.querySelector("#decoration-color").value || "#007EF3FF"); // Create new element with currently displayed settings
6063
var customs = result.customOptions || []; // Get current saved settings; if there are none, initialize an empty list
6164
customs.push(customSettings); // Add new custom settings to the list
6265
browser.storage.local.set({ // Store the new list in the storage
@@ -95,18 +98,30 @@ function removeCustom() {
9598
document.querySelector("#shadow-color").jscolor.fromString(result.shadowColor || "#ffffff");
9699
document.querySelector("#shadow-blur").value = result.shadowBlur || "0px";
97100
document.querySelector("input#activate_textShadow").checked = result.shadowActivated;
101+
document.querySelector("input#activate_textDecoration").checked = result.decorationActivated;
102+
document.querySelector("#decoration_select").value = result.decorationType;
103+
document.querySelector("#decoration-color").jscolor.fromString(result.decorationColor || "#007EF3FF");
98104
if(result.shadowActivated) {
99105
document.querySelector('div#textShadowOptions').style.display = "flex";
100106
} else {
101107
document.querySelector('div#textShadowOptions').style.display = "none";
102108
}
109+
110+
if(result.decorationActivated) {
111+
document.querySelector('div#textDecorationOptions').style.display = "flex";
112+
} else {
113+
document.querySelector('div#textDecorationOptions').style.display = "none";
114+
};
103115
chrome.tabs.query({active: true, currentWindow: true}, async tabs => {
104116
var activeTab = tabs[0];
105117
var activeTabURL = new URL(activeTab.url);
106118
let urlField = document.querySelector("#add_url");
107119
urlField.value = activeTabURL.host;
108120
});
109121
updatePreview(); // Update preview
122+
browser.runtime.sendMessage({ // Send message to background script asking to update the action icon
123+
request: "inject-css-all"
124+
});
110125
browser.runtime.sendMessage({ // Send message to background script asking to update the action icon
111126
request: "update-action-icon"
112127
});
@@ -123,6 +138,9 @@ function saveOptions(e) { // Function called when user clicks on "Save" button
123138
shadowActivated: document.querySelector("input#activate_textShadow").checked || false,
124139
shadowColor: document.querySelector("#shadow-color").value || "none",
125140
shadowBlur: document.querySelector("#shadow-blur").value || "0",
141+
decorationActivated: document.querySelector("input#activate_textDecoration").checked || false,
142+
decorationType: document.querySelector("#decoration_select").value || "none",
143+
decorationColor: document.querySelector("#decoration-color").value || "none",
126144
witness: true
127145
});
128146
preferencesSave.then(saveSuccess, saveError); // Display notifications
@@ -137,6 +155,9 @@ function saveOptions(e) { // Function called when user clicks on "Save" button
137155
shadowActivated: document.querySelector("input#activate_textShadow").checked || false,
138156
shadowColor: document.querySelector("#shadow-color").value || "none",
139157
shadowBlur: document.querySelector("#shadow-blur").value || "0",
158+
decorationActivated: document.querySelector("input#activate_textDecoration").checked || false,
159+
decorationType: document.querySelector("#decoration_select").value || "none",
160+
decorationColor: document.querySelector("#decoration-color").value || "none",
140161
url: document.querySelector("#change_url").value
141162
};
142163
var preferencesSave = browser.storage.local.set({ // Update custom settings
@@ -161,6 +182,11 @@ function updatePreview() { // Function called when input values are changed
161182
} else {
162183
document.querySelector("#preview").style.textShadow = "";
163184
}
185+
if (document.querySelector("input#activate_textDecoration").checked) {
186+
document.querySelector("#preview").style.textDecoration = document.querySelector("#decoration_select").value + " " + document.querySelector("#decoration-color").value;
187+
} else {
188+
document.querySelector("#preview").style.textDecoration = "";
189+
}
164190
};
165191

166192
function restoreOptions() {
@@ -210,6 +236,14 @@ function updateShadowColorDisplay() {
210236
}
211237
};
212238

239+
function updateDecorationDisplay() {
240+
if (document.querySelector("input#activate_textDecoration").checked) {
241+
document.querySelector('div#textDecorationOptions').style.display = "flex"
242+
} else {
243+
document.querySelector('div#textDecorationOptions').style.display = "none"
244+
}
245+
};
246+
213247
function changeCustomDisplay(event) { // Function called when select changes
214248
var selectIndex = document.querySelector("#custom_select").selectedIndex;
215249
if(selectIndex != 0) { // If selected option is not default settings
@@ -226,11 +260,19 @@ function changeCustomDisplay(event) { // Function called when select changes
226260
document.querySelector("#shadow-color").jscolor.fromString(customs[selectIndex - 1].shadowColor || "#ffffff");
227261
document.querySelector("#shadow-blur").value = customs[selectIndex - 1].shadowBlur || "0px";
228262
document.querySelector("input#activate_textShadow").checked = customs[selectIndex - 1].shadowActivated;
263+
document.querySelector("input#activate_textDecoration").checked = customs[selectIndex - 1].decorationActivated;
264+
document.querySelector("#decoration_select").value = customs[selectIndex - 1].decorationType;
265+
document.querySelector("#decoration-color").jscolor.fromString(customs[selectIndex - 1].decorationColor || "#007EF3FF");
229266
if(customs[selectIndex - 1].shadowActivated) {
230267
document.querySelector('div#textShadowOptions').style.display = "flex";
231268
} else {
232269
document.querySelector('div#textShadowOptions').style.display = "none";
233270
};
271+
if(customs[selectIndex - 1].decorationActivated) {
272+
document.querySelector('div#textDecorationOptions').style.display = "flex";
273+
} else {
274+
document.querySelector('div#textDecorationOptions').style.display = "none";
275+
};
234276
updatePreview(); // Update preview
235277
}, onError);
236278
} else {
@@ -244,11 +286,19 @@ function changeCustomDisplay(event) { // Function called when select changes
244286
document.querySelector("#shadow-color").jscolor.fromString(result.shadowColor || "#ffffff");
245287
document.querySelector("#shadow-blur").value = result.shadowBlur || "0px";
246288
document.querySelector("input#activate_textShadow").checked = result.shadowActivated;
289+
document.querySelector("input#activate_textDecoration").checked = result.decorationActivated;
290+
document.querySelector("#decoration_select").value = result.decorationType;
291+
document.querySelector("#decoration-color").jscolor.fromString(result.decorationColor || "#007EF3FF");
247292
if(result.shadowActivated) {
248293
document.querySelector('div#textShadowOptions').style.display = "flex";
249294
} else {
250295
document.querySelector('div#textShadowOptions').style.display = "none";
251296
}
297+
if(result.decorationActivated) {
298+
document.querySelector('div#textDecorationOptions').style.display = "flex";
299+
} else {
300+
document.querySelector('div#textDecorationOptions').style.display = "none";
301+
};
252302
updatePreview(); // Update preview
253303
}, onError);
254304
};
@@ -301,3 +351,4 @@ document.querySelector("#remove_custom").addEventListener("click", removeCustom)
301351
document.querySelector("input#activate_textShadow").addEventListener("change", updatePreview);
302352
document.querySelector("select#custom_select").addEventListener("change", changeCustomDisplay);
303353
document.querySelector("input#activate_textShadow").addEventListener("change", updateShadowColorDisplay);
354+
document.querySelector("input#activate_textDecoration").addEventListener("change", updateDecorationDisplay);

0 commit comments

Comments
 (0)