| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ import fetchJson from 'lib/fetch-json'; | |||
| 9 | 9 | import mediator from 'lib/mediator'; | |
| 10 | 10 | import reportError from 'lib/report-error'; | |
| 11 | 11 | import { spaceFiller } from 'common/modules/article/space-filler'; | |
| 12 | + import { commercialFeatures } from 'common/modules/commercial/commercial-features'; | ||
| 12 | 13 | ||
| 13 | 14 | const richLinkTag = ({ href }: { href: string }): string => | |
| 14 | 15 | `<aside class=" element element-rich-link element-rich-link--tag | |
@@ -19,6 +20,19 @@ const richLinkTag = ({ href }: { href: string }): string => | |||
| 19 | 20 | <p><a href="${href}">${href}</a></p> | |
| 20 | 21 | </aside>`; | |
| 21 | 22 | ||
| 23 | + const hideIfPaidForAndAdFree = (el: Element): Promise<void> => { | ||
| 24 | + if (!commercialFeatures.adFree) { | ||
| 25 | + return Promise.resolve(); | ||
| 26 | + } | ||
| 27 | + return fastdom.write(() => { | ||
| 28 | + [...el.children] | ||
| 29 | + .filter(child => | ||
| 30 | + child.classList.toString().includes('rich-link--paidfor') | ||
| 31 | + ) | ||
| 32 | + .forEach(child => child.classList.add('u-h')); | ||
| 33 | + }); | ||
| 34 | + }; | ||
| 35 | + | ||
| 22 | 36 | const elementIsBelowViewport = (el: Element): Promise<boolean> => | |
| 23 | 37 | fastdom.read(() => { | |
| 24 | 38 | const rect = el.getBoundingClientRect(); | |
@@ -71,6 +85,7 @@ const upgradeRichLink = (el: Element): Promise<void> => { | |||
| 71 | 85 | } else { | |
| 72 | 86 | doUpgrade(el, resp); | |
| 73 | 87 | } | |
| 88 | + hideIfPaidForAndAdFree(el); // only identifiable as paid-for when upgraded | ||
| 74 | 89 | } | |
| 75 | 90 | }) | |
| 76 | 91 | .catch(ex => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ import { | |||
| 5 | 5 | richLinkTag, | |
| 6 | 6 | insertTagRichLink, | |
| 7 | 7 | } from 'common/modules/article/rich-links'; | |
| 8 | + import { commercialFeatures } from 'common/modules/commercial/commercial-features'; | ||
| 8 | 9 | ||
| 9 | 10 | let mockParas: ?NodeList<HTMLParagraphElement>; | |
| 10 | 11 | ||
@@ -21,6 +22,9 @@ jest.mock('common/modules/article/space-filler', () => ({ | |||
| 21 | 22 | }), | |
| 22 | 23 | }, | |
| 23 | 24 | })); | |
| 25 | + jest.mock('common/modules/commercial/commercial-features', () => ({ | ||
| 26 | + commercialFeatures() {}, | ||
| 27 | + })); | ||
| 24 | 28 | ||
| 25 | 29 | describe('rich-links', () => { | |
| 26 | 30 | const getRichLinkElements = (): HTMLCollection<HTMLElement> => | |
@@ -39,6 +43,8 @@ describe('rich-links', () => { | |||
| 39 | 43 | showRelatedContent: true, | |
| 40 | 44 | shouldHideAdverts: false, | |
| 41 | 45 | }; | |
| 46 | + | ||
| 47 | + commercialFeatures.adFree = false; | ||
| 42 | 48 | }); | |
| 43 | 49 | ||
| 44 | 50 | afterEach(() => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments