From 940935e18ef9e05dcdee3102437687a0a95a2e4d Mon Sep 17 00:00:00 2001 From: Alexander Bass Date: Fri, 30 Dec 2022 13:32:28 -0500 Subject: [PATCH] Make more firefox dependant, but better ish --- content_scripts/saveload.js | 18 ++++-------------- inject_scripts/save.js | 7 ------- manifest.json | 6 ++---- 3 files changed, 6 insertions(+), 25 deletions(-) delete mode 100644 inject_scripts/save.js diff --git a/content_scripts/saveload.js b/content_scripts/saveload.js index 0be7322..1632f0d 100644 --- a/content_scripts/saveload.js +++ b/content_scripts/saveload.js @@ -16,15 +16,11 @@ setTimeout(checkIfReady, 200); } - const expressionExport = document.createElement("div"); - expressionExport.id = "EXPORTEXPRESSION"; - expressionExport.style.display = "none"; const expressionImport = document.createElement("div"); expressionImport.id = "IMPORTEXPRESSION"; expressionImport.style.display = "none"; document.body.appendChild(expressionImport); - document.body.appendChild(expressionExport); function download(filename, textInput) { var element = document.createElement('a'); @@ -82,24 +78,18 @@ function loadExpr(json) { const expressions = JSON.stringify(json); var scriptTag = document.createElement('script'); - scriptTag.src = chrome.extension.getURL('inject_scripts/load.js'); + scriptTag.src = browser.runtime.getURL('inject_scripts/load.js'); scriptTag.onload = function () { this.parentNode.removeChild(this); }; document.getElementById("IMPORTEXPRESSION").textContent = expressions; document.body.append(scriptTag); } function saveExpr() { - var scriptTag = document.createElement('script'); + const expressions = window.wrappedJSObject.Calc.getExpressions(); const graphTitle = document.querySelector(".align-left-container").querySelector(".dcg-variable-title").textContent + ".json"; - scriptTag.src = chrome.extension.getURL('inject_scripts/save.js'); - scriptTag.onload = function () { this.parentNode.removeChild(this); }; - document.body.append(scriptTag); + const expressionsString = JSON.stringify(expressions); + download(graphTitle, expressionsString); - document.addEventListener("updatedExpression", () => { - const expressionsString = document.getElementById("EXPORTEXPRESSION").textContent; - download(graphTitle, expressionsString); - document.getElementById("EXPORTEXPRESSION").textContent = ""; - }); } })(); diff --git a/inject_scripts/save.js b/inject_scripts/save.js deleted file mode 100644 index 26e3c22..0000000 --- a/inject_scripts/save.js +++ /dev/null @@ -1,7 +0,0 @@ -(function () { - const expressions = Calc.getExpressions(); - const expressionBox = document.getElementById("EXPORTEXPRESSION"); - expressionBox.textContent = JSON.stringify(expressions); - const updateEvent = new Event("updatedExpression"); - document.dispatchEvent(updateEvent); -})(); diff --git a/manifest.json b/manifest.json index 772399a..8fd125b 100644 --- a/manifest.json +++ b/manifest.json @@ -17,11 +17,9 @@ ] } ], - "host_permissions": [ - "https://www.desmos.com/" - ], "web_accessible_resources": [ - "inject_scripts/*.js" + "inject_scripts/load.js", + "inject_scripts/save.js" ], "browser_action": { "default_icon": "icons/icon-32.png",