Skip to content

Commit 7287955

Browse files
authored
Merge pull request #9 from aruniverse/fetch-req
add a network req as a fail safe
2 parents bed3cb9 + c270248 commit 7287955

30 files changed

+11758
-433
lines changed

.github/workflows/publish.yml

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,11 @@ on:
55
types: [created]
66

77
jobs:
8-
# build:
9-
# runs-on: ubuntu-latest
10-
# steps:
11-
# - uses: actions/checkout@v2
12-
# - uses: actions/setup-node@v1
13-
# with:
14-
# node-version: 12
15-
# - run: yarn
16-
# - run: yarn build
17-
188
publish-npm:
19-
# needs: build
209
runs-on: ubuntu-latest
10+
defaults:
11+
run:
12+
working-directory: ./adblock-detect-react
2113
steps:
2214
- uses: actions/checkout@v2
2315
- uses: actions/setup-node@v1
@@ -29,18 +21,4 @@ jobs:
2921
- run: yarn publish --access public
3022
env:
3123
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
32-
# publish-gpr:
33-
# # needs: build
34-
# runs-on: ubuntu-latest
35-
# steps:
36-
# - uses: actions/checkout@v2
37-
# - uses: actions/setup-node@v1
38-
# with:
39-
# node-version: 12
40-
# registry-url: https://npm.pkg.github.com/
41-
# scope: "@aruniverse"
42-
# # - run: npm ci
43-
# - run: yarn
44-
# - run: yarn publish
45-
# env:
46-
# NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
24+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ node_modules/
22
cjs/
33
esm/
44
*.tgz
5+
6+
build/
7+
*.eslintcache
File renamed without changes.
File renamed without changes.
File renamed without changes.

adblock-detect-react/package.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "adblock-detect-react",
3+
"version": "1.0.3",
4+
"description": "Provides utilities to check if ad block is enabled on a page via both a React hook and a wrapper component.",
5+
"main": "cjs/index.js",
6+
"module": "esm/index.js",
7+
"types": "cjs/index.d.ts",
8+
"author": "https://github.com/aruniverse",
9+
"license": "MIT",
10+
"repository": {
11+
"url": "https://github.com/aruniverse/adblock-detect-react",
12+
"type": "git"
13+
},
14+
"files": [
15+
"cjs/**/*",
16+
"esm/**/*"
17+
],
18+
"keywords": [
19+
"react",
20+
"hooks",
21+
"adblock",
22+
"ad",
23+
"block",
24+
"detect"
25+
],
26+
"scripts": {
27+
"build": "concurrently yarn:build:cjs yarn:build:esm",
28+
"build:cjs": "tsc -p cjs.tsconfig.json",
29+
"build:esm": "tsc -p esm.tsconfig.json",
30+
"clean": "rimraf cjs esm",
31+
"rebuild": "yarn clean && yarn build",
32+
"publish:local": "yarn rebuild && yarn pack"
33+
},
34+
"devDependencies": {
35+
"@types/react": "^16.9.43",
36+
"@types/react-dom": "^16.9.8",
37+
"concurrently": "^5.2.0",
38+
"react": "16.13.1",
39+
"react-dom": "16.13.1",
40+
"rimraf": "^3.0.2",
41+
"typescript": "^3.7.2"
42+
},
43+
"peerDependencies": {
44+
"react": "^16.8.0",
45+
"react-dom": "^16.8.0"
46+
}
47+
}
File renamed without changes.

src/hooks/useDetectAdBlock.ts renamed to adblock-detect-react/src/hooks/useDetectAdBlock.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,18 @@ export const useDetectAdBlock = () => {
4242
};
4343
}, []);
4444

45+
useEffect(() => {
46+
// fail safe to double check
47+
if (!adBlockDetected) {
48+
fetch("pagead/js/adsbygoogle.js", {
49+
method: "HEAD",
50+
mode: "no-cors",
51+
cache: "no-store",
52+
}).catch(() => {
53+
setAdBlockDetected(true);
54+
});
55+
}
56+
}, []);
57+
4558
return adBlockDetected;
4659
};
File renamed without changes.

package.json

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,11 @@
11
{
2-
"name": "adblock-detect-react",
3-
"version": "1.0.2",
4-
"description": "Provides utilities to check if ad block is enabled on a page via both a React hook and a wrapper component.",
5-
"main": "cjs/index.js",
6-
"module": "esm/index.js",
7-
"types": "cjs/index.d.ts",
8-
"author": "https://github.com/aruniverse",
9-
"license": "MIT",
10-
"repository": {
11-
"url": "https://github.com/aruniverse/adblock-detect-react",
12-
"type": "git"
13-
},
14-
"files": [
15-
"cjs/**/*",
16-
"esm/**/*"
17-
],
18-
"keywords": [
19-
"react",
20-
"hooks",
21-
"adblock",
22-
"ad",
23-
"block",
24-
"detect"
25-
],
2+
"name": "adblock-monorepo",
3+
"private": "true",
264
"scripts": {
27-
"build": "concurrently yarn:build:cjs yarn:build:esm",
28-
"build:cjs": "tsc -p cjs.tsconfig.json",
29-
"build:esm": "tsc -p esm.tsconfig.json",
30-
"clean": "rimraf cjs esm",
31-
"rebuild": "yarn clean && yarn build",
32-
"publish:local": "yarn rebuild && yarn pack"
33-
},
34-
"devDependencies": {
35-
"@types/react": "^16.9.43",
36-
"@types/react-dom": "^16.9.8",
37-
"concurrently": "^5.2.0",
38-
"react": "16.13.1",
39-
"react-dom": "16.13.1",
40-
"rimraf": "^3.0.2",
41-
"typescript": "^3.7.2"
5+
"build": ""
426
},
43-
"peerDependencies": {
44-
"react": "^16.8.0",
45-
"react-dom": "^16.8.0"
46-
}
7+
"workspaces": [
8+
"adblock-detect-react/**",
9+
"test-app/**"
10+
]
4711
}

0 commit comments

Comments
 (0)