-
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
1968 lines (1730 loc) · 38.8 KB
/
Copy pathoptions.js
File metadata and controls
1968 lines (1730 loc) · 38.8 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
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
"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 = 1024 * 1024;
const MAX_LABEL_LENGTH = 63;
const MAX_REJECTION_SAMPLES = 20;
const indexStatusOutput =
document.querySelector("#index-status");
const labelCountOutput =
document.querySelector("#label-count");
const activeGenerationOutput =
document.querySelector("#active-generation");
const previousGenerationOutput =
document.querySelector("#previous-generation");
const importedAtOutput =
document.querySelector("#imported-at");
const sourceCountOutput =
document.querySelector("#source-count");
const publicSuffixStatusOutput =
document.querySelector("#psl-status");
const enabledInput =
document.querySelector("#enabled");
const protectedLabelsInput =
document.querySelector("#protected-labels");
const saveSettingsButton =
document.querySelector("#save-settings");
const startImportButton =
document.querySelector("#start-import");
const resumeImportButton =
document.querySelector("#resume-import");
const pauseImportButton =
document.querySelector("#pause-import");
const abandonImportButton =
document.querySelector("#abandon-import");
const progressElement =
document.querySelector("#progress");
const progressTextOutput =
document.querySelector("#progress-text");
const currentSourceOutput =
document.querySelector("#current-source");
const completedSourcesOutput =
document.querySelector("#completed-sources");
const acceptedCountOutput =
document.querySelector("#accepted-count");
const rejectedCountOutput =
document.querySelector("#rejected-count");
const rejectionSummaryElement =
document.querySelector("#rejection-summary");
const rejectionSamplesElement =
document.querySelector("#rejection-samples");
const cleanUnusedButton =
document.querySelector("#clean-unused");
const deletePreviousButton =
document.querySelector("#delete-previous");
const clearDataButton =
document.querySelector("#clear-data");
const maintenanceStatusOutput =
document.querySelector("#maintenance-status");
let importRunning = false;
let pauseRequested = false;
let activeImportId = null;
let activeFetchController = null;
let savedImportState = null;
let latestStatus = 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 setOutputStatus(
output,
message,
kind = ""
) {
output.textContent = message;
output.classList.remove(
"status-success",
"status-error"
);
errorMessage(error),
"error"
);
setControls();
}
);
}
);
cleanUnusedButton.addEventListener(
"click",
() => {
cleanUnusedDatabases().catch(
(error) => {
console.error(error);
setOutputStatus(
maintenanceStatusOutput,
"Could not clean unused databases: " +
errorMessage(error),
"error"
);
setControls();
}
);
}
);
deletePreviousButton.addEventListener(
"click",
() => {
deletePreviousGeneration().catch(
(error) => {
console.error(error);
setOutputStatus(
maintenanceStatusOutput,
"Could not delete the previous generation: " +
errorMessage(error),
"error"
);
setControls();
}
);
}
);
clearDataButton.addEventListener(
"click",
() => {
clearAllData().catch((error) => {
console.error(error);
setOutputStatus(
maintenanceStatusOutput,
"Could not delete index data: " +
errorMessage(error),
"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.";
setOutputStatus(
progressTextOutput,
errorMessage(error),
"error"
);
setControls();
});