Initial commit
This commit is contained in:
commit
dd95ae2fe7
|
@ -0,0 +1 @@
|
||||||
|
web-ext-artifacts
|
|
@ -0,0 +1,64 @@
|
||||||
|
const cfRange = [
|
||||||
|
'173.245.48.0/20',
|
||||||
|
'103.21.244.0/22',
|
||||||
|
'103.22.200.0/22',
|
||||||
|
'103.31.4.0/22',
|
||||||
|
'141.101.64.0/18',
|
||||||
|
'108.162.192.0/18',
|
||||||
|
'190.93.240.0/20',
|
||||||
|
'188.114.96.0/20',
|
||||||
|
'197.234.240.0/22',
|
||||||
|
'198.41.128.0/17',
|
||||||
|
'162.158.0.0/15',
|
||||||
|
'104.16.0.0/13',
|
||||||
|
'104.24.0.0/14',
|
||||||
|
'172.64.0.0/13',
|
||||||
|
'131.0.72.0/22'
|
||||||
|
];
|
||||||
|
const cfRange6 = [
|
||||||
|
'2400:cb00::/32',
|
||||||
|
'2606:4700::/32',
|
||||||
|
'2803:f800::/32',
|
||||||
|
'2405:b500::/32',
|
||||||
|
'2405:8100::/32',
|
||||||
|
'2a06:98c0::/29',
|
||||||
|
'2c0f:f248::/32'
|
||||||
|
];
|
||||||
|
// TODO: implement IPv6 check
|
||||||
|
function ip42int(address) {
|
||||||
|
let _4 = address.split('.');
|
||||||
|
let rtn = 0;
|
||||||
|
rtn += Number(_4[0]) * 0x100**3;
|
||||||
|
rtn += Number(_4[1]) * 0x100**2;
|
||||||
|
rtn += Number(_4[2]) * 0x100;
|
||||||
|
rtn += Number(_4[3]);
|
||||||
|
return rtn;
|
||||||
|
}
|
||||||
|
function calc4range(range) {
|
||||||
|
let base = range.split('/')[0];
|
||||||
|
let prefix = Number(range.split('/')[1]);
|
||||||
|
let hostN = 2 ** (32-prefix);
|
||||||
|
let hostMin = ip42int(base);
|
||||||
|
hostMin -= hostMin % hostN--;
|
||||||
|
let hostMax = hostMin + hostN;
|
||||||
|
return [hostMin, hostMax];
|
||||||
|
}
|
||||||
|
function in_4range(range, address) {
|
||||||
|
range = calc4range(range);
|
||||||
|
address = ip42int(address);
|
||||||
|
return address >= range[0] && address <= range[1];
|
||||||
|
}
|
||||||
|
function is_cloudfucked(address) {
|
||||||
|
return cfRange.some(range => in_4range(range, address));
|
||||||
|
}
|
||||||
|
browser.runtime.onConnect.addListener(function(port) {
|
||||||
|
port.onMessage.addListener(async function(data) {
|
||||||
|
console.log(`testing ${data.hostname}`);
|
||||||
|
let result = await browser.dns.resolve(data.hostname, ['disable_ipv6']);
|
||||||
|
let cloudfucked = result.addresses.some(ip => is_cloudfucked(ip));
|
||||||
|
port.postMessage({
|
||||||
|
"hostname": data.hostname,
|
||||||
|
"cloudfucked": cloudfucked
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,115 @@
|
||||||
|
const gatekeepers = {
|
||||||
|
// "here-goes-hostname-of-your-local-searx-instance": "searx",
|
||||||
|
"html.duckduckgo.com": "duckduckgo"
|
||||||
|
};
|
||||||
|
function prepare_searx(hosts, port) {
|
||||||
|
port.onMessage.addListener(function(data) {
|
||||||
|
hosts[data.hostname].cloudfucked = data.cloudfucked;
|
||||||
|
hosts[data.hostname].links.forEach(link => {
|
||||||
|
if (!link.querySelector('.cloudfuck_market')) {
|
||||||
|
let market = document.createElement('img');
|
||||||
|
market.classList.add('cloudfuck_market');
|
||||||
|
market.setAttribute('data-test', data.cloudfucked);
|
||||||
|
if (data.cloudfucked) {
|
||||||
|
market.alt = 'cloudflare';
|
||||||
|
market.src = browser.runtime.getURL('images/pure-evil.png');
|
||||||
|
market.style.height = '1em';
|
||||||
|
market.style.marginRight = '0.5em';
|
||||||
|
}
|
||||||
|
link.prepend(market);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
function getPages() {
|
||||||
|
return document.querySelectorAll('#main_results hr').length + 1;
|
||||||
|
}
|
||||||
|
let pages = getPages();
|
||||||
|
parse_searx(hosts, port);
|
||||||
|
addEventListener('scroll', function() {
|
||||||
|
if (getPages() > pages) {
|
||||||
|
parse_searx(hosts, port);
|
||||||
|
pages = getPages();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function parse_searx(hosts, port) {
|
||||||
|
Array.from(document.querySelectorAll('.result-default'))
|
||||||
|
.forEach(function(el) {
|
||||||
|
let link = el.querySelector('a');
|
||||||
|
let hostname = new URL(link.href).hostname;
|
||||||
|
if (!(hostname in hosts)) {
|
||||||
|
hosts[hostname] = {
|
||||||
|
"links": [link],
|
||||||
|
"cloudfucked": null
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
hosts[hostname].links.push(link);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (hostname in hosts) {
|
||||||
|
let host = hosts[hostname];
|
||||||
|
if (host.cloudfucked === null) {
|
||||||
|
port.postMessage({
|
||||||
|
"hostname": hostname
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: optimize code for search engines modules
|
||||||
|
function prepare_duckduckgo(hosts, port) {
|
||||||
|
port.onMessage.addListener(function(data) {
|
||||||
|
hosts[data.hostname].cloudfucked = data.cloudfucked;
|
||||||
|
hosts[data.hostname].links.forEach(link => {
|
||||||
|
if (!link.querySelector('.cloudfuck_market')) {
|
||||||
|
let market = document.createElement('img');
|
||||||
|
market.classList.add('cloudfuck_market');
|
||||||
|
market.setAttribute('data-test', data.cloudfucked);
|
||||||
|
if (data.cloudfucked) {
|
||||||
|
market.alt = 'cloudflare';
|
||||||
|
market.src = browser.runtime.getURL('images/pure-evil.png');
|
||||||
|
market.style.height = '1em';
|
||||||
|
market.style.marginRight = '0.5em';
|
||||||
|
}
|
||||||
|
link.prepend(market);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
parse_duckduckgo(hosts, port);
|
||||||
|
}
|
||||||
|
function parse_duckduckgo(hosts, port) {
|
||||||
|
Array.from(document.querySelectorAll('.result__a'))
|
||||||
|
.forEach(function(link) {
|
||||||
|
let hostname = new URL(link.href).hostname;
|
||||||
|
if (!(hostname in hosts)) {
|
||||||
|
hosts[hostname] = {
|
||||||
|
"links": [link],
|
||||||
|
"cloudfucked": null
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
hosts[hostname].links.push(link);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (hostname in hosts) {
|
||||||
|
let host = hosts[hostname];
|
||||||
|
if (host.cloudfucked === null) {
|
||||||
|
port.postMessage({
|
||||||
|
"hostname": hostname
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let hosts = [];
|
||||||
|
let port = browser.runtime.connect();
|
||||||
|
switch (gatekeepers[location.hostname]) {
|
||||||
|
case 'duckduckgo':
|
||||||
|
if (document.body.classList.contains('body--html')) {
|
||||||
|
prepare_duckduckgo(hosts, port);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'searx':
|
||||||
|
if (document.body.classList.contains('results_endpoint')) {
|
||||||
|
prepare_searx(hosts, port);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"manifest_version": 2,
|
||||||
|
"name": "Cloudfuck",
|
||||||
|
"version": "1.0",
|
||||||
|
"description": "Adds an icons next to the search results to indicate pages that uses Cloudflare. Detection is performed by checking a DNS record.",
|
||||||
|
"browser_specific_settings": {
|
||||||
|
"gecko": {
|
||||||
|
"id": "{66abaf41-20a3-48da-bafb-1eef7f75ec57}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"icons": {
|
||||||
|
"64": "images/pure-evil.png"
|
||||||
|
},
|
||||||
|
"permissions": [
|
||||||
|
"dns"
|
||||||
|
],
|
||||||
|
"background": {
|
||||||
|
"scripts": ["background-script.js"]
|
||||||
|
},
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": ["<all_urls>"],
|
||||||
|
"js": ["content-script.js"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"web_accessible_resources": [
|
||||||
|
"images/check.png"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue