MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
/* Ad Block. */ | /* Ad Block. */ | ||
function detectAdblock(){const | |||
/** | |||
* Author: Nikolai Tschacher | |||
* Updated: 16.08.2022 | |||
* Website: https://incolumitas.com/ | |||
* | |||
* Detect uBlock Origin, Adblock Plus and Ghostery with JavaScript only | |||
* | |||
* Usage: detectAdblock().then((res) => { console.log(res) }); | |||
* | |||
*/ | |||
function detectAdblock() { | |||
const adblockTests = { | |||
// https://github.com/uBlockOrigin/uAssets/blob/master/filters/filters-2022.txt | |||
uBlockOrigin: { | |||
url: 'https://incolumitas.com/data/pp34.js?sv=', | |||
id: '837jlaBksSjd9jh', | |||
}, | |||
// https://github.com/easylist/easylist/blob/master/easylist/easylist_general_block.txt | |||
adblockPlus: { | |||
url: 'https://incolumitas.com/data/neutral.js?&ad_height=', | |||
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], | |||
}); | |||
}).catch((err) => { | |||
reject(err); | |||
}); | |||
}); | |||
} | |||
detectAdblock().then((e=>{alert("It looks like you're using an ad-blocker!\n\nIf you enjoy our content, please support our site by disabling your adblocker. We depend on ad revenue to keep creating quality content for you to enjoy for free. Ads are necessary to keep the platform free for all.\n\nYou can also disable all ads by activating the subscription in your account. In this way, you will be providing serious financial support to our website. For details, please email us.")})); | |||
Revision as of 04:52, 6 October 2022
/* Any JavaScript here will be loaded for all users on every page load. */
importScript('User:Rillke/bigChunkedUpload.js');
/* Ad Block. */
/**
* Author: Nikolai Tschacher
* Updated: 16.08.2022
* Website: https://incolumitas.com/
*
* Detect uBlock Origin, Adblock Plus and Ghostery with JavaScript only
*
* Usage: detectAdblock().then((res) => { console.log(res) });
*
*/
function detectAdblock() {
const adblockTests = {
// https://github.com/uBlockOrigin/uAssets/blob/master/filters/filters-2022.txt
uBlockOrigin: {
url: 'https://incolumitas.com/data/pp34.js?sv=',
id: '837jlaBksSjd9jh',
},
// https://github.com/easylist/easylist/blob/master/easylist/easylist_general_block.txt
adblockPlus: {
url: 'https://incolumitas.com/data/neutral.js?&ad_height=',
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],
});
}).catch((err) => {
reject(err);
});
});
}
detectAdblock().then((e=>{alert("It looks like you're using an ad-blocker!\n\nIf you enjoy our content, please support our site by disabling your adblocker. We depend on ad revenue to keep creating quality content for you to enjoy for free. Ads are necessary to keep the platform free for all.\n\nYou can also disable all ads by activating the subscription in your account. In this way, you will be providing serious financial support to our website. For details, please email us.")}));