Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions OpenFoodFactsPower.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')+''+
Copy link

Copilot AI Aug 26, 2025

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.

Suggested change
appendPUSCheckbox('pus-helpers','Field helpers')+''+
appendPUSCheckbox('pus-helpers','Field helpers')+

Copilot uses AI. Check for mistakes.
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>" +
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -1254,6 +1255,10 @@ ul#products_match_all > li > a > span { display: table-cell; width: 70%; vert

} // if list mode

Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function lacks documentation. Consider adding a JSDoc comment to describe its purpose, parameters, and return value for better maintainability.

Suggested change
/**
* 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 uses AI. Check for mistakes.
function appendPUSCheckbox(checkboxId, labelText){
Copy link

Copilot AI Aug 26, 2025

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 uses AI. Check for mistakes.
return `<li><input class="pus-checkbox" type="checkbox" id="${checkboxId}"><label for="${checkboxId}">${labelText}</label></li>`;
Comment on lines +1258 to +1259
Copy link

Copilot AI Aug 26, 2025

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.

Suggested change
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, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}
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>`;

Copilot uses AI. Check for mistakes.
}

var langcodes_with_different_countrycodes = [ "af", "am", "ar", "bn", "cs", "da", "dv", "dz", "el", "et", "fa", "hy", "ja", "ka", "kl", "km", "ko", "lo", "ms", "my", "na", "nb", "ne", "ps", "si", "sl", "sq", "sr", "sv", "ta", "tk", "uk", "ur", "vi", "zh" ];

//Copy data from the list textarea to the ingredients_text in the hidden form so it can be passed to the analyser
Expand Down