-
Notifications
You must be signed in to change notification settings - Fork 0
Collapse file tree
Files
Search this repository(forward slash) forward slash/
/
Copy pathoptions.js
More file actions
More file actions
Latest commit
1058 lines (873 loc) · 21.7 KB
/
Copy pathoptions.js
File metadata and controls
1058 lines (873 loc) · 21.7 KB
You must be signed in to make or propose changes
More edit options
Edit and raw actions
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
"use strict";
const api = globalThis.browser ?? globalThis.chrome;
const SOURCE_BASE =
"https:" + "//raw.githubusercontent.com/Fengsemul/2/main/";
const SOURCE_FILES = Object.freeze([
"1.txt",
"2.txt",
"3.txt",
"4.txt",
"5.txt",
"6.txt",
"7.txt",
"8.txt",
"9.txt",
"a.txt",
"b.txt",
"c.txt",
"cdn",
"d.txt",
"e.txt",
"f.txt",
"g.txt"
]);
const SOURCE_URLS = Object.freeze(
SOURCE_FILES.map((name) => SOURCE_BASE + name)
);
const IMPORT_BATCH_SIZE = 2000;
const MAX_LINE_LENGTH = 1048576;
const MAX_LABEL_LENGTH = 63;
const indexStatusOutput =
document.querySelector("#index-status");
const domainCountOutput =
document.querySelector("#domain-count");
const generationOutput =
document.querySelector("#generation");
const importedAtOutput =
document.querySelector("#imported-at");
const sourceCountOutput =
document.querySelector("#source-count");
const enabledInput =
document.querySelector("#enabled");
const includeSubdomainsInput =
document.querySelector("#include-subdomains");
const startImportButton =
document.querySelector("#start-import");
const resumeImportButton =
document.querySelector("#resume-import");
const abandonImportButton =
document.querySelector("#abandon-import");
const clearDataButton =
document.querySelector("#clear-data");
const progressElement =
document.querySelector("#progress");
const progressTextOutput =
document.querySelector("#progress-text");
let importRunning = false;
let cancellationRequested = false;
let activeImportId = null;
let activeFetchController = null;
let savedImportState = null;
function formatInteger(value) {
const number = Number(value);
if (!Number.isFinite(number)) {
return "-";
}
return new Intl.NumberFormat().format(number);
}
function formatDate(value) {
if (!value) {
return "-";
}
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return String(value);
}
return date.toLocaleString();
}
function errorMessage(error) {
if (error instanceof Error) {
return error.message;
}
return String(error);
}
function createImportId() {
if (
globalThis.crypto &&
typeof globalThis.crypto.randomUUID === "function"
) {
return globalThis.crypto
.randomUUID()
.replaceAll("-", "");
}
return (
Date.now().toString(36) +
Math.random().toString(36).slice(2) +
Math.random().toString(36).slice(2)
);
}
function sourceConfigurationMatches(importState) {
if (!importState) {
return false;
}
if (
importState.expectedSourceCount !==
SOURCE_FILES.length
) {
return false;
}
if (!Array.isArray(importState.sourceNames)) {
return false;
}
return (
JSON.stringify(importState.sourceNames) ===
JSON.stringify(SOURCE_FILES)
);
}
function setControls() {
const resumable =
!importRunning &&
savedImportState?.status === "building";
startImportButton.disabled =
startImportButton.addEventListener(
"click",
() => {
startNewImport().catch((error) => {
console.error(error);
progressTextOutput.textContent =
"Could not start import: " +
errorMessage(error);
importRunning = false;
setControls();
});
}
);
resumeImportButton.addEventListener(
"click",
() => {
resumeSavedImport().catch((error) => {
console.error(error);
progressTextOutput.textContent =
"Could not resume import: " +
errorMessage(error);
importRunning = false;
setControls();
});
}
);
abandonImportButton.addEventListener(
"click",
() => {
const operation = importRunning
? pauseImport()
: abandonSavedImport();
operation.catch((error) => {
console.error(error);
progressTextOutput.textContent =
"Could not update the import: " +
errorMessage(error);
setControls();
});
}
);
clearDataButton.addEventListener(
"click",
() => {
clearData().catch((error) => {
console.error(error);
progressTextOutput.textContent =
"Could not delete index: " +
errorMessage(error);
setControls();
});
}
);
globalThis.addEventListener(
"beforeunload",
warnBeforeClosing
);
sourceCountOutput.textContent =
formatInteger(SOURCE_FILES.length);
refreshStatus().catch((error) => {
console.error(error);
indexStatusOutput.textContent =
"Could not contact the extension background process.";
progressTextOutput.textContent =
errorMessage(error);
setControls();
});