-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support eradication of Hacker News (news.ycombinator.com) (#97)
- Loading branch information
Showing
5 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters