Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaumaus committed Jan 27, 2022
1 parent cbdc4d3 commit 6350b1d
Show file tree
Hide file tree
Showing 14 changed files with 461 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: andriir
106 changes: 106 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
# dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
package-lock.json
pnpm-lock.yaml
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
# hunt-adblock
Detect adblocks
# Adblock Hunter 🔫
This library enables you to determine whether a user is using an ad blocker or not.

## Installation
```bash
$ npm install --save adblock-hunter
```

## Examples
```javascript
import { isAdblocking } from 'adblock-hunter'

isAdblocking().then((adblocking) => {
if (adblocking) {
// an adblocker is present
}
})

// or

const someFunction = async () => {
// some of your code here...

const adblocking = await isAdblocking()
if (adblocking) {
// an adblocker is present
}
}
```

## API
### `isAdblocking`
`isAdblocking` is a function which makes a call to Google Ads URL and checks wheater the request succeeds (user has no adblock) or not (the adblock is present).\
The returned value is `Promise<Boolean>`.

## Donate
You can support the project by donating me at https://ko-fi.com/andriir
85 changes: 85 additions & 0 deletions dist/adblock-hunter.cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}

function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}

var adURL = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
/**
* Check if AdBlocker is present in user's browser
* @return Promise<Boolean>
*/
var isAblocking = function () { return __awaiter(void 0, void 0, void 0, function () {
var enabled;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
enabled = false;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, fetch(adURL)];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3:
_a.sent();
enabled = true;
return [3 /*break*/, 4];
case 4: return [2 /*return*/, enabled];
}
});
}); };

exports.isAblocking = isAblocking;
81 changes: 81 additions & 0 deletions dist/adblock-hunter.es5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}

function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}

var adURL = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
/**
* Check if AdBlocker is present in user's browser
* @return Promise<Boolean>
*/
var isAblocking = function () { return __awaiter(void 0, void 0, void 0, function () {
var enabled;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
enabled = false;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, fetch(adURL)];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3:
_a.sent();
enabled = true;
return [3 /*break*/, 4];
case 4: return [2 /*return*/, enabled];
}
});
}); };

export { isAblocking };
1 change: 1 addition & 0 deletions dist/adblock-hunter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions dist/esnext/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Check if AdBlocker is present in user's browser
* @return Promise<Boolean>
*/
declare const isAblocking: () => Promise<boolean>;
export { isAblocking, };
17 changes: 17 additions & 0 deletions dist/esnext/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/esnext/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "adblock-hunter",
"version": "1.0.0",
"description": "Detect adblock usage with ease",
"main": "dist/adblock-hunter.cjs.js",
"module": "dist/adblock-hunter.es5.js",
"browser": "dist/adblock-hunter.js",
"esnext": "dist/esnext/index.js",
"typings": "dist/esnext/index.d.ts",
"scripts": {
"prebuild": "rimraf dist",
"prepublish": "npm run build",
"build": "rollup -c && tsc -p tsconfig.esnext.json",
"start": "rollup -c -w",
"tsc": "tsc -p tsconfig.esnext.json"
},
"funding": {
"type": "individual",
"url": "https://ko-fi.com/andriir"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Blaumaus/adblock-hunter.git"
},
"author": "Andrii R. <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/Blaumaus/adblock-hunter/issues"
},
"homepage": "https://github.com/Blaumaus/adblock-hunter",
"devDependencies": {
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.0.6",
"rimraf": "^3.0.2",
"rollup": "^2.61.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-typescript2": "^0.30.0",
"rollup-plugin-uglify": "^6.0.4",
"tslib": "^2.3.1",
"typescript": "^4.5.3"
}
}
Loading

0 comments on commit 6350b1d

Please sign in to comment.