Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option to call a callback after engine has run #467

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion Extension/GDPRConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,27 @@ export default class GDPRConfig {
});
});
}
}


static getHandledCallback() {
return new Promise((resolve, reject) => {
chrome.storage.sync.get({
handledCallback: GDPRConfig.defaultHandledCallback
}, (result) => {
resolve(Function(result.handledCallback));
});
});
}

static setHandledCallback(handledCallback) {
return new Promise((resolve, reject) => {
chrome.storage.sync.set({
handledCallback: handledCallback
}, () => {
resolve();
});
});
}

GDPRConfig.defaultValues = {
"A": false,
Expand Down Expand Up @@ -334,3 +354,5 @@ GDPRConfig.defaultDebugFlags = {
GDPRConfig.defaultRuleLists = [
"https://raw.githubusercontent.com/cavi-au/Consent-O-Matic/master/rules-list.json",
];

GDPRConfig.defaultHandledCallback = "";
65 changes: 35 additions & 30 deletions Extension/contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,44 @@ async function contentScriptRunner() {
GDPRConfig.getConsentValues().then((consentTypes)=>{
GDPRConfig.getDebugValues().then((debugValues)=>{
GDPRConfig.getGeneralSettings().then((generalSettings)=>{
if(debugValues.debugLog) {
console.log("FetchedRules:", fetchedRules);
console.log("CustomRules:", customRules);
}

ConsentEngine.debugValues = debugValues;
ConsentEngine.generalSettings = generalSettings;
ConsentEngine.topFrameUrl = url;

chrome.runtime.sendMessage("Searching");
let engine = new ConsentEngine(config, consentTypes, (evt)=>{
let result = {
"handled": evt.handled
};

if(evt.handled) {
result.cmp = evt.cmpName;
result.clicks = evt.clicks;
result.url = url;
GDPRConfig.getHandledCallback().then((handledCallback)=>{
if(debugValues.debugLog) {
console.log("FetchedRules:", fetchedRules);
console.log("CustomRules:", customRules);
}

ConsentEngine.debugValues = debugValues;
ConsentEngine.generalSettings = generalSettings;
ConsentEngine.topFrameUrl = url;

chrome.runtime.sendMessage("Searching");
let engine = new ConsentEngine(config, consentTypes, (evt)=>{
let result = {
"handled": evt.handled
};

chrome.runtime.sendMessage("HandledCMP|"+JSON.stringify(result));
} else if(evt.error) {
chrome.runtime.sendMessage("CMPError");
} else {
chrome.runtime.sendMessage("NothingFound");
if(evt.handled) {
result.cmp = evt.cmpName;
result.clicks = evt.clicks;
result.url = url;

chrome.runtime.sendMessage("HandledCMP|"+JSON.stringify(result));
handledCallback("HandledCMP", result);
} else if(evt.error) {
chrome.runtime.sendMessage("CMPError");
handledCallback("CMPError");
} else {
chrome.runtime.sendMessage("NothingFound");
handledCallback("NothingFound");
}
});

ConsentEngine.singleton = engine;

if(debugValues.debugLog) {
console.log("ConsentEngine loaded " + engine.cmps.length + " of " + Object.keys(config).length + " rules");
}
});

ConsentEngine.singleton = engine;

if(debugValues.debugLog) {
console.log("ConsentEngine loaded " + engine.cmps.length + " of " + Object.keys(config).length + " rules");
}
});
});
});
Expand Down