You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
363 lines
9.9 KiB
363 lines
9.9 KiB
|
|
/** |
|
* This function give feedback is for debugging purpose |
|
* If the functionthe infalte_adbend_view() is uncommented, the script can infalte the faq without the popup |
|
**/ |
|
|
|
|
|
$(function() { |
|
//inflate_advanced_view(); |
|
}); |
|
|
|
var result ="<p>something went wrong</p>"; |
|
|
|
// This variable is to infalte a dummy |
|
var custom_css_cut = "<style> .dummy{} </style>"; |
|
|
|
// This variable is used to create the summary cards in the faq |
|
var advanced_new_information = ""; |
|
|
|
|
|
|
|
/** |
|
* This function inflates the faq inside the open website |
|
* */ |
|
function inflate_advanced_view(){ |
|
try { |
|
console.log("Try to get Policy"); |
|
$("head").append(custom_css_cut); |
|
$("body").children().wrapAll("<div id='policycontainer'></div>"); |
|
$("#policycontainer").addClass("cut"); |
|
$("<div id='faq-policy-div'></div>").insertAfter("#policycontainer"); |
|
$("#faq-policy-div").append(button_what_are_my_rights); |
|
$("#faq-policy-div").append(card_what_are_my_right); |
|
$("#faq-policy-div").append(button_what_is_technicaldata); |
|
$("#faq-policy-div").append(card_what_is_technicaldata); |
|
$("#faq-policy-div").append(button_what_are_personal_data); |
|
$("#faq-policy-div").append(card_what_are_personal_data); |
|
$("#faq-policy-div").append(button_what_are_anonymised_data); |
|
$("#faq-policy-div").append(card_what_are_anonymised_data); |
|
$("#faq-policy-div").append(button_what_techical_data); |
|
$("#faq-policy-div").append(card_what_techical_data); |
|
$("#faq-policy-div").append(button_what_third); |
|
$("#faq-policy-div").append(card_what_third); |
|
$("#faq-policy-div").append(button_what_are_cookies); |
|
$("#faq-policy-div").append(card_what_are_cookies); |
|
$("#faq-policy-div").append(button_what_which_cookies_are_tracking_me); |
|
$("#faq-policy-div").append(card_what_which_cookies_are_tracking_me); |
|
$("#faq-policy-div").append(button_what_can_i_do_to_refuse); |
|
$("#faq-policy-div").append(card_what_can_i_do_to_refuse); |
|
$("#faq-policy-div").append(button_what_they_know_about_me); |
|
$("#faq-policy-div").append(card_what_they_know_about_me); |
|
$("#faq-policy-div").append(button_what_need_help); |
|
$("#faq-policy-div").append(card_what_need_help); |
|
|
|
$("#faq-policy-div").addClass("disable-inheritance"); |
|
$("#faq-policy-div").addClass("costum-advanced-div"); |
|
$("body").children().wrapAll("<div id='policy-costum-package'></div>"); |
|
$("body").prepend("<div class='costum-app-bar'><h1>FAQ - Privacy and cookies</h1></div>"); |
|
$("#policy-costum-package").addClass("custom-direction-cut"); |
|
|
|
$("#faq-policy-div").children().each(function(){ |
|
console.log($(this)); |
|
}); |
|
init_emails(); |
|
init_cards(); |
|
init_buttons_cards(); |
|
init_buttons_close(); |
|
} catch(e){ |
|
console.log(e); |
|
} |
|
|
|
|
|
} |
|
|
|
/** |
|
* This function inflates the e-mail addresses of a provider into the corresponding Material-Cards |
|
*/ |
|
function init_emails(){ |
|
let tmp = email_address_extraction(); |
|
for(let i = 0; i < tmp.length; i++){ |
|
$("#email-refuse").append("<p>"+tmp[i]+"</p>"); |
|
$("#email-help").append("<p>"+tmp[i]+"</p>"); |
|
$("#email-knew").append("<p>"+tmp[i]+"</p>"); |
|
} |
|
} |
|
|
|
/** |
|
* This function deletes blanks outside of a string |
|
*/ |
|
function handleblanks(text){ |
|
text = text.trim(); |
|
text = text+" "; |
|
return text; |
|
} |
|
|
|
|
|
/** |
|
* This function deletes \t or \n inside a text |
|
*/ |
|
function deleteblanks(text){ |
|
text = text.trim(); |
|
text = text.replace("\\n", ""); |
|
text = text.replace("\\t", ""); |
|
text = text.replace("\n", ""); |
|
text = text.replace("\t", ""); |
|
text = text+""; |
|
return text; |
|
} |
|
|
|
/** |
|
* This function filters a privacy policy |
|
* it returns an array of sections. |
|
*/ |
|
function get_policy_and_inflate_id(){ |
|
try { |
|
let list = []; |
|
let tmp_list = []; |
|
let html = $("body").html(); |
|
let jq_html = $.parseHTML(html); |
|
let cl_id = ""; |
|
$("body *").each(function() { |
|
|
|
let tagname = $(this).prop("tagName"); |
|
if(isUsefull(tagname)){ |
|
if(isTitle(tagname)){ |
|
list.push(tmp_list); |
|
tmp_list = []; |
|
cl_id = $(this).text().replace(/\s+/g, ''); |
|
cl_id = cl_id.replace(/\n/g, ''); |
|
cl_id = cl_id.replace(/\\n/g, ''); |
|
cl_id = cl_id.replace(/\t/g, ''); |
|
cl_id = cl_id.replace(/\\t/g, ''); |
|
cl_id = cl_id.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, ''); |
|
cl_id = cl_id.replace(/[^a-zA-Z ]/g, ''); |
|
cl_id = deleteblanks(cl_id); |
|
cl_id = cl_id.toLowerCase(); |
|
let tmp = $(this).text(); |
|
tmp = tmp.replace(/\n/g, ' '); |
|
tmp = tmp.replace(/\\n/g, ' '); |
|
tmp = tmp.replace(/\t/g, ' '); |
|
tmp = tmp.replace(/\\t/g, ' '); |
|
tmp = tmp.replace(/[&\/\\#+()$~%'":*<>{}]/g, ' '); |
|
tmp = handleblanks(tmp); |
|
console.log("id: "+cl_id); |
|
tmp_list.push({tag: tagname, text: tmp, id:cl_id}); |
|
|
|
$(this).addClass(cl_id); |
|
|
|
} else { |
|
if(isList(tagname)){ |
|
|
|
$(this).addClass(cl_id); |
|
$(this).children().each(function(){ |
|
|
|
let tmp = $(this).text(); |
|
tmp = tmp.replace(/\n/g, ' '); |
|
tmp = tmp.replace(/\\n/g, ' '); |
|
tmp = tmp.replace(/\t/g, ' '); |
|
tmp = tmp.replace(/\\t/g, ' '); |
|
tmp = tmp.replace(/[&\/\\#+()$~%'":*<>{}]/g, ' '); |
|
tmp = handleblanks(tmp); |
|
tmp_list.push({tag: "LI", text: tmp, id: cl_id}); |
|
|
|
}); |
|
|
|
} else { |
|
let tmp = $(this).text(); |
|
tmp = tmp.replace(/\n/g, ' '); |
|
tmp = tmp.replace(/\\n/g, ' '); |
|
tmp = tmp.replace(/\t/g, ' '); |
|
tmp = tmp.replace(/\\t/g, ' '); |
|
tmp = tmp.replace(/[&\/\\#+()$~%'":*?<>{}]/g, ' '); |
|
tmp = handleblanks(tmp); |
|
tmp_list.push({tag: tagname, text: tmp, id: cl_id}); |
|
|
|
$(this).addClass(cl_id); |
|
//console.log($(this).attr("class")); |
|
} |
|
} |
|
} |
|
}); |
|
|
|
|
|
list.shift(); |
|
list.shift(); |
|
console.log("...."); |
|
console.log(list); |
|
console.log("...."); |
|
let back = JSON.stringify(list); |
|
return back; |
|
}catch(e){ |
|
console.log(e); |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
* This function checks if its usefull in our case |
|
* */ |
|
function isUsefull(tagname){ |
|
switch(tagname.toLowerCase()){ |
|
case "p": return true; |
|
break; |
|
case "ul": return true; |
|
break; |
|
case "ol": return true; |
|
break; |
|
case "dl": return true; |
|
break; |
|
case "h1": return true; |
|
break; |
|
case "h2": return true; |
|
break; |
|
case "h3": return true; |
|
break; |
|
case "h4": return true; |
|
break; |
|
case "h5": return true; |
|
break; |
|
case "h6": return true; |
|
break; |
|
default: return false; |
|
|
|
} |
|
} |
|
|
|
/** |
|
* This function checks if a html tag is a list |
|
*/ |
|
function isList(tagname){ |
|
switch(tagname.toLowerCase()){ |
|
case "ul": return true; |
|
break; |
|
case "ol": return true; |
|
break; |
|
case "dl": return true; |
|
break; |
|
default: return false; |
|
} |
|
} |
|
|
|
/** |
|
* This function checks if a html tag is a title |
|
*/ |
|
function isTitle(tagname){ |
|
switch(tagname.toLowerCase()){ |
|
case "h1": return true; |
|
break; |
|
case "h2": return true; |
|
break; |
|
case "h3": return true; |
|
break; |
|
case "h4": return true; |
|
break; |
|
case "h5": return true; |
|
break; |
|
case "h6": return true; |
|
break; |
|
default: return false; |
|
} |
|
} |
|
|
|
/** |
|
* This function is called if the browser listener fired |
|
* This function defines the action of this contentscript |
|
*/ |
|
function listener(which){ |
|
try{ |
|
if(which.func === "get_policy"){ |
|
get_policy(); |
|
return Promise.resolve({html: result}); |
|
} else if(which.func == "get_policy_and_id"){ |
|
let out = get_policy_and_inflate_id(); |
|
console.log("leite folgendes weiter:"); |
|
console.log(out); |
|
return Promise.resolve({html : out}); |
|
} else if(which.func == "create_advanced") { |
|
advanced_new_information = JSON.parse(which.advanced); |
|
create_faq_context(); |
|
console.log("Folgendes wird gespeichert:"); |
|
console.log(advanced_new_information); |
|
} else if(which.func == "check_if_dsgvo"){ |
|
console.log("policy: " + checkpolicy()); |
|
let thirdparties = findThirdpartydomains(); |
|
console.log(thirdparties); |
|
return Promise.resolve({is_dsgvo: checkpolicy(), third: JSON.stringify(thirdparties)}); |
|
} |
|
} catch (e) { |
|
console.log(e); |
|
} |
|
} |
|
|
|
/** |
|
* This function creates the faq . |
|
* In this function is also the scroll function |
|
*/ |
|
function create_faq_context(){ |
|
//debug(); |
|
try { |
|
inflate_advanced_view(); |
|
let list_saved = advanced_new_information[0]; |
|
let list_third = advanced_new_information[1]; |
|
let saved_card = create_summary_saved(list_saved); |
|
let third_card = create_summary_third(list_third); |
|
console.log(saved_card); |
|
$("#result-saved-technical").append(saved_card); |
|
$("#result-saved-third").append(third_card); |
|
|
|
for(let i = 0; i < list_saved.length; i++){ |
|
console.log("hallo von" + list_saved[i].id); |
|
|
|
$("body").find("."+list_saved[i].id+"button").click(function(){ |
|
console.log("clicked: "+"."+list_saved[i].id+"button"); |
|
|
|
|
|
$("body").find(".costum-css-select").each(function(){ |
|
$(this).removeClass("costum-css-select"); |
|
}); |
|
|
|
|
|
$("body").find("."+list_saved[i].id).each(function(){ |
|
$(this).addClass("costum-css-select"); |
|
}); |
|
|
|
let jq_obj = $("body").find("."+list_saved[i].id).first().offset().top; |
|
let height = $("body").find("."+list_saved[i].id).first().height() / 2; |
|
console.log(jq_obj); |
|
$("#policycontainer").stop(); |
|
$("#policycontainer").animate({ scrollTop: jq_obj + height}, 1000); |
|
|
|
}); |
|
} |
|
|
|
|
|
for(let i = 0; i < list_third.length; i++){ |
|
//console.log("hallo von" + list_third[i].id); |
|
$("body").find("."+list_third[i].id+"button").click(function(){ |
|
|
|
$("body").find(".costum-css-select").each(function(){ |
|
$(this).removeClass("costum-css-select"); |
|
}); |
|
|
|
$("body").find("."+list_third[i].id).each(function(){ |
|
$(this).addClass("costum-css-select"); |
|
console.log("treffer third"); |
|
}); |
|
let jq_obj = $("body").find("."+list_third[i].id).first().offset().top; |
|
let height = $("body").find("."+list_third[i].id).first().height() / 2; |
|
console.log(jq_obj); |
|
$("#policycontainer").stop(); |
|
$("#policycontainer").animate({ scrollTop: jq_obj + height + 100}, 1000); |
|
}); |
|
} |
|
} catch(e){ |
|
console.log(e); |
|
} |
|
|
|
|
|
} |
|
|
|
browser.runtime.onMessage.addListener(listener);
|
|
|