-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathmyScript.js
More file actions
196 lines (160 loc) · 5.35 KB
/
myScript.js
File metadata and controls
196 lines (160 loc) · 5.35 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
* @file myScript.js
* Script to analyze Facebook feed and make connection with the server
*
* @author Mark Craft, Qinglin Chen
* @date Fall 2016
*/
(function(document) {
'use strict';
var feeds = new Set();
function text(res) {
return res.text();
}
/**
* Http request to fbserve.herokuapp.com.
*
* @param url to send to the server.
* @param the type of information sent
* @param the location to put the button
*/
function httpGet(input, type, data) {
var server = "https://fbserve.herokuapp.com/";
var contents = "?content=";
var page = (type=="url")? decode(input) : input;
var theUrl = server + contents + page;
theUrl = theUrl.replace("&", "^");
//console.log("Type: " + type + " : " + page);
fetch(theUrl)
.then(text).then(function(text) {
var btn = document.createElement('div'),
button = Ladda.create(btn);
btn.style = "font-weight:bold; padding: 3px; position:absolute; top: 4px; right: 30px;background: #3b5998; font-size: 15px;";
if(text=="verified") {
btn.innerHTML = "verified";
btn.style.color = "#D5F5E3";
} else {
btn.innerHTML = "not verified";
btn.style.color = "#E74C3C";
}
data.appendChild(btn);
});
}
/**
* Create a button on the screen
*
* @param location of the button
* @param the text to display on the button
* @param whether the server is down or not
*/
function createButton(btn, loc) {
var btn = document.createElement('div'),
button = Ladda.create(btn);
//btn.addEventListener("mouseover", hoverTooltip.bind(text), false);
btn.innerHTML = "server down";
btn.style = "font-weight:bold; padding: 3px; position:absolute; top: 4px; right: 30px;background: #3b5998; font-size: 15px; color: #FFFFFF;";
loc.appendChild(btn);
}
/**
* Display tooltip with more accurate information
*
* @param the information to display
*/
function hoverTooltip(info) {
//console.log("hovering: " + info);
}
/*
* Parse through Facebook's encoded url for the actual url
*
*/
function parseUri(str) {
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;
while (i--) uri[o.key[i]] = m[i] || "";
uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2;
});
return uri;
};
parseUri.options = {
strictMode: false,
key: ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
};
function decode(code) {
var url_obj = parseUri(code);
if (url_obj.queryKey.u) {
return url_obj.queryKey.u;
} else if (url_obj.host === 'www.facebook.com') {
return url_obj;
} else {
return link;
}
}
/**
* Receive each Facebook post and analyze texts, urls, pics for validity.
* Refreshes every second.
*
*/
setInterval(function() {
var test = document.getElementsByClassName('_4-u2 mbm _5v3q _4-u8');
for(var i=0; i<test.length; i++) {
var data = test[i];
// Check if feed needs to be modified
if(!feeds.has(data)) {
feeds.add(data);
// Send server requests
var statement = "";
var processed = false;
var linked = test[i].querySelector('._6ks');
if(!processed && linked != null && linked.querySelector('a') != null) {
processed = true;
httpGet(linked.querySelector('a').href, "url", data);
}
var link = test[i].querySelector('._5pbx.userContent');
if(!processed && link != null && link.querySelector('a') != null && link.querySelector('a').href != null) {
processed = true;
httpGet(link.href, "url", data);
}
var picComment = test[i].querySelector('.uiScaledImageContainer._4-ep');
if(!processed && picComment != null && picComment.querySelector('img') != undefined && picComment.querySelector('img').src != null) {
processed = true;
httpGet(picComment.querySelector('img').src, "image", data);
}
var picPost = test[i].querySelector('._46-h._517g');
if(!processed && picPost != null && picPost.querySelector('img') != undefined && picPost.querySelector('img').src != null) {
processed = true;
httpGet(picPost.querySelector('img').src, "image", data);
}
var picTagged = test[i].querySelector('._4-eo._2t9n');
if(!processed && picTagged != null && picTagged.querySelector('._46-h._4-ep') != null && picTagged.querySelector('._46-h._4-ep').querySelector('img') != null) {
processed = true;
httpGet(picTagged.querySelector('._46-h._4-ep').querySelector('img').src, "image", data);
}
/*
var picAlbum = test[i].querySelector('._2a2q');
if(!processed && picAlbum != null && picAlbum.querySelectorAll('._5dec._xcx')!=undefined) {
processed = true;
var pics = picAlbum.querySelectorAll('a._5dec._xcx');
for(var i=0; i<pics.length; i++) {}
}
*/
var text = test[i].querySelector('._5pbx.userContent');
if(!processed && text != null && text.textContent != null) {
processed = true;
httpGet(text.textContent, "text", data);
}
}
}
}, 1000);
})(document);