Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support eradication of Hacker News (news.ycombinator.com) #97

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/eradicate.css
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,8 @@ html:not([data-nfe-enabled='false']) div[data-testid="primaryColumn"] > div:last
pointer-events: none !important;
height: 0 !important;
}

/* Hacker News */
html:not([data-nfe-enabled='false']) table#hnmain .itemlist {
display: none;
}
7 changes: 5 additions & 2 deletions src/intercept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { setupRouteChange } from './lib/route-change';
import * as FbClassic from './sites/fb-classic';
import * as Fb2020 from './sites/fb-2020';
import * as Twitter from './sites/twitter';
import * as HackerNews from './sites/hackernews';
import { createStore, Store } from './store';

const store = createStore();
Expand All @@ -19,9 +20,11 @@ export function eradicate(store: Store) {
Twitter.eradicate(store);
} else if (FbClassic.checkSite()) {
FbClassic.eradicate(store);
} else {
} else if (HackerNews.checkSite()) {
HackerNews.eradicate(store);
} else {
Fb2020.eradicate(store);
}
}
}

setupRouteChange(store);
Expand Down
5 changes: 3 additions & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"http://web.facebook.com/*",
"https://web.facebook.com/*",
"http://twitter.com/*",
"https://twitter.com/*"
],
"https://twitter.com/*",
"https://news.ycombinator.com/*"
],
"browser_action": {
"default_icon": {
"16": "icon16.png",
Expand Down
37 changes: 37 additions & 0 deletions src/sites/hackernews.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import injectUI, { isAlreadyInjected } from '../lib/inject-ui';
import { isEnabled } from '../lib/is-enabled';
import { Store } from '../store';

export function checkSite(): boolean {
return window.location.host.includes('news.ycombinator.com');
}

export function eradicate(store: Store) {
function eradicateRetry() {
const settings = store.getState().settings;
if (settings == null || !isEnabled(settings)) {
return;
}

// Don't do anything if the UI hasn't loaded yet
const feed = document.querySelector(
'table#hnmain tr:nth-of-type(2)'
);

if (feed == null) {
console.log('not ready yet');
return;
}

const container = feed;

// Add News Feed Eradicator quote/info panel
if (container && !isAlreadyInjected()) {
injectUI(container, store);
}
}

// This delay ensures that the elements have been created before we attempt
// to replace them
setInterval(eradicateRetry, 1000);
}
8 changes: 7 additions & 1 deletion src/sites/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type SiteId = 'facebook' | 'twitter';
export type SiteId = 'facebook' | 'twitter' | 'hackernews';
export const Sites: Record<SiteId, Site> = {
facebook: {
label: 'Facebook',
Expand All @@ -17,6 +17,12 @@ export const Sites: Record<SiteId, Site> = {
paths: ['/home', '/compose/tweet'],
origins: ['http://twitter.com/*', 'https://twitter.com/*'],
},
hackernews: {
label: 'Y Combinator News (HN)',
domain: 'news.ycombinator.com',
paths: ['/'],
origins: ['https://news.ycombinator.com/*'],
},
};

export type Site = {
Expand Down