-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
34 lines (27 loc) · 1001 Bytes
/
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
const REQUEST_SIGNATURE = "vimeo/SEARCH_VIDEOS"
function parseConfigs(rawHtml) {
const cleanedHtml = rawHtml.replace(/\s+/gi, "");
const start = cleanedHtml.search('"progressive":');
const end = cleanedHtml.search(/}]},/g);
if (start === -1 || end === -1) {
return [];
}
const configsJsonString = cleanedHtml.slice(start, end).replace(/\"progressive\":/g, "") + "}]";
const configsJson = JSON.parse(configsJsonString);
return configsJson;
}
function parsePage() {
const mHtml = document.body.innerHTML;
const configsJson = parseConfigs(mHtml);
return configsJson.sort((x, y) => (x.width <= y.width ? -1 : 1));
}
chrome.runtime.onMessage.addListener(function (request) {
if (request === REQUEST_SIGNATURE) {
setTimeout(
function () {
const configsJson = parsePage();
chrome.extension.sendRequest({ type: "SET_CONFIGS", payload: configsJson });
},
1000);
}
});