@jeniex/utils 1.0.23 → 1.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/index.cjs +24 -0
- package/browser/index.d.ts +4 -1
- package/browser/index.js +23 -1
- package/package.json +1 -1
package/browser/index.cjs
CHANGED
|
@@ -307,6 +307,28 @@ function removeSearchParams(keys, fullURL) {
|
|
|
307
307
|
return updatedURL.join('');
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
async function checkVPN() {
|
|
311
|
+
let pass = false;
|
|
312
|
+
try {
|
|
313
|
+
await fishXResponse('http://192.168.1.1/index.html', { method: 'HEAD' });
|
|
314
|
+
}
|
|
315
|
+
catch (exception) {
|
|
316
|
+
if (exception.message.includes('ended with 0 status')) {
|
|
317
|
+
pass = true;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (pass === false) {
|
|
321
|
+
throw new Error('VPN is not enabled!');
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
async function checkVPNRandomly() {
|
|
325
|
+
// a 1/10 chance to check.
|
|
326
|
+
if (Math.floor(Math.random() * 10) === 0) {
|
|
327
|
+
await checkVPN();
|
|
328
|
+
console.log('%cPass check for VPN!', 'color: #04da79');
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
310
332
|
function addStyle(css, parent = document.documentElement) {
|
|
311
333
|
const style = document.createElement('style');
|
|
312
334
|
style.setAttribute('type', 'text/css');
|
|
@@ -451,6 +473,8 @@ exports.addStyle = addStyle;
|
|
|
451
473
|
exports.alert = alert;
|
|
452
474
|
exports.asserted = asserted;
|
|
453
475
|
exports.capitalize = capitalize;
|
|
476
|
+
exports.checkVPN = checkVPN;
|
|
477
|
+
exports.checkVPNRandomly = checkVPNRandomly;
|
|
454
478
|
exports.confirm = confirm;
|
|
455
479
|
exports.fish = fish;
|
|
456
480
|
exports.fishResponse = fishResponse;
|
package/browser/index.d.ts
CHANGED
|
@@ -112,6 +112,9 @@ declare const logId: string;
|
|
|
112
112
|
/** The initial tab URL on the script run. */
|
|
113
113
|
declare const tabURL: string;
|
|
114
114
|
|
|
115
|
+
declare function checkVPN(): Promise<void>;
|
|
116
|
+
declare function checkVPNRandomly(): Promise<void>;
|
|
117
|
+
|
|
115
118
|
declare function addStyle(css: string, parent?: HTMLElement): HTMLStyleElement;
|
|
116
119
|
|
|
117
120
|
/**
|
|
@@ -153,4 +156,4 @@ type Options = Record<string, FlagValue>;
|
|
|
153
156
|
|
|
154
157
|
declare function getOptions(flags: Flag[]): Promise<Options>;
|
|
155
158
|
|
|
156
|
-
export { $, $$, Flag, Fn, Nullable, Prettify, addStyle, alert, asserted, capitalize, confirm, fish, fishResponse, fishX, fishXResponse, getOptions, getSearchParam, imageLoad, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, logId, noop, padZeros, pageLoad, prompt, remove, removeSearchParams, saveFile, scriptName, setSearchParam, sleep, tabURL, toString };
|
|
159
|
+
export { $, $$, Flag, Fn, Nullable, Prettify, addStyle, alert, asserted, capitalize, checkVPN, checkVPNRandomly, confirm, fish, fishResponse, fishX, fishXResponse, getOptions, getSearchParam, imageLoad, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, logId, noop, padZeros, pageLoad, prompt, remove, removeSearchParams, saveFile, scriptName, setSearchParam, sleep, tabURL, toString };
|
package/browser/index.js
CHANGED
|
@@ -305,6 +305,28 @@ function removeSearchParams(keys, fullURL) {
|
|
|
305
305
|
return updatedURL.join('');
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
+
async function checkVPN() {
|
|
309
|
+
let pass = false;
|
|
310
|
+
try {
|
|
311
|
+
await fishXResponse('http://192.168.1.1/index.html', { method: 'HEAD' });
|
|
312
|
+
}
|
|
313
|
+
catch (exception) {
|
|
314
|
+
if (exception.message.includes('ended with 0 status')) {
|
|
315
|
+
pass = true;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (pass === false) {
|
|
319
|
+
throw new Error('VPN is not enabled!');
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async function checkVPNRandomly() {
|
|
323
|
+
// a 1/10 chance to check.
|
|
324
|
+
if (Math.floor(Math.random() * 10) === 0) {
|
|
325
|
+
await checkVPN();
|
|
326
|
+
console.log('%cPass check for VPN!', 'color: #04da79');
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
308
330
|
function addStyle(css, parent = document.documentElement) {
|
|
309
331
|
const style = document.createElement('style');
|
|
310
332
|
style.setAttribute('type', 'text/css');
|
|
@@ -443,4 +465,4 @@ async function getOptions(flags) {
|
|
|
443
465
|
return options;
|
|
444
466
|
}
|
|
445
467
|
|
|
446
|
-
export { $, $$, addStyle, alert, asserted, capitalize, confirm, fish, fishResponse, fishX, fishXResponse, getOptions, getSearchParam, imageLoad, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, logId, noop, padZeros, pageLoad, prompt, remove, removeSearchParams, saveFile, scriptName, setSearchParam, sleep, tabURL, toString };
|
|
468
|
+
export { $, $$, addStyle, alert, asserted, capitalize, checkVPN, checkVPNRandomly, confirm, fish, fishResponse, fishX, fishXResponse, getOptions, getSearchParam, imageLoad, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, logId, noop, padZeros, pageLoad, prompt, remove, removeSearchParams, saveFile, scriptName, setSearchParam, sleep, tabURL, toString };
|