diff --git a/extension/changelog.json b/extension/changelog.json index c90b87b8b..edf765f71 100644 --- a/extension/changelog.json +++ b/extension/changelog.json @@ -1,9 +1,9 @@ [ { - "version": { "major": 7, "minor": 3, "build": 0 }, + "version": { "major": 7, "minor": 2, "build": 2 }, "title": "Beta", "date": false, - "logs": { "features": [], "fixes": [], "changes": [], "removed": [] } + "logs": { "features": [], "fixes": [{ "message": "Fixed Trade Open Chat.", "contributor": "TheFoxMan" }], "changes": [], "removed": [] } }, { "version": { "major": 7, "minor": 2, "build": 1 }, diff --git a/extension/manifest.json b/extension/manifest.json index 4df98bab7..523381b62 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "TornTools", - "version": "7.3.0", + "version": "7.2.2", "description": "Several tools for Torn.", "icons": { "16": "resources/images/icon_16.png", "48": "resources/images/icon_48.png", "128": "resources/images/icon_128.png" }, "action": { "default_title": "TornTools", "default_popup": "pages/popup/popup.html", "default_icon": "resources/images/icon_128.png" }, diff --git a/extension/scripts/features/add-debug-info/ttAddDebugInfo.inject.js b/extension/scripts/features/add-debug-info/ttAddDebugInfo.inject.js new file mode 100644 index 000000000..2fed9522c --- /dev/null +++ b/extension/scripts/features/add-debug-info/ttAddDebugInfo.inject.js @@ -0,0 +1 @@ +$("#editor-wrapper .editor-content.mce-content-body").keyup() diff --git a/extension/scripts/features/add-debug-info/ttAddDebugInfo.js b/extension/scripts/features/add-debug-info/ttAddDebugInfo.js index b7896df02..85a50c58f 100644 --- a/extension/scripts/features/add-debug-info/ttAddDebugInfo.js +++ b/extension/scripts/features/add-debug-info/ttAddDebugInfo.js @@ -65,10 +65,7 @@ // Add the browser information to BBCode input. // Need jQuery as dispatchEvent is not working. - executeScript( - (wrapped) => wrapped.$("#editor-wrapper .editor-content.mce-content-body").keyup(), - "$('#editor-wrapper .editor-content.mce-content-body').keyup();" - ); + executeScript(chrome.runtime.getURL("scripts/features/add-debug-info/ttAddDebugInfo.inject.js")); }, }, }); diff --git a/extension/scripts/features/no-confirm/ttItemNoConfirm.js b/extension/scripts/features/no-confirm/ttItemNoConfirm.js index 8e389fa7e..3d82b0325 100644 --- a/extension/scripts/features/no-confirm/ttItemNoConfirm.js +++ b/extension/scripts/features/no-confirm/ttItemNoConfirm.js @@ -6,11 +6,6 @@ function injectAdjustments() { injectXHR(); - document.head.appendChild( - document.newElement({ - type: "script", - attributes: { type: "text/javascript", src: chrome.runtime.getURL("/scripts/features/no-confirm/ttItemNoConfirm.inject.js") }, - }) - ); + executeScript(chrome.runtime.getURL("/scripts/features/no-confirm/ttItemNoConfirm.inject.js"), false); } })(); diff --git a/extension/scripts/features/points-value/ttPointsValue.js b/extension/scripts/features/points-value/ttPointsValue.js index 164d6a15e..45cddb681 100644 --- a/extension/scripts/features/points-value/ttPointsValue.js +++ b/extension/scripts/features/points-value/ttPointsValue.js @@ -56,16 +56,7 @@ ); }); - // New method instead of executeScript() to avoid CSP error. - const scriptEl = document.newElement({ - type: "script", - attributes: { - type: "text/javascript", - src: chrome.runtime.getURL("scripts/features/points-value/ttPointsValue.inject.js"), - }, - }); - document.head.appendChild(scriptEl); - setTimeout(() => scriptEl.remove(), 2000); + executeScript(chrome.runtime.getURL("scripts/features/points-value/ttPointsValue.inject.js")); } function removeValue() { diff --git a/extension/scripts/features/trade-open-chat/ttTradeOpenChat.inject.js b/extension/scripts/features/trade-open-chat/ttTradeOpenChat.inject.js new file mode 100644 index 000000000..76e7ce500 --- /dev/null +++ b/extension/scripts/features/trade-open-chat/ttTradeOpenChat.inject.js @@ -0,0 +1,8 @@ +(async () => { + const playerID = (await cookieStore.get("uid")).value; + const traderID = $(`#trade-container .log > li .desc a:not([href*="${playerID}"])`) + .attr("href") + .match(/XID=(\d*)/i)[1]; + + chat.r(traderID); +})(); diff --git a/extension/scripts/features/trade-open-chat/ttTradeOpenChat.js b/extension/scripts/features/trade-open-chat/ttTradeOpenChat.js index e1c538613..4c379cc91 100644 --- a/extension/scripts/features/trade-open-chat/ttTradeOpenChat.js +++ b/extension/scripts/features/trade-open-chat/ttTradeOpenChat.js @@ -38,7 +38,7 @@ class: "tt-open-chat", }); - button.addEventListener("click", () => executeScript((wrapped) => wrapped.chat.r(id), `chat.r(${id})`)); + button.addEventListener("click", () => executeScript(chrome.runtime.getURL("scripts/features/trade-open-chat/ttTradeOpenChat.inject.js"))); document.find("#trade-container > .title-black").appendChild( document.newElement({ diff --git a/extension/scripts/global/functions/dom.js b/extension/scripts/global/functions/dom.js index a068af5ee..e045645d8 100644 --- a/extension/scripts/global/functions/dom.js +++ b/extension/scripts/global/functions/dom.js @@ -429,18 +429,19 @@ function showLoadingPlaceholder(element, show) { } } -function executeScript(handler, code) { - if (window.wrappedJSObject && handler) handler(window.wrappedJSObject); - else { - const script = document.newElement({ - type: "script", - attributes: { type: "text/javascript" }, - html: code, - }); - - document.head.appendChild(script); - setTimeout(() => script.remove(), 100); - } +function executeScript(filename, remove=true) { + const script = document.newElement({ + type: "script", + attributes: { + type: "text/javascript", + src: filename, + } + }); + + document.head.appendChild(script); + + if (remove) + setTimeout(() => script.remove(), 2000); } function updateQuery(key, value) { diff --git a/extension/scripts/global/functions/listeners.js b/extension/scripts/global/functions/listeners.js index d70eee7ee..123c7af55 100644 --- a/extension/scripts/global/functions/listeners.js +++ b/extension/scripts/global/functions/listeners.js @@ -62,12 +62,7 @@ let injectedXHR, injectedFetch; function injectFetch() { if (injectedFetch) return; - document.head.appendChild( - document.newElement({ - type: "script", - attributes: { type: "text/javascript", src: chrome.runtime.getURL("/scripts/global/inject/fetch.inject.js") }, - }) - ); + executeScript(chrome.runtime.getURL("/scripts/global/inject/fetch.inject.js"), false); injectedFetch = true; } @@ -80,12 +75,7 @@ function addFetchListener(callback) { function injectXHR() { if (injectedXHR) return; - document.head.appendChild( - document.newElement({ - type: "script", - attributes: { type: "text/javascript", src: chrome.runtime.getURL("/scripts/global/inject/xhr.inject.js") }, - }) - ); + executeScript(chrome.runtime.getURL("/scripts/global/inject/xhr.inject.js"), false); injectedXHR = true; }