Upload files to 'tool/block_cloudflare_requests_pm/src'

This commit is contained in:
Domesday 2021-04-14 09:25:45 +00:00
parent 3284925b1c
commit b2f934d6b5
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,35 @@
const Cc = Components.classes,
Ci = Components.interfaces;
function ignoreCF(h) {
return /(cloudflare(\-(dns|free|ipfs|quic)|(support|warp)))\.com$/.test(h) ? true : false;
}
let knownCF = [];
let CFBlocking = {
observe: function (subject, topic, data) {
let httpChl = subject.QueryInterface(Ci.nsIHttpChannel),
reqURL = subject.URI.spec;
if (reqURL.indexOf('http') === 0 && reqURL.indexOf('.archive.org/') === -1) {
let hostN = (new URL(reqURL)).hostname;
if (topic == 'http-on-modify-request') {
if (knownCF.includes(hostN)) {
httpChl.cancel(Cr.NS_BINDING_ABORTED);
}
}
if (topic == 'http-on-examine-response') {
let rayid = '';
try {
rayid = httpChl.getResponseHeader('cf-ray');
} catch (e) {}
if (rayid.length > 3) {
if (!knownCF.includes(hostN) && !ignoreCF(hostN)) {
knownCF.push(hostN);
}
httpChl.cancel(Cr.NS_BINDING_ABORTED);
}
}
}
}
};
let OBS = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
OBS.addObserver(CFBlocking, 'http-on-modify-request', false);
OBS.addObserver(CFBlocking, 'http-on-examine-response', false);

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://cfblocker/content/header.js"></script>
</overlay>