Skip to content

Commit 229452b

Browse files
committed
Merge branch 'dev' of https://github.com/HoangTran0410/useful-script into dev
2 parents 9d1678b + a23b0ac commit 229452b

File tree

6 files changed

+91
-86
lines changed

6 files changed

+91
-86
lines changed

scripts/archiveToday.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getCurrentTab } from "./helpers/utils.js";
2+
13
export default {
24
icon: `https://archive.ph/favicon.ico`,
35
name: {
@@ -10,17 +12,13 @@ export default {
1012
},
1113
runInExtensionContext: true,
1214

13-
func: function () {
14-
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
15-
var currentTab = tabs[0];
16-
if (currentTab?.url) {
17-
var a = currentTab.url.replace(/^http\:\/\/(.*)$/, "$1");
18-
window.open(
19-
"https://archive.today/?run=1&url=" + encodeURIComponent(a)
20-
);
21-
} else {
22-
alert("Không tìm thấy url web hiện tại");
23-
}
24-
});
15+
func: async function () {
16+
let { url } = await getCurrentTab();
17+
18+
var a = window.prompt(
19+
"Nhập URL muốn xem archive: ",
20+
url.replace(/^http\:\/\/(.*)$/, "$1")
21+
);
22+
window.open("https://archive.today/?run=1&url=" + encodeURIComponent(a));
2523
},
2624
};

scripts/checkWebDie.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getCurrentTab } from "./helpers/utils.js";
2+
13
export default {
24
icon: `https://s2.googleusercontent.com/s2/favicons?domain=downforeveryoneorjustme.com`,
35
name: {
@@ -10,17 +12,15 @@ export default {
1012
},
1113
runInExtensionContext: true,
1214

13-
func: function () {
14-
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
15-
var currentTab = tabs[0];
16-
if (currentTab?.url) {
17-
let url = prompt("Enter web url to check", currentTab.url);
18-
if (url) {
19-
window.open("https://downforeveryoneorjustme.com/" + url);
20-
}
21-
} else {
22-
alert("Không tìm thấy url web hiện tại");
15+
func: async function () {
16+
let { url } = await getCurrentTab();
17+
if (url) {
18+
let url_to_check = prompt("Enter web url to check", url);
19+
if (url_to_check) {
20+
window.open("https://downforeveryoneorjustme.com/" + url_to_check);
2321
}
24-
});
22+
} else {
23+
alert("Không tìm thấy url web hiện tại");
24+
}
2525
},
2626
};

scripts/downDetector.js

Lines changed: 42 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/googleCache.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getCurrentTab } from "./helpers/utils.js";
2+
13
export default {
24
// icon get from https://chrome.google.com/webstore/detail/google-cache-viewer/fgfklknfijhflahngajfoagmoilakebp
35
icon: "https://lh3.googleusercontent.com/OoZ3sM4u01hfT9201pmeBasLOsaRlZe2CbXzcXQLBYOcgpKVDPEakpr_ZHxiXQ1IkQ5dYTvEYndU0m8RH7TOhb1H=w128-h128-e365-rj-sc0x00ffffff",
@@ -11,17 +13,16 @@ export default {
1113
},
1214
runInExtensionContext: true,
1315

14-
func: function () {
16+
func: async function () {
1517
// https://cachedviews.com/
1618

17-
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
18-
var currentTab = tabs[0];
19-
if (currentTab?.url) {
20-
var a = currentTab.url.replace(/^http\:\/\/(.*)$/, "$1");
21-
window.open("http://www.google.com/search?q=cache:" + encodeURIComponent(a));
22-
} else {
23-
alert("Không tìm thấy url web hiện tại");
24-
}
25-
});
19+
let { url } = await getCurrentTab();
20+
let url_to_check = window.prompt(
21+
"Nhập URL muốn xem cache: ",
22+
url.replace(/^http\:\/\/(.*)$/, "$1")
23+
);
24+
window.open(
25+
"http://www.google.com/search?q=cache:" + encodeURIComponent(url_to_check)
26+
);
2627
},
2728
};

scripts/helpers/utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,12 @@ export async function getCookie(domain, raw = false) {
6161
? cookies
6262
: cookies.map((_) => _.name + "=" + decodeURI(_.value)).join(";");
6363
}
64+
65+
export function getCurrentTab() {
66+
return new Promise((resolve, reject) => {
67+
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
68+
console.log(tabs[0]);
69+
resolve(tabs?.[0] || {});
70+
});
71+
});
72+
}

0 commit comments

Comments
 (0)