Skip to content

Commit

Permalink
add detectAdblock helper
Browse files Browse the repository at this point in the history
  • Loading branch information
driedpampas authored Oct 14, 2023
1 parent d9256bd commit c29eee3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 55 deletions.
57 changes: 2 additions & 55 deletions src/bypasses/letsboost.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class Letsboost extends BypassDefinition {
}

execute() {
detectAdblock()
this.helpers.detectAdblock()
.then((adblockResults) => {
if (!adblockResults.usingAdblock) {
const jsonDat = JSON.parse(window.stepDat);
Expand All @@ -18,60 +18,7 @@ export default class Letsboost extends BypassDefinition {
}
});
}

detectAdblock() {
const adblockTests = {
// https://github.com/uBlockOrigin/uAssets/blob/master/filters/filters-2022.txt
uBlockOrigin: {
url: 'https://incolumitas.com/data/yzfdmoan.js',
id: '837jlaBksSjd9jh',
},
// https://github.com/easylist/easylist/blob/master/easylist/easylist_general_block.txt
adblockPlus: {
url: 'https://incolumitas.com/data/utep_ad.js',
id: 'hfuBadsf3hFAk',
},
};

function canLoadRemoteScript(obj) {
return new Promise(function (resolve, reject) {
var script = document.createElement('script');

script.onload = function () {
if (document.getElementById(obj.id)) {
resolve(false);
} else {
resolve(true);
}
}

script.onerror = function () {
resolve(true);
}

script.src = obj.url;
document.body.appendChild(script);
});
}

return new Promise(function (resolve, reject) {
let promises = [
canLoadRemoteScript(adblockTests.uBlockOrigin),
canLoadRemoteScript(adblockTests.adblockPlus),
];

Promise.all(promises).then((results) => {
resolve({
uBlockOrigin: results[0],
adblockPlus: results[1],
usingAdblock: (results[0] === true) || (results[1] === true),
});
}).catch((err) => {
reject(err);
});
});
}



}

Expand Down
54 changes: 54 additions & 0 deletions src/helpers/detectadblock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export function detectAdblock() {
const adblockTests = {
// https://github.com/uBlockOrigin/uAssets/blob/master/filters/filters-2022.txt
uBlockOrigin: {
url: 'https://incolumitas.com/data/yzfdmoan.js',
id: '837jlaBksSjd9jh',
},
// https://github.com/easylist/easylist/blob/master/easylist/easylist_general_block.txt
adblockPlus: {
url: 'https://incolumitas.com/data/utep_ad.js',
id: 'hfuBadsf3hFAk',
},
};

function canLoadRemoteScript(obj) {
return new Promise(function (resolve, reject) {
var script = document.createElement('script');

script.onload = function () {
if (document.getElementById(obj.id)) {
resolve(false);
} else {
resolve(true);
}
}

script.onerror = function () {
resolve(true);
}

script.src = obj.url;
document.body.appendChild(script);
});
}

return new Promise(function (resolve, reject) {
let promises = [
canLoadRemoteScript(adblockTests.uBlockOrigin),
canLoadRemoteScript(adblockTests.adblockPlus),
];

Promise.all(promises).then((results) => {
resolve({
uBlockOrigin: results[0],
adblockPlus: results[1],
usingAdblock: (results[0] === true) || (results[1] === true),
});
}).catch((err) => {
reject(err);
});
});
}

export default detectAdblock;
3 changes: 3 additions & 0 deletions src/helpers/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,11 @@ export async function bypassRequests(execution_method) {
};
}

import { detectAdblock } from './detectadblock.js';

export default {
insertInfoBox,
detectAdblock,
ensureDomLoaded,
awaitElement,
ffclipboard,
Expand Down

0 comments on commit c29eee3

Please sign in to comment.