Skip to content

Conversation

@DanieliusAsm
Copy link
Contributor

What

  • Reusable function appendPUSCheckbox

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a reusable function appendPUSCheckbox to standardize the creation of checkbox elements throughout the codebase, replacing hardcoded HTML strings with function calls.

  • Creates a centralized function for generating checkbox HTML markup
  • Refactors existing hardcoded checkbox HTML to use the new function
  • Adds a new checkbox option for "Image rotation and Hunger Games buttons"

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

((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.

} // if list mode

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.
});

} // 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.
Comment on lines +1258 to +1259
function appendPUSCheckbox(checkboxId, labelText){
return `<li><input class="pus-checkbox" type="checkbox" id="${checkboxId}"><label for="${checkboxId}">${labelText}</label></li>`;
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

2 participants