From 8004229f995d567100b360b8b1f2592e208d7f96 Mon Sep 17 00:00:00 2001 From: Jacopo Jannone Date: Wed, 23 Sep 2020 17:05:09 +0200 Subject: [PATCH] Fix #3 --- src/background.js | 16 ++++++++++++++++ src/content.js | 27 +++++++++++---------------- src/manifest.json | 5 ++++- src/popup.html | 1 + 4 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 src/background.js diff --git a/src/background.js b/src/background.js new file mode 100644 index 0000000..a38acbe --- /dev/null +++ b/src/background.js @@ -0,0 +1,16 @@ +chrome.runtime.onMessage.addListener( + function(request, sender, sendResponse) { + if (request.fetchJson) { + fetch(request.fetchJson) + .then(response => response.json()) + .then(response => sendResponse(response)); + return true; + } + if (request.fetchText) { + fetch(request.fetchText) + .then(response => response.text()) + .then(response => sendResponse(response)); + return true; + } + } +) \ No newline at end of file diff --git a/src/content.js b/src/content.js index 6da11e8..141f965 100644 --- a/src/content.js +++ b/src/content.js @@ -23,33 +23,28 @@ var observer = new MutationObserver(function(mutations) { let subdomain = match[1]; let sitename = match[2]; let recording_id = match[3];; - fetch(`https://${subdomain}.webex.com/webappng/api/v1/recordings/${recording_id}/stream?siteurl=${sitename}`) - .then(response => response.json()) - .then(data => { + chrome.runtime.sendMessage( + {fetchJson: `https://${subdomain}.webex.com/webappng/api/v1/recordings/${recording_id}/stream?siteurl=${sitename}`}, + function(data) { let host = data["mp4StreamOption"]["host"]; let recording_dir = data["mp4StreamOption"]["recordingDir"]; let timestamp = data["mp4StreamOption"]["timestamp"]; let token = data["mp4StreamOption"]["token"]; let xml_name = data["mp4StreamOption"]["xmlName"]; let playback_option = data["mp4StreamOption"]["playbackOption"]; - let meeting_name = data["recordName"]; - fetch(`${host}/apis/html5-pipeline.do?recordingDir=${recording_dir}×tamp=${timestamp}&token=${token}&xmlName=${xml_name}&isMobileOrTablet=false&ext=${playback_option}`) - .then(response => response.text()) - .then(text => (new window.DOMParser()).parseFromString(text, "text/xml")) - .then(data => { + chrome.runtime.sendMessage( + {fetchText: `${host}/apis/html5-pipeline.do?recordingDir=${recording_dir}×tamp=${timestamp}&token=${token}&xmlName=${xml_name}&isMobileOrTablet=false&ext=${playback_option}`}, + function(text) { + let data = (new window.DOMParser()).parseFromString(text, "text/xml"); let filename = data.getElementsByTagName("Sequence")[0].textContent; let mp4Url = `${host}/apis/download.do?recordingDir=${recording_dir}×tamp=${timestamp}&token=${token}&fileName=${filename}`; i.addEventListener("click", function() { window.location = mp4Url; }) - }) - .catch(exception => { - console.log("Error") - }); - }) - .catch(exception => { - console.log("Error") - }); + } + ) + } + ) } }); diff --git a/src/manifest.json b/src/manifest.json index ca2014e..caae1e4 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -4,7 +4,7 @@ }, "name": "WebXDownloader", "manifest_version": 2, - "version": "1.1", + "version": "1.1.1", "description": "Extracts the HLS stream of Webex meeting recordings", "browser_action": { "default_icon": "icon.png", @@ -16,6 +16,9 @@ "matches": ["*://*.webex.com/*"], "run_at": "document_end" }], + "background": { + "scripts": ["background.js"] + }, "homepage_url": "https://github.com/jacopo-j/WebXDownloader", "permissions": [ "tabs", diff --git a/src/popup.html b/src/popup.html index 6386292..b56cca5 100644 --- a/src/popup.html +++ b/src/popup.html @@ -1,5 +1,6 @@ +