-
Notifications
You must be signed in to change notification settings - Fork 8
/
payload.js
34 lines (26 loc) · 1.08 KB
/
payload.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
chrome.extension.onMessage.addListener(function(msg, _sender, sendResponse) {
if (msg.action == 'download_video') {
// Default parameters to grab video info
var name = "";
var url = "";
var metas = document.getElementsByTagName('meta');
for (var i=0; i<metas.length; i++)
if (metas[i].getAttribute("name") == "twitter:player:stream") {
console.log(metas[i].getAttribute("content"));
url = (metas[i].getAttribute("content").split('?')[0]);
}
else if (metas[i].getAttribute("property") == "og:title") {
console.log(metas[i].getAttribute("content"));
name = metas[i].getAttribute("content").split('?')[0];
}
// Split the name up (remove invalid characters in file names) && add file format
name = name.split('/').join('_'); // Remove slashes
name = name.split(' ').join('_'); // Remove spaces
name = name.split(':').join('-'); // Remove colons
name = name + ".mp4";
// Pack into array to send through callback function
var infoArray = [url, name];
// Callback function
sendResponse(infoArray);
}
});