Skip to content

Conversation

devsdenepal
Copy link
Collaborator

Description

Screenshot

image

Product/code may vary. Please do a self-check.
Tags: feat, wip

@devsdenepal devsdenepal requested a review from ashiishme January 18, 2025 12:11
@devsdenepal devsdenepal requested a review from ashiishme January 18, 2025 14:04

if (match) {
const commentCount = parseInt(match[1], 10);
if (commentCount < 5) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you create a CONSTANT for this value like MINIMUM_COMMENTS & use it here

Suggested change
if (commentCount < 5) {
if (commentCount < MINIMUM_COMMENTS) {

const runScriptButton = document.getElementById('runScript');
const postList = document.getElementById('postList');
const noPosts = document.getElementById('noPosts');
if (runScriptButton) {
Copy link
Member

Choose a reason for hiding this comment

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

We can exit early here too.

if(!runScriptButton) {
  console.error('#runScript button not found!');
  return;
}

Comment on lines +7 to +8
postList.innerHTML = '';
noPosts.style.display = 'none';
Copy link
Member

Choose a reason for hiding this comment

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

It seems like this is required for clearing the existing content?

We can create a helper function like below also, can we use replaceChildren method rather than innerHTML?

function clearUI() {
  postLisst.replaceChildren();
  noPosts.style.display = 'none';
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the suggestion!

Comment on lines +17 to +44
(results) => {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
return;
}

const lowCommentPosts = results[0]?.result || [];
if (lowCommentPosts.length === 0) {
noPosts.style.display = 'block';
} else {
lowCommentPosts.forEach((post) => {
const li = document.createElement('li');
li.textContent = `Post #${post.posinset} - ${post.commentCount} comments`;
li.style.cursor = 'pointer';

li.addEventListener('click', () => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
func: leaveComment,
args: [post.posinset],
});
});

postList.appendChild(li);
});
}
}
);
Copy link
Member

Choose a reason for hiding this comment

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

This can be a separate function to make things more readable.

@ashiishme
Copy link
Member

Overall, it looks good but can we please typescript here? After the build, the popup.js should be generated but we should use typescript for the development.

"vite": "^6.0.5"
}
}
}
Copy link

Choose a reason for hiding this comment

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

always add newline at the end of file.

If you are using vscode: https://stackoverflow.com/questions/44704968/visual-studio-code-insert-newline-at-the-end-of-files

noPosts.style.display = 'none';
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });

if (tab.id) {
Copy link

Choose a reason for hiding this comment

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

this if statement seems to be so complex.... try to reduce complexity for better maintainability and readability...

simple idea to reduce complexity is it extract this in separate function, and leverage early return.

@puncoz
Copy link

puncoz commented Jan 19, 2025

Overall, it looks good but can we please typescript here? After the build, the popup.js should be generated but we should use typescript for the development.

+1

Copy link

Choose a reason for hiding this comment

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

try implementing this popup.js code as a react component. Since we’re using react, we can simplify all this complexities by leveraging react components to render the content as part of the react DOM.

Co-authored-by: Ashish Yadav <18111862+ashiishme@users.noreply.github.com>
@devsdenepal devsdenepal reopened this Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants