diff --git a/src/eradicate.css b/src/eradicate.css index 51e8009..e87024f 100644 --- a/src/eradicate.css +++ b/src/eradicate.css @@ -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; +} diff --git a/src/intercept.ts b/src/intercept.ts index 006af5e..c839e94 100644 --- a/src/intercept.ts +++ b/src/intercept.ts @@ -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(); @@ -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); diff --git a/src/manifest.json b/src/manifest.json index 7708830..010d63b 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -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", diff --git a/src/sites/hackernews.ts b/src/sites/hackernews.ts new file mode 100644 index 0000000..92a1e39 --- /dev/null +++ b/src/sites/hackernews.ts @@ -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); +} diff --git a/src/sites/index.ts b/src/sites/index.ts index 9b124d3..6abee85 100644 --- a/src/sites/index.ts +++ b/src/sites/index.ts @@ -1,4 +1,4 @@ -export type SiteId = 'facebook' | 'twitter'; +export type SiteId = 'facebook' | 'twitter' | 'hackernews'; export const Sites: Record = { facebook: { label: 'Facebook', @@ -17,6 +17,12 @@ export const Sites: Record = { 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 = {