Skip to content

Commit 265b024

Browse files
committed
json formatter
1 parent 229452b commit 265b024

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

popup/tabs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ const tabs = [
149149
...CATEGORY.automation,
150150
scripts: [
151151
s.transfer_sh,
152+
s.jsonformatter,
152153
s.textToQRCode,
153154
s.webToQRCode,
154155
s.getAllEmailsInWeb,

scripts/helpers/utils.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,25 @@ export function getCurrentTab() {
7070
});
7171
});
7272
}
73+
74+
// https://stackoverflow.com/a/15292178/11898496
75+
// https://stackoverflow.com/a/40815514/11898496
76+
// 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],
91+
});
92+
93+
!willOpenActive && chrome.tabs.remove(tab.id);
94+
}

scripts/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ import fb_checkToken from "./fb_checkToken.js";
107107
import fb_getTokenCampaigns from "./fb_getTokenCampaigns.js";
108108
import unshorten from "./unshorten.js";
109109
import transfer_sh from "./transfer_sh.js";
110+
import jsonformatter from "./jsonformatter.js";
110111

111112
// inject badges
112113
const allScripts = {
@@ -223,6 +224,7 @@ const allScripts = {
223224
fb_getTokenCampaigns: addBadge(fb_getTokenCampaigns, BADGES.new),
224225
unshorten: addBadge(unshorten, BADGES.hot),
225226
transfer_sh: addBadge(transfer_sh, BADGES.new),
227+
jsonformatter: addBadge(jsonformatter, BADGES.new),
226228
};
227229

228230
// inject id to all scripts

scripts/jsonformatter.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { setLocalStorage } from "./helpers/utils.js";
2+
3+
export default {
4+
icon: "https://jsonformatter.org/img/favicon.png",
5+
name: {
6+
en: "JSON formatter",
7+
vi: "JSON formatter",
8+
},
9+
description: {
10+
en: "",
11+
vi: "",
12+
},
13+
runInExtensionContext: true,
14+
15+
func: async function () {
16+
try {
17+
let url = "https://jsonformatter.org";
18+
let jsonString = prompt("Nhập object json muốn làm đẹp:", "");
19+
if (jsonString != null) {
20+
let stringify = JSON.stringify(jsonString);
21+
await setLocalStorage(url, "index", stringify, true);
22+
}
23+
} catch (e) {
24+
alert("Lỗi: " + e);
25+
}
26+
},
27+
};

scripts/zingmp3_oldLayout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
func: function () {
1515
// Mặc định thì mp3.zing.vn (giao diện cũ) sẽ tự động redirect người dùng về zingmp3.vn (giao diện mới)
1616

17-
// Vui lòng xem file content-script/mp3.zing.vn.js và content-script/document_start.js
17+
// Vui lòng xem file content-script/scripts/mp3.zing.vn.js và content-script/document_start.js
1818
// Để biết cách bypass quá trình tự động này
1919

2020
if (location.hostname === "mp3.zing.vn") location.hostname = "zingmp3.vn";

0 commit comments

Comments
 (0)