-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathextension.js
103 lines (86 loc) · 2.55 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const vscode = require("vscode");
const axios = require("axios").default;
function GetrandomAyaNumber() {
const ayatMinimumFromNumber = 1;
const ayatMaximumAtNumber = 6236;
return (
Math.floor(
Math.random() * (ayatMaximumAtNumber - ayatMinimumFromNumber + 1)
) + ayatMinimumFromNumber
);
}
function getUserLanguage() {
return vscode.workspace.getConfiguration("ayat").get("language") === "Arabic"
? "ar"
: "en";
}
async function getRandomAya() {
let randomAyaNumber = GetrandomAyaNumber();
let content = "";
try {
let ayalanguage = getUserLanguage();
let response = await axios.get(
`http://api.alquran.cloud/v1/ayah/${randomAyaNumber}/${ayalanguage}.asad`
);
let aya = response.data.data.text;
if (vscode.workspace.getConfiguration("ayat").get("getSuraName") === true) {
let ayaNumber = response.data.data.numberInSurah;
let surahName = response.data.data.surah.name;
content = `${aya}✨
${surahName} (${ayaNumber})
`;
} else {
content = aya;
}
} catch (error) {
content = `✨لا إله إلا أنت سبحانك إني كنت من الظالمين
🔴 غير متصل بالشبكة `;
}
return content;
}
function activate() {
let repeatedEveryMinute = vscode.workspace
.getConfiguration("ayat")
.get("repeatedEveryMinute");
let convertMinuteToMs = repeatedEveryMinute * 60000;
setInterval(async function () {
getRandomAya()
.then(function (response) {
vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: response,
cancellable: true,
},
async (progress) => {
progress.report({ increment: 0 });
await new Promise((resolve) =>
setTimeout(resolve, convertMinuteToMs)
);
progress.report({ increment: 100, message: "Done!" });
}
);
})
.catch(function () {
vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Error while activating Ayat :( ",
cancellable: true,
},
async (progress) => {
progress.report({ increment: 0 });
await new Promise((resolve) =>
setTimeout(resolve, convertMinuteToMs)
);
progress.report({ increment: 100, message: "Done!" });
}
);
});
}, convertMinuteToMs);
}
function deactivate() {}
module.exports = {
activate,
deactivate,
};