Skip to content

Commit fb5d9de

Browse files
move hideAd to startAd.js
1 parent eb97e60 commit fb5d9de

File tree

15 files changed

+43
-29
lines changed

15 files changed

+43
-29
lines changed

src/components/settingsPage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import helpers from "utils/helpers";
1111
import Checkbox from "./checkbox";
1212
import Page from "./page";
1313
import searchBar from "./searchbar";
14+
import { hideAd } from "./startAd.js";
1415

1516
/**
1617
* @typedef {object} SettingsPage
@@ -99,7 +100,7 @@ export default function settingsPage(
99100
/** DISCLAIMER: do not assign hideSearchBar directly because it can change */
100101
$page.ondisconnect = () => hideSearchBar();
101102
$page.onhide = () => {
102-
helpers.hideAd();
103+
hideAd();
103104
actionStack.remove(title);
104105
};
105106

src/lib/removeAds.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import purchaseListener from "handlers/purchase";
22
import helpers from "utils/helpers";
3+
import { hideAd } from "./startAd.js";
34

45
/**
56
* Remove ads after purchase
@@ -25,7 +26,7 @@ export default function removeAds() {
2526

2627
function onpurchase() {
2728
resolve(null);
28-
helpers.hideAd(true);
29+
hideAd(true);
2930
localStorage.setItem("acode_pro", "true");
3031
window.IS_FREE_VERSION = false;
3132
toast(strings["thank you :)"]);

src/lib/startAd.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,20 @@ export default async function startAd() {
5757
window.iad = interstitial;
5858
window.adRewardedUnitId = adUnitIdRewarded;
5959
}
60+
61+
/**
62+
* Hides the ad
63+
* @param {Boolean} [force=false]
64+
*/
65+
export function hideAd(force = false) {
66+
const { ad } = window;
67+
if (ad?.active) {
68+
const $pages = tag.getAll(".page-replacement");
69+
const hide = $pages.length === 1;
70+
71+
if (force || hide) {
72+
ad.active = false;
73+
ad.hide();
74+
}
75+
}
76+
}

src/pages/about/about.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Reactive from "html-tag-js/reactive";
55
import actionStack from "lib/actionStack";
66
import constants from "lib/constants";
77
import helpers from "utils/helpers";
8+
import { hideAd } from "./startAd.js";
89

910
export default function AboutInclude() {
1011
const $page = Page(strings.about.capitalize());
@@ -115,7 +116,7 @@ export default function AboutInclude() {
115116

116117
$page.onhide = function () {
117118
actionStack.remove("about");
118-
helpers.hideAd();
119+
hideAd();
119120
};
120121

121122
app.append($page);

src/pages/adRewards/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import actionStack from "lib/actionStack";
66
import adRewards from "lib/adRewards";
77
import removeAds from "lib/removeAds";
88
import helpers from "utils/helpers";
9+
import { hideAd } from "./startAd.js";
910

1011
let $rewardPage = null;
1112

@@ -179,7 +180,7 @@ export default function openAdRewardsPage() {
179180
action: $page.hide,
180181
});
181182

182-
helpers.hideAd(true);
183+
hideAd(true);
183184
render();
184185
app.append($page);
185186
$rewardPage = $page;

src/pages/changelog/changelog.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import markdownIt from "markdown-it";
1010
import markdownItFootnote from "markdown-it-footnote";
1111
import markdownItTaskLists from "markdown-it-task-lists";
1212
import helpers from "utils/helpers";
13+
import { hideAd } from "./startAd.js";
1314

1415
export default async function Changelog() {
1516
const GITHUB_API_URL =
@@ -73,7 +74,7 @@ export default async function Changelog() {
7374

7475
$page.onhide = function () {
7576
actionStack.remove("changelog");
76-
helpers.hideAd();
77+
hideAd();
7778
};
7879

7980
actionStack.push({

src/pages/customTheme/customTheme.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ThemeBuilder from "theme/builder";
1010
import themes from "theme/list";
1111
import { isValidColor } from "utils/color/regex";
1212
import helpers from "utils/helpers";
13+
import { hideAd } from "./startAd.js";
1314

1415
export default function CustomThemeInclude() {
1516
const theme = themes.get("custom");
@@ -34,7 +35,7 @@ export default function CustomThemeInclude() {
3435

3536
$page.onhide = () => {
3637
actionStack.remove("custom-theme");
37-
helpers.hideAd();
38+
hideAd();
3839
};
3940

4041
$page.addEventListener("click", handleClick);

src/pages/fileBrowser/fileBrowser.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import _addMenuHome from "./add-menu-home.hbs";
3131
import _template from "./fileBrowser.hbs";
3232
import _list from "./list.hbs";
3333
import util from "./util";
34+
import { hideAd } from "./startAd.js";
3435

3536
/**
3637
* @typedef {{url: String, name: String}} Location
@@ -511,7 +512,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
511512

512513
$page.onhide = function () {
513514
hideSearchBar();
514-
helpers.hideAd();
515+
hideAd();
515516
actionStack.clearFromMark();
516517
actionStack.remove("filebrowser");
517518
$content.removeEventListener("click", handleClick);

src/pages/fontManager/fontManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import appSettings from "lib/settings";
1515
import FileBrowser from "pages/fileBrowser";
1616
import helpers from "utils/helpers";
1717
import Url from "utils/Url";
18+
import { hideAd } from "./startAd.js";
1819

1920
export default function fontManager() {
2021
const defaultFont = "Roboto Mono";
@@ -32,7 +33,7 @@ export default function fontManager() {
3233
});
3334

3435
$page.onhide = () => {
35-
helpers.hideAd();
36+
hideAd();
3637
actionStack.remove("fontManager");
3738
};
3839

src/pages/plugin/plugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { highlightCodeBlock, initHighlighting } from "utils/codeHighlight";
1919
import helpers from "utils/helpers";
2020
import Url from "utils/Url";
2121
import view from "./plugin.view.js";
22+
import { hideAd } from "./startAd.js";
2223

2324
let $lastPluginPage;
2425

@@ -61,7 +62,7 @@ export default async function PluginInclude(
6162
});
6263

6364
$page.onhide = function () {
64-
helpers.hideAd();
65+
hideAd();
6566
actionStack.remove("plugin");
6667
loader.removeTitleLoader();
6768
cancelled = true;

0 commit comments

Comments
 (0)