-
-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Reusable function appendPUSCheckbox #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -753,11 +753,11 @@ textarea.monospace { | |||||||||||||||||||||||||||||||
| "<li>(?) or (h): this present help</li>" + | ||||||||||||||||||||||||||||||||
| "<hr id='nav_keys'>" + | ||||||||||||||||||||||||||||||||
| ((pageType === "edit") ? | ||||||||||||||||||||||||||||||||
| '<li><input class="pus-checkbox" type="checkbox" id="pus-helpers" checked><label for="pus-helpers">Field helpers</label></li>' + | ||||||||||||||||||||||||||||||||
| '<li><input class="pus-checkbox" type="checkbox" id="pus-dist-free"><label for="pus-dist-free">Distraction free mode</label></li>': | ||||||||||||||||||||||||||||||||
| appendPUSCheckbox('pus-helpers','Field helpers')+''+ | ||||||||||||||||||||||||||||||||
| appendPUSCheckbox('pus-dist-free','Distraction free mode'): | ||||||||||||||||||||||||||||||||
| "") + | ||||||||||||||||||||||||||||||||
| ((pageType === "edit" || pageType === "list") ? | ||||||||||||||||||||||||||||||||
| '<li><input class="pus-checkbox" type="checkbox" id="pus-ingredients-font"><label for="pus-ingredients-font">Ingredients fixed-width font</label></li>': | ||||||||||||||||||||||||||||||||
| appendPUSCheckbox('pus-ingredients-font','Ingredients fixed-width font'): | ||||||||||||||||||||||||||||||||
| "") + | ||||||||||||||||||||||||||||||||
| ((pageType === "product view" || pageType === "edit") ? | ||||||||||||||||||||||||||||||||
| "<li>(Shift+b): show/hide <strong>barcode</strong></li>" + | ||||||||||||||||||||||||||||||||
|
|
@@ -1186,8 +1186,9 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert | |||||||||||||||||||||||||||||||
| var listhelp = `<ul class="pus_menu"> | ||||||||||||||||||||||||||||||||
| <li>(?) or (h): this present help</li> | ||||||||||||||||||||||||||||||||
| <hr> | ||||||||||||||||||||||||||||||||
| <li><input class="pus-checkbox" type="checkbox" id="pus-ingredients-font"><label for="pus-ingredients-font">Ingredients fixed-width font</label></li> | ||||||||||||||||||||||||||||||||
| <li><input class="pus-checkbox" type="checkbox" id="pus-always-show-barcode"><label for="pus-always-show-barcode">Always show barcodes</label></li> | ||||||||||||||||||||||||||||||||
| ${appendPUSCheckbox('pus-ingredients-font','Ingredients fixed-width font')} | ||||||||||||||||||||||||||||||||
| ${appendPUSCheckbox('pus-always-show-barcode','Always show barcodes')} | ||||||||||||||||||||||||||||||||
| ${appendPUSCheckbox('pus-rotation-hunger-games-buttons','Image rotation and Hunger Games buttons')} | ||||||||||||||||||||||||||||||||
| <hr> | ||||||||||||||||||||||||||||||||
| <li>(Shift+L): List edit mode</li> | ||||||||||||||||||||||||||||||||
| <li>(Shift+b): Show/hide barcodes</li> | ||||||||||||||||||||||||||||||||
|
|
@@ -1254,6 +1255,10 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| } // if list mode | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| /** | |
| * Returns an HTML string for a checkbox with a label, used in the Power User Script UI. | |
| * @param {string} checkboxId - The id attribute for the checkbox input and its label. | |
| * @param {string} labelText - The text to display in the label. | |
| * @returns {string} HTML string for a list item containing the checkbox and label. | |
| */ |
Copilot
AI
Aug 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is defined after it's used in the code above (lines 756, 757, 760, 1189-1191). Consider moving the function definition before its first usage to improve code readability and avoid potential hoisting confusion.
Copilot
AI
Aug 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function doesn't validate or escape the input parameters. If checkboxId or labelText contain HTML special characters, they could lead to XSS vulnerabilities. Consider adding input validation or HTML escaping.
| function appendPUSCheckbox(checkboxId, labelText){ | |
| return `<li><input class="pus-checkbox" type="checkbox" id="${checkboxId}"><label for="${checkboxId}">${labelText}</label></li>`; | |
| function escapeHtml(str) { | |
| return String(str) | |
| .replace(/&/g, '&') | |
| .replace(/</g, '<') | |
| .replace(/>/g, '>') | |
| .replace(/"/g, '"') | |
| .replace(/'/g, '''); | |
| } | |
| function appendPUSCheckbox(checkboxId, labelText){ | |
| const safeId = escapeHtml(checkboxId); | |
| const safeLabel = escapeHtml(labelText); | |
| return `<li><input class="pus-checkbox" type="checkbox" id="${safeId}"><label for="${safeId}">${safeLabel}</label></li>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty string concatenation
+''is unnecessary and adds visual clutter. Consider removing it for cleaner code.