-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
178 lines (148 loc) · 8.54 KB
/
main.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* Variables
*/
let jsessionId = findJsessionId();
jsessionId = cleanupJsessionId(jsessionId);
let loader, anonymousButton, fullyVisibleButton;
let commands = {
'anonymous' : '------WebKitFormBoundary\r\nContent-Disposition: form-data; name="dataKey"\r\n\r\nprofileVisibility\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="el"\r\n\r\n#setting-profile-visibility\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="settingsUrls"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="name"\r\n\r\nprofile-visibility\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="locale"\r\n\r\nen_US\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="isNotCnDomain"\r\n\r\ntrue\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="headerData"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="path"\r\n\r\n/psettings/profile-visibility\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="data"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="lixTests"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="pageTitle"\r\n\r\nProfile viewing\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="settingVisibility"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="device"\r\n\r\nDESKTOP\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="setting"\r\n\r\nprofile-visibility\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="initialFetch"\r\n\r\ntrue\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="dataVal"\r\n\r\nDISCLOSE_FULL\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="hasSuccess"\r\n\r\nfalse\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="errors"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="discloseAsProfileViewer"\r\n\r\nHIDE\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="csrfToken"\r\n\r\n' + jsessionId + '\r\n------WebKitFormBoundary--\r\n',
'full' : '------WebKitFormBoundary\r\nContent-Disposition: form-data; name="dataKey"\r\n\r\nprofileVisibility\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="el"\r\n\r\n#setting-profile-visibility\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="settingsUrls"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="name"\r\n\r\nprofile-visibility\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="dataVal"\r\n\r\nHIDE\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="locale"\r\n\r\nen_US\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="isNotCnDomain"\r\n\r\ntrue\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="headerData"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="path"\r\n\r\n/psettings/profile-visibility\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="data"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="lixTests"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="pageTitle"\r\n\r\nProfile viewing\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="settingVisibility"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="device"\r\n\r\nDESKTOP\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="setting"\r\n\r\nprofile-visibility\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="initialFetch"\r\n\r\ntrue\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="hasSuccess"\r\n\r\nfalse\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="errors"\r\n\r\n[object Object]\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="discloseAsProfileViewer"\r\n\r\nDISCLOSE_FULL\r\n------WebKitFormBoundary\r\nContent-Disposition: form-data; name="csrfToken"\r\n\r\n' + jsessionId + '\r\n------WebKitFormBoundary--\r\n'
};
const defaultClassNames = {
'loader' : 'text-center f-8',
'anonymousButton' : 'button f-8',
'fullyVisibleButton' : 'button f-8'
};
/**
* Functions
*/
function findJsessionId() {
let theCookies = document.cookie.split(';');
for (let i = 1 ; i <= theCookies.length; i++) {
let cookieStr = theCookies[i-1].trim();
let cookieParts = cookieStr.split('=');
if (cookieParts[0].indexOf('JSESSIONID') > -1) {
return cookieParts[1];
}
}
return '';
}
function cleanupJsessionId(jsessionId) {
return jsessionId.substring(1, jsessionId.length - 1);
}
function executeCommandToApi(commandKey, callback) {
http('POST', '/psettings/profile-visibility', commands[commandKey], {
'Content-Type' : 'multipart/form-data; boundary=----WebKitFormBoundary',
'x-requested-with' : 'XMLHttpRequest'
}, function(rawResponse) {
callback();
});
}
function isVisibleFromApi(callback) {
http('GET', '/psettings/profile-visibility?asJson=true', null, {}, function(rawResponse) {
let result = JSON.parse(rawResponse);
let visibility = result.map.data.profileVisibility;
if (visibility === 'DISCLOSE_FULL') {
// Visible
callback(true);
} else {
// Hidden
callback(false);
}
});
}
function http(method, url, requestBody, headers, callback){
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
callback(xmlHttp.responseText);
}
}
xmlHttp.open(method, url, true); // true for asynchronous
for (headerKey in headers) {
xmlHttp.setRequestHeader(headerKey, headers[headerKey]);
}
xmlHttp.send(requestBody);
}
function onClickFullyAnonymous(){
showLoading();
executeCommandToApi('anonymous', function() {
location.reload();
});
}
function onClickFullyVisible() {
showLoading();
executeCommandToApi('full', function(){
location.reload();
});
}
function showLoading() {
loader.className = defaultClassNames['loader'];
anonymousButton.className = defaultClassNames['anonymousButton'] + ' hide';
fullyVisibleButton.className = defaultClassNames['fullyVisibleButton'] + ' hide';
}
function showAnonymousButton() {
loader.className = defaultClassNames['loader'] + ' hide';
anonymousButton.className = defaultClassNames['anonymousButton'];
fullyVisibleButton.className = defaultClassNames['fullyVisibleButton'] + ' hide';
}
function showVisibleButton() {
loader.className = defaultClassNames['loader'] + ' hide';
anonymousButton.className = defaultClassNames['anonymousButton'] + ' hide';
fullyVisibleButton.className = defaultClassNames['fullyVisibleButton'];
}
function createDomElement(elementTag, attributes) {
let element = document.createElement(elementTag);
for (attributeKey in attributes) {
if (attributeKey === 'text') {
element.innerHTML = attributes[attributeKey];
} else {
element[attributeKey] = attributes[attributeKey];
}
}
return element;
}
function init() {
isVisibleFromApi(function(isVisible) {
if (isVisible) {
showAnonymousButton();
} else {
showVisibleButton();
}
});
}
/**
* Build DOM
*/
let container = createDomElement('div', {
id : 'linkedin-hider',
className : 'border-gray'
});
let hiderTitle = createDomElement('p', {
text : 'Hider',
className : 'text-center color-gray f-8'
});
container.appendChild(hiderTitle);
loader = createDomElement('p', {
text : 'Loading...',
className : defaultClassNames['loader']
});
container.appendChild(loader);
anonymousButton = createDomElement('button', {
text : 'Hide me',
onclick : onClickFullyAnonymous,
className : defaultClassNames['anonymousButton'] + ' hide'
});
container.appendChild(anonymousButton);
fullyVisibleButton = createDomElement('button', {
text : 'Show me',
onclick : onClickFullyVisible,
className : defaultClassNames['fullyVisibleButton'] + ' hide'
});
container.appendChild(fullyVisibleButton);
document.body.appendChild(container);
/**
* Main
*/
init();
console.log('LinkedIn Hider loaded');