Skip to content

Commit aea01f9

Browse files
committed
wip
1 parent 265b024 commit aea01f9

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

scripts/helpers/utils.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,23 @@ export function getCurrentTab() {
7474
// https://stackoverflow.com/a/15292178/11898496
7575
// https://stackoverflow.com/a/40815514/11898496
7676
// https://stackoverflow.com/a/69507918/11898496
77-
export async function setLocalStorage(
78-
domain,
79-
key,
80-
value,
81-
willOpenActive = false
82-
) {
83-
let tab = await chrome.tabs.create({ active: willOpenActive, url: domain });
84-
await chrome.scripting.executeScript({
85-
target: { tabId: tab.id },
86-
func: function (_key, _value) {
87-
alert(_key + " " + _value);
88-
localStorage.setItem(_key, _value);
89-
},
90-
args: [key, value],
77+
export function setLocalStorage(domain, key, value, willOpenActive = false) {
78+
return new Promise((resolve, reject) => {
79+
chrome.tabs.create({ active: willOpenActive, url: domain }, (tab) => {
80+
chrome.scripting.executeScript(
81+
{
82+
target: { tabId: tab.id },
83+
func: function (_key, _value) {
84+
alert(_key + " " + _value);
85+
localStorage.setItem(_key, _value);
86+
},
87+
args: [key, value],
88+
},
89+
() => {
90+
// !willOpenActive && chrome.tabs.remove(tab.id);
91+
resolve();
92+
}
93+
);
94+
});
9195
});
92-
93-
!willOpenActive && chrome.tabs.remove(tab.id);
9496
}

scripts/jsonformatter.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ export default {
1818
let jsonString = prompt("Nhập object json muốn làm đẹp:", "");
1919
if (jsonString != null) {
2020
let stringify = JSON.stringify(jsonString);
21-
await setLocalStorage(url, "index", stringify, true);
21+
setLocalStorage(url, "index", stringify);
2222
}
2323
} catch (e) {
2424
alert("Lỗi: " + e);
2525
}
26+
27+
// https://stackoverflow.com/a/32357610/11898496
28+
// var win = window.open("https://jsonformatter.org");
29+
// win.focus();
30+
// win.addEventListener("load", () => {
31+
// win.localStorage.setItem("index", "{'abc':1}");
32+
// win.alert("yep");
33+
// });
2634
},
2735
};

0 commit comments

Comments
 (0)