forked from chadselph/fPrivacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
85 lines (72 loc) · 3 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(function() {
var PERMS_URL_PARAM = "perms",
PERMS_FORM_PARAM = "perms",
FORM_ID = "uiserver_form";
function split_url_parts() {
var query_parts = window.location.search.substring(1).split("&");
var dict = {};
for(var part_i in query_parts) {
var part = query_parts[part_i];
var key = decodeURIComponent(part.split("=")[0]);
var value = decodeURIComponent(part.split("=")[1]);
dict[key] = value;
}
return dict;
};
function get_active_permissions() {
var parts = split_url_parts()
var perms = parts[PERMS_URL_PARAM]
if(perms) return perms.split(",");
else return [];
};
function set_perms_in_form(choosen) {
/*
* Modify the form live instead of reloading the page.
* Could be used in the future.
*/
var perms = choosen.join(",");
document.getElementById(FORM_ID)[PERMS_FORM_PARAM].value = perms;
};
function reload_page(choosen) {
var url = window.location.origin + window.location.pathname;
var parts = split_url_parts();
parts[PERMS_URL_PARAM] = choosen.join(",");
var new_params = [];
var enc = encodeURIComponent;
for(key in parts) {
new_params.push((enc(key) + "=" + enc(parts[key])));
}
window.location.replace(url + "?" + new_params.join("&"));
};
function generate_header() {
/*
* FIXME: some kind of proper templating or something here.
* Maybe find a lightweight js lib for DOM manipulation.
* Or just use jQuery.
*/
var holder = document.createElement('div');
holder.className = "SocialAuthDisconnect";
holder.innerHTML = "";
var permissions = get_active_permissions();
for(var p in permissions) {
var perm = permissions[p];
holder.innerHTML += '<input type="checkbox" id="'+perm+'" value="'+perm+'" checked=checked name="newperms" /><label for="'+perm+'">'+perm+'</label>';
}
var btn = document.createElement("button");
btn.appendChild(document.createTextNode("Update"));
btn.onclick = function() {
// "Update" is clicked: figure out what's checked and reload the window.
var elements = document.getElementsByName("newperms");
var permissions = Array.prototype.slice.call(elements);
permissions = permissions.filter(function(me){ return me.checked });
permissions = permissions.map(function(me){ return me.value;});
reload_page(permissions);
}
holder.innerHTML += '<a target="_new" href="https://www.facebook.com/settings?tab=applications">Application Settings</a>';
// put it in the pizza!
document.body.insertBefore(holder, document.body.firstChild);
holder.appendChild(btn);
}
generate_header();
console.log(get_active_permissions());
})();