Skip to content

Commit

Permalink
Merge pull request #3 from nemanjam/feature/new-reddit-design
Browse files Browse the repository at this point in the history
Update to new design
  • Loading branch information
nemanjam authored Apr 17, 2024
2 parents 78dc3e9 + f3e4904 commit 2309255
Show file tree
Hide file tree
Showing 43 changed files with 1,224 additions and 801 deletions.
10 changes: 8 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": [
"@abhijithvijayan/eslint-config/typescript",
// "@abhijithvijayan/eslint-config/typescript", // garbage
"@abhijithvijayan/eslint-config/node",
"@abhijithvijayan/eslint-config/react",
"plugin:no-unsanitized/DOM"
Expand All @@ -25,7 +25,13 @@
}
],
"no-unsanitized/method": "error",
"no-unsanitized/property": "error"
"no-unsanitized/property": "error",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "off",
// "prettier/prettier": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"node/no-unpublished-require": "off"
},
"env": {
"webextensions": true
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Have you ever had to reread entire 200+ comments Reddit thread just to find a fe

Chrome/Firefox extension for easier tracking of new comments on Reddit. Free, open source, privacy aware, runs completely client side without sending any data to any server.

#### Update 2024

Around January 2024. Reddit moved all users to the new design and made version `v0.0.4` outdated. In April 2024. I updated the extension to `1.0.0` to support the new design, and that is the only Reddit design that is supported (available on `www.reddit.com`).

The screenshot bellow shows the new design, demo video shows deprecated design - all features are the same, it shouldn't be a problem.

Version `1.0.0` also includes `Immediately` checkbox to mark the current thread as read manually.

## Screenshots

![Screenshot_1](/docs/screenshots/Screenshot_1.png)
Expand Down Expand Up @@ -41,19 +49,19 @@ Chrome/Firefox extension for easier tracking of new comments on Reddit. Free, op

### Install manually

Go to release page [https://github.com/nemanjam/reddit-unread-comments/releases/tag/v0.0.4](https://github.com/nemanjam/reddit-unread-comments/releases/tag/v0.0.4) and download Firefox `.xpi` or Chrome `.zip`.
Go to release page [https://github.com/nemanjam/reddit-unread-comments/releases/tag/1.0.0](https://github.com/nemanjam/reddit-unread-comments/releases/tag/1.0.0) and download Firefox `.xpi` or Chrome `.zip`.

- **Firefox manual install:**

- In Firefox click `Settings` (three horizontal lines in the top-right corner), click `Extensions tab`, click `Gear` icon right from `Manage Your Extensions`, choose `Install Add-on From File...` from the menu and browse `reddit-unread-comments-v0.0.4-firefox.xpi` file which you can download from the release page.
- In Firefox click `Settings` (three horizontal lines in the top-right corner), click `Extensions tab`, click `Gear` icon right from `Manage Your Extensions`, choose `Install Add-on From File...` from the menu and browse `reddit-unread-comments-1.0.0-firefox.xpi` file which you can download from the release page.

- **Firefox `.xpi`:** [reddit-unread-comments-v0.0.4-firefox.xpi](https://github.com/nemanjam/reddit-unread-comments/releases/download/v0.0.4/reddit-unread-comments-v0.0.4-firefox.xpi)
- **Firefox `.xpi`:** [reddit-unread-comments-1.0.0-firefox.xpi](https://github.com/nemanjam/reddit-unread-comments/releases/download/1.0.0/reddit-unread-comments-1.0.0-firefox.xpi)

- **Chrome manual install:**

- In Chrome navigate to `chrome://extensions/`, switch `Enable developer mode` to true, click `Load unpacked` and browse `reddit-unread-comments-v0.0.4-chrome.zip` file which you can download from the release page.
- In Chrome navigate to `chrome://extensions/`, switch `Enable developer mode` to true, click `Load unpacked` and browse `reddit-unread-comments-1.0.0-chrome.zip` file which you can download from the release page.

- **Chrome `.zip`:** [reddit-unread-comments-v0.0.4-chrome.zip](https://github.com/nemanjam/reddit-unread-comments/releases/download/v0.0.4/reddit-unread-comments-v0.0.4-chrome.zip)
- **Chrome `.zip`:** [reddit-unread-comments-1.0.0-chrome.zip](https://github.com/nemanjam/reddit-unread-comments/releases/download/1.0.0/reddit-unread-comments-1.0.0-chrome.zip)

## Usage

Expand Down
Binary file modified docs/screenshots/Screenshot_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/Screenshot_1_old_Reddit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions docs/work-notes/test-code2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@


const commentId = 't1_kznmxco';

const commentSelector = 'shreddit-comment[thingid^="t1_"]';

const getCommentSelectorById = (commentId) => `shreddit-comment[thingid^="${commentId}"]`;

const getTimestampSelectorById = (commentId) => {
const targetedCommentSelector = getCommentSelectorById(commentId);
// avoid nested comments
const timestampSelector = `${targetedCommentSelector} *:not(${commentSelector}) time:first-child[datetime]`;
return timestampSelector;
};

const timestampSelector = getTimestampSelectorById(commentId);

document.querySelectorAll(timestampSelector);

document.querySelectorAll(
'shreddit-comment[thingid^="t1_kznmxco"] :not(shreddit-comment) time:first-child[datetime]'
);

document.querySelectorAll(
'shreddit-comment[thingid^="t1_kznmxco"] > div[slot="commentMeta"] time'
);


document.querySelectorAll('shreddit-comment[thingid^="t1_kzklld1"]');
document.querySelector(
'shreddit-comment[thingid^="t1_kzklld1"] time:first-child[datetime]'
);

const shadowHost = document.getElementById('shadow-host');
const shadowRoot = shadowHost.getRootNode();
const buttonInsideShadow = shadowRoot.querySelector('button');
buttonInsideShadow.click();


document.querySelector('shreddit-sort-dropdown').click()


document.querySelector('#comment-sort-button').click()


document.querySelectorAll('shreddit-sort-dropdown')



var shadowHost = document.querySelector('shreddit-sort-dropdown');
var buttonInsideShadow = shadowHost.shadowRoot.querySelector('button[id="comment-sort-button"] > span > span');
buttonInsideShadow.textContent

buttonInsideShadow.click();


document.querySelector('button[id="comment-sort-button"]');


document.querySelector('data[value="NEW"]').click()

document.querySelector('#main-content').click()

-------------

var currentElement = document.querySelector('shreddit-comment[thingid^="t1_kz4bckd"]')
var contentElement = currentElement.querySelector('shreddit-comment[thingid^="t1_kz4bckd"] > div[slot="comment"]')
contentElement;



6 changes: 6 additions & 0 deletions docs/work-notes/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,9 @@ git tag -a v0.0.4 -m "Release 0.0.4"
git push all v0.0.4
----------
add mark thread as read button


git checkout -b feature/new-reddit-design

git push -u origin feature/new-reddit-design

32 changes: 32 additions & 0 deletions docs/work-notes/todo2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
break dom into multiple files
remove modal from events
parse exact time from time.datetime iso string
put config vars into single object
mark as read label in popup ui
review delay values
fix sort by new selector
wrapper for querySelector that returns Node or throws, not null
scroll ctrl + space broken
update readme
all exception should be handled in 1-2 chosen levels
everything should throw custom exception classes and log
db wrapper
mark thread as read button, immediately radio
add version label
nested comments, check that only comments content is in viewport

fix chrome manifest errors

// ovde na pocetku nove sesije oznacava prethodnu kao procitanu
const { threadId, updatedAt } = existingThread;
const updatedComments = await updateCommentsSessionCreatedAtForThread(
db,
threadId,
updatedAt
);
comment.sessionCreatedAt = thread.updatedAt

// zapravo meni treba ovo, da oznacim comments mark as rad za current session, sa 2e12
// a to je addComment()
const sessionCreatedAt = currentSessionCreatedAt;
await addComment(db, { threadId, commentId, sessionCreatedAt });
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reddit-unread-comments",
"version": "0.0.4",
"version": "1.0.0",
"description": "Web extension for easier tracking of new comments on Reddit.",
"private": false,
"repository": "https://github.com/nemanjam/reddit-unread-comments",
Expand Down Expand Up @@ -40,8 +40,8 @@
},
"devDependencies": {
"@abhijithvijayan/eslint-config": "2.6.3",
"@abhijithvijayan/eslint-config-airbnb": "^1.0.2",
"@abhijithvijayan/tsconfig": "^1.3.0",
"@abhijithvijayan/eslint-config-airbnb": "1.0.2",
"@abhijithvijayan/tsconfig": "1.3.0",
"@babel/core": "^7.14.3",
"@babel/eslint-parser": "^7.12.16",
"@babel/plugin-proposal-class-properties": "^7.13.0",
Expand Down
7 changes: 7 additions & 0 deletions source/Background/service-worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'emoji-log';
import browser from 'webextension-polyfill';

// for Chrome manifest v3
browser.runtime.onInstalled.addListener((): void => {
console.emoji('🦄', 'extension installed');
});
2 changes: 1 addition & 1 deletion source/manifest-v2-firefox.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Reddit Unread Comments",
"version": "0.0.4",
"version": "1.0.0",

"icons": {
"16": "assets/icons/favicon-16.png",
Expand Down
15 changes: 6 additions & 9 deletions source/manifest-v3-chrome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Reddit Unread Comments",
"version": "0.0.4",
"version": "1.0.0",

"icons": {
"16": "assets/icons/favicon-16.png",
Expand All @@ -13,7 +13,9 @@
"homepage_url": "https://github.com/nemanjam/reddit-unread-comments",
"short_name": "Reddit Unread Comments",

"permissions": ["activeTab", "http://*.reddit.com/*", "https://*.reddit.com/*"],
"permissions": ["activeTab"],

"host_permissions": ["http://*.reddit.com/*", "https://*.reddit.com/*"],

"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self'"
Expand All @@ -24,12 +26,6 @@
"name": "Nemanja Mitic"
},

"browser_specific_settings": {
"gecko": {
"id": "{754FB1AD-CC3B-4756-B6A0-7776F7CA9D17}"
}
},

"__chrome__minimum_chrome_version": "88",
"__opera__minimum_opera_version": "36",

Expand All @@ -53,7 +49,8 @@
},

"background": {
"service_worker": "js/background.bundle.js"
"__firefox__scripts": ["js/background.bundle.js"],
"__chrome|opera|edge__service_worker": "js/bgServiceWorker.bundle.js"
},

"content_scripts": [
Expand Down
2 changes: 1 addition & 1 deletion source/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Reddit Unread Comments",
"version": "0.0.4",
"version": "1.0.0",

"icons": {
"16": "assets/icons/favicon-16.png",
Expand Down
65 changes: 65 additions & 0 deletions source/reddit-comments/constants/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*----------------------------------- My constants ---------------------------------*/

/*---------- url and scroll waiting ---------*/

/** Must reduce number of triggers on scroll */
export const scrollDebounceWait = 1000;

/** Must wait for routing (change page), and load content */
export const urlChangeDebounceWait = 2000;

/*----------- sort by new dropdown ----------*/

/** Wait for new comments to reload. */
export const waitAfterSortByNew = 2000;

/** Wait for sort menu to load. */
export const sortMenuWait = 300;

/*------------------ popup -----------------*/

/** Debounce only slider onChange in form. */
export const formSubmitDebounceWait = 300;

export const calcHighlightOnTimeDebounceWait = 300;

/** Refetch every interval. */
export const highlightedCommentsCountInterval = 1000;

export const markAllAsReadDbAndDomWait = 500;

/*--------------- highlighting --------------*/

/** In highlight by read mode, delay to mark as read and un-highlight comments. */
export const markAsReadDelay = 5 * 1000;

/** Increase comment height by 100px. */
export const commentHeightHeadroom = 100;

/*------------- highlight classes ------------*/

export const highlightedCommentClass = 'ruc-highlight-comment';
export const highlightedCommentReadClass = 'ruc-highlight-comment-read';
/** Both read and unread. Don't use.*/
export const allHighlightedCommentsSelector = `.${highlightedCommentClass}, .${highlightedCommentReadClass}`;

export const highlightedCommentByDateClass = 'ruc-highlight-comment-by-date';

/*------------------ datetime -----------------*/

/** Offset in seconds to fix Date comparison 1hr > 1hr and prevent flicker. */
export const dateCorrectionOffset = 30 as const;

/*------------------ database -----------------*/

export const databaseName = 'reddit-unread-comments-db';

/** 2 * 10**12 */
export const currentSessionCreatedAt = 2e12 as const;

/*--------------- database limits --------------*/

/** Start deleting at. */
export const dbSizeLimit: number = 1 * 1024 * 1024; // 1 MB limit
/** Bring to this size. */
export const dbTargetSize: number = 0.5 * 1024 * 1024; // 0.5 MB target size
57 changes: 57 additions & 0 deletions source/reddit-comments/constants/selectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// selectors, easier to select children than parents

/*------------------ url regex -----------------*/

export const redditThreadUrlRegex = /https?:\/\/www\.?reddit\.com\/r\/\w+\/comments\/.+/;
export const redditUrlRegex = /https?:\/\/www\.?reddit\.com.*/;

/*------------------ comment -----------------*/

export const commentIdAttribute = 'thingid';
export const commentSelector = 'shreddit-comment[thingid^="t1_"]';
export const commentIdRegexValidate = /^t1_[a-z0-9]+$/;

// comment
export const getCommentSelectorFromId = (commentId: string) =>
`shreddit-comment[thingid^="${commentId}"]`;

// timestamp
export const getTimestampSelectorFromId = (commentId: string) => {
const targetCommentSelector = getCommentSelectorFromId(commentId);

// select direct child element first to exclude nested comments
const timestampSelector = `${targetCommentSelector} > div[slot="commentMeta"] time[datetime]`;
return timestampSelector;
};

// content
export const getContentSelectorFromId = (commentId: string) => {
const targetCommentSelector = getCommentSelectorFromId(commentId);

const contentSelector = `${targetCommentSelector} > div[slot="comment"]`; // used in styles.scss too
return contentSelector;
};

/*----------------- thread ----------------*/

export const threadPostSelector = 'shreddit-post[id^="t3_"]';
export const threadPostIdRegexReplace = /^t3_/; // Only to get url id from element.id
export const threadPostIdRegexValidate = /^t3_[a-z0-9]+$/;

/*----------------- header ----------------*/

export const pageHeaderSelector = 'reddit-header-large';

/*------------- sort dropdown ------------*/

// shadow host 1
export const sortMenuShadowHostSelector = 'shreddit-sort-dropdown';
// inside shadow dom
export const currentlySelectedItemSelector = '#comment-sort-button > span > span';
export const sortMenuClickSelector = '#comment-sort-button';

// dropdown item new
export const sortByNewMenuItemSelector = 'div[slot="dropdown-items"] span.text-14';

// for blur, outside of shadow dom, simple selector
export const mainContentForBlurSelector = '#main-content';
1 change: 1 addition & 0 deletions source/reddit-comments/database/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const defaultDbValues: SettingsData = {
export const defaultValues: SettingsData = {
...defaultDbValues,
resetDb: '',
markAllAsRead: false,
} as const;

export const addSettings = async (
Expand Down
Loading

0 comments on commit 2309255

Please sign in to comment.