diff --git a/background.js b/background.js index f530823..36f25a5 100644 --- a/background.js +++ b/background.js @@ -5,6 +5,7 @@ var remoteOptionId; var s = chrome.storage.local; var cn = chrome.notifications; var apiKey; +var folderId; var APIURLS = { instantDld: 'https://offcloud.com/api/instant/download', @@ -21,12 +22,15 @@ restoreOptions(); initMenus(); function restoreOptions(){ - chrome.storage.local.get(['apiKey', 'remoteOptionId'], function(object){ + chrome.storage.local.get(['apiKey', 'remoteOptionId', 'folderId'], function(object){ if (object.apiKey != null) apiKey = object.apiKey; if (object.remoteOptionId != null) remoteOptionId = object.remoteOptionId; + + if (object.folderId != null) + folderId = object.folderId; }); } @@ -63,6 +67,21 @@ function setApiKey(newApiKey){ }); } +function setFolderId(newFolderId){ + s.set({ + folderId: newFolderId + }, function(){ + folderId = newFolderId; + }); +} + +function getFolderId(callback) { + s.get('folderId', function(result){ + folderId = result.folderId; + callback(); + }); +} + function initMenus() { cm.removeAll(); @@ -193,6 +212,10 @@ function processMultipleLink(html, needReg, remote, tab, api, href, type) { dataBody.remoteOptionId = remoteOptionId; else dataBody.remoteOptionId = ""; + if (folderId) + dataBody.folderId = folderId; + else + dataBody.folderId = ""; } requestList.push($.ajax(api, { method: 'POST', @@ -260,6 +283,10 @@ function processCall(api, link, remote, tab, type) { dataBody.remoteOptionId = remoteOptionId; else dataBody.remoteOptionId = ""; + if (folderId) + dataBody.folderId = folderId; + else + dataBody.folderId = ""; processAjax(api, link, true, tab, dataBody, type); @@ -354,6 +381,9 @@ om.addListener(function(req, sender, sendResponse) { if (req.action == "removeRemoteOptionId") remoteOptionId = null; + + if (req.action == "setFolderId") + setFolderId(req.newFolderId); if (req.cmd == "custom") { var currentApi; diff --git a/options.html b/options.html index 8915bc9..254b7c3 100644 --- a/options.html +++ b/options.html @@ -41,6 +41,15 @@
+
+ Google Folder ID / Amazon Cloud Drive Parent ID: +
+
+ +
+
+ +
diff --git a/options.js b/options.js index f656859..3b0b93f 100644 --- a/options.js +++ b/options.js @@ -1,7 +1,9 @@ var apiKeyInput = document.getElementById('apiKeyInput'); var remoteOptionsSelect = document.getElementById('remoteOptionsSelect'); +var folderIdInput = document.getElementById('folderIdInput'); var saveApiKeyBtn = document.getElementById('saveApiKeyBtn'); var saveRemoteOptionBtn = document.getElementById('saveRemoteOptionBtn'); +var saveFolderIdBtn = document.getElementById('saveFolderIdBtn'); var statusDiv = document.querySelector('.status-div'); restoreOptions(); @@ -44,18 +46,34 @@ function setEventHandlers(){ }); }); } - + }); + + saveFolderIdBtn.addEventListener('click', function(){ + var folderId = folderIdInput.value; + if (folderId == "") + folderId = null; + chrome.storage.local.set({ + folderId: folderId + }, function(){ + chrome.runtime.sendMessage({ + action: "setFolderId", + newFolderId: folderId + }); + if (folderId) statusDiv.innerText = 'Your Folder ID / Parent ID has been successfully changed!'; + else statusDiv.innerText = 'Your Folder ID / Parent ID has been cleared.'; + }); }); } function restoreOptions(){ - chrome.storage.local.get(['apiKey', 'remoteOptionId'], function(object){ + chrome.storage.local.get(['apiKey', 'remoteOptionId', 'folderId'], function(object){ if (object.apiKey != null){ apiKeyInput.value = object.apiKey; getRemoteOptionsRequest(object.apiKey) .then((data) => { setRemoteOptions(data, object.remoteOptionId); }) .catch((err) => { console.log(err); }); } + folderIdInput.value = object.folderId; }); }