Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
madawei2699 committed Nov 12, 2024
1 parent d65b3d1 commit ca868aa
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 79 deletions.
158 changes: 158 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Contributing to Community TL;DR

We love your input! We want to make contributing to Community TL;DR as easy and transparent as possible, whether it's:

- Reporting a bug
- Discussing the current state of the code
- Submitting a fix
- Proposing new features
- Adding support for new communities

## Development Process

We use GitHub to host code, to track issues and feature requests, as well as accept pull requests.

1. Fork the repo and create your branch from `main`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. Issue that pull request!

## Adding Support for New Communities

To add support for a new community, you'll need to:

1. Create a new parser in `src/content/parsers/`:
```javascript
// Example: src/content/parsers/reddit.js
export class RedditParser extends BaseParser {
isDiscussionPage() {
// Implementation
}

getPageContent() {
// Implementation
}

parseCommentThread(commentElement) {
// Implementation
}

// ... other required methods
}
```

2. Update the community registry in `src/content/registry.js`:
```javascript
import { HNParser } from './parsers/hn';
import { RedditParser } from './parsers/reddit';

export const COMMUNITY_PARSERS = {
'news.ycombinator.com': HNParser,
'reddit.com': RedditParser,
// Add your new parser here
};
```

3. Add necessary styles in `src/styles/`:
```css
/* styles/reddit.css */
.tldr-reddit-specific-class {
/* Your styles */
}
```

4. Update the manifest to include new permissions if needed:
```json
{
"host_permissions": [
"https://news.ycombinator.com/*",
"https://www.reddit.com/*"
// Add your new domain
]
}
```

### Parser Requirements

Your parser must implement these methods:

- `isDiscussionPage()`: Detect if current page is a discussion
- `getPageContent()`: Extract main post content
- `parseCommentThread()`: Parse comment thread structure
- `getTopLevelComments()`: Get top-level comments
- `scrollToComment()`: Handle comment navigation

## Code Style Guidelines

- Use meaningful variable names
- Write comments for complex logic
- Follow the existing code style
- Use TypeScript for new code if possible
- Keep functions small and focused

## Testing

- Add appropriate test cases
- Test across different browsers
- Test with various content types
- Verify error handling

## Community Parser Template

Here's a template for new community parsers:

```javascript
export class CommunityParser extends BaseParser {
constructor() {
super();
this.communitySpecific = {};
}

isDiscussionPage() {
// Return boolean indicating if current page is a discussion
return false;
}

getPageContent() {
// Return {
// title: string,
// text: string,
// url: string,
// author: string
// }
return null;
}

parseCommentThread(commentElement) {
// Return {
// id: string,
// root: Comment,
// replies: Comment[],
// level: number
// }
return null;
}

getTopLevelComments() {
// Return HTMLElement[]
return [];
}

scrollToComment(commentId) {
// Implement smooth scroll to comment
}
}
```

## Pull Request Process

1. Update the README.md with details of changes if needed
2. Update the documentation for new communities
3. Update the version numbers following [SemVer](http://semver.org/)
4. The PR will be merged once you have sign-off from maintainers

## Any questions?

Feel free to ask in issues or discussions!
88 changes: 72 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
# Community TL;DR

A Chrome extension that uses AI to summarize Hacker News discussions, providing quick insights into lengthy threads.
A Chrome extension powered by AI to generate quick summaries of community discussions. Get insights from lengthy threads without reading through everything.

## Features

- 🤖 AI-powered discussion summarization
- 📱 Support for Hacker News discussions
- 🌐 Multiple language support (English, Chinese, Japanese, Korean)
- 🔄 Custom AI endpoint configuration
- 📊 Thread-level summaries
- 🎯 Focused on key points and insights
- 🌐 Multiple community support (currently supports Hacker News, more coming soon)
- 🌍 Multiple language support
- English
- Chinese (中文)
- Japanese (日本語)
- Korean (한국어)
- ⚙️ Flexible AI backend
- Custom API endpoint
- OpenAI API
- Anthropic Claude
- Cloudflare AI Worker
- 📱 Thread-level summaries
- 🎯 Focus on key points and insights
- 📊 Smart content analysis

## Supported Communities

Currently supported:
- ✅ Hacker News discussions

Coming soon:
- 🔄 Reddit
- 🔄 Stack Overflow
- 🔄 GitHub Discussions
- More suggestions welcome!

## Installation

Since this extension is not yet available on the Chrome Web Store, you'll need to install it manually:
Since this extension is not yet available on the Chrome Web Store, follow these steps to install:

1. Download the latest release from the [Releases](../../releases) page
2. Unzip the downloaded file
3. Open Chrome and navigate to `chrome://extensions/`
4. Enable "Developer mode" in the top right corner
3. Open Chrome and go to `chrome://extensions/`
4. Enable "Developer mode" in the top right
5. Click "Load unpacked" and select the unzipped folder

## Development Setup
Expand All @@ -41,29 +61,32 @@ npm run build
## Configuration

1. After installation, click the extension icon and go to Settings
2. Configure your preferred AI service:
2. Configure your AI service:
- Custom Endpoint (recommended)
- OpenAI
- Anthropic (Claude)
- Cloudflare AI Worker
3. Set your preferred summarization language
3. Set your preferred:
- Summary language
- Summary length
- Auto-summarize options
4. Save settings and start using

## Usage

1. Visit any Hacker News discussion page
1. Visit a supported community discussion page
2. Click the extension icon to show the summary sidebar
3. Click "TL;DR" next to any thread to summarize it
3. Use the "TL;DR" button next to threads to summarize them
4. View summaries in the sidebar
5. Click on summaries to jump to original comments
5. Click on summaries to jump to original content

## Building From Source

```bash
# Install dependencies
npm install

# Development build
# Development build with watch mode
npm run dev

# Production build
Expand All @@ -74,12 +97,45 @@ npm run build

## Contributing

We welcome contributions! Here are some ways you can help:

1. 🐛 Report bugs
2. 💡 Suggest new features
3. 🌐 Add support for new communities
4. 📝 Improve documentation
5. 🔧 Submit pull requests

### Development Workflow

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

### Adding Support for New Communities

Interested in adding support for a new community? Check out our [Contributing Guide](CONTRIBUTING.md) for details on:
- Architecture overview
- Adding new parsers
- Testing guidelines
- PR submission process

## Future Plans

- [ ] Support for more communities
- [ ] Enhanced summarization options
- [ ] Offline mode with local AI models
- [ ] Custom prompt templates
- [ ] Summary sharing functionality
- [ ] Community voting on summaries

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

- Thanks to all contributors and users
- Special thanks to the open source community
- AI providers for making this possible
10 changes: 7 additions & 3 deletions src/content/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// src/content/index.js
import { HNParser } from './hn/parser';
import { getParser, isSupportedSite } from './parsers/registry';

// Simple markdown renderer
const renderMarkdown = (text) => {
Expand All @@ -19,7 +18,12 @@ const renderMarkdown = (text) => {

class ContentScript {
constructor() {
this.parser = new HNParser();
if (!isSupportedSite()) {
console.log('Site not supported');
return;
}

this.parser = getParser();
this.sidebarVisible = false;
this.threadSummaries = new Map();
this.settings = null;
Expand Down
55 changes: 55 additions & 0 deletions src/content/parsers/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export class BaseParser {
constructor() {
if (this.constructor === BaseParser) {
throw new Error('Cannot instantiate abstract BaseParser');
}
}

// Check if current page is a discussion
isDiscussionPage() {
throw new Error('Method isDiscussionPage() must be implemented');
}

// Get page title
getTitle() {
throw new Error('Method getTitle() must be implemented');
}

// Get page content including main post and metadata
getPageContent() {
throw new Error('Method getPageContent() must be implemented');
}

// Parse a comment thread starting from the given element
parseCommentThread(commentElement) {
throw new Error('Method parseCommentThread() must be implemented');
}

// Get all top-level comments
getTopLevelComments() {
throw new Error('Method getTopLevelComments() must be implemented');
}

// Scroll to specific comment
scrollToComment(commentId) {
throw new Error('Method scrollToComment() must be implemented');
}

// Highlight specific comment
highlightComment(commentElement) {
if (!commentElement) return;

// Remove existing highlights
document.querySelectorAll('.comment-highlight').forEach(el =>
el.classList.remove('comment-highlight')
);

// Add highlight to target comment
commentElement.classList.add('comment-highlight');
}

// Get comment indentation level
getCommentIndent(commentElement) {
throw new Error('Method getCommentIndent() must be implemented');
}
}
Loading

0 comments on commit ca868aa

Please sign in to comment.