@jeniex/utils 1.0.22 → 1.0.24

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 CHANGED
@@ -130,11 +130,11 @@ if (typeof GM !== 'undefined') {
130
130
  infoObject = GM.info;
131
131
  // eslint-disable-next-line unicorn/no-negated-condition
132
132
  }
133
- else if (typeof GM_info !== 'undefined') {
134
- infoObject = GM_info;
133
+ else if (typeof GM_info === 'undefined') {
134
+ infoObject = { script: { name: document.title } };
135
135
  }
136
136
  else {
137
- infoObject = { script: { name: document.title } };
137
+ infoObject = GM_info;
138
138
  }
139
139
  const scriptName = infoObject.script.name;
140
140
  /** The identifier of the script to be used in logging. */
@@ -307,6 +307,27 @@ function removeSearchParams(keys, fullURL) {
307
307
  return updatedURL.join('');
308
308
  }
309
309
 
310
+ async function checkVPN() {
311
+ let pass;
312
+ try {
313
+ await fishXResponse('http://192.168.1.1/index.html', { method: 'HEAD' });
314
+ pass = false;
315
+ }
316
+ catch {
317
+ pass = true;
318
+ }
319
+ if (pass === false) {
320
+ throw new Error('VPN is not enabled!');
321
+ }
322
+ }
323
+ async function checkVPNRandomly() {
324
+ // a 1/10 chance to check.
325
+ if (Math.floor(Math.random() * 10) === 0) {
326
+ await checkVPN();
327
+ console.log('%cPass check for VPN!', 'color: #04da79');
328
+ }
329
+ }
330
+
310
331
  function addStyle(css, parent = document.documentElement) {
311
332
  const style = document.createElement('style');
312
333
  style.setAttribute('type', 'text/css');
@@ -361,6 +382,15 @@ async function pageLoad(completely) {
361
382
  });
362
383
  }
363
384
 
385
+ function saveFile(blob, fileName) {
386
+ const blobURL = URL.createObjectURL(blob);
387
+ const link = document.createElement('a');
388
+ link.href = blobURL;
389
+ link.download = fileName;
390
+ link.dispatchEvent(new MouseEvent('click'));
391
+ window.setTimeout(() => window.URL.revokeObjectURL(blobURL), 1000);
392
+ }
393
+
364
394
  function createFlagMessage(flag) {
365
395
  const { message: messageHeader, values, type } = flag;
366
396
  let message = messageHeader;
@@ -442,6 +472,8 @@ exports.addStyle = addStyle;
442
472
  exports.alert = alert;
443
473
  exports.asserted = asserted;
444
474
  exports.capitalize = capitalize;
475
+ exports.checkVPN = checkVPN;
476
+ exports.checkVPNRandomly = checkVPNRandomly;
445
477
  exports.confirm = confirm;
446
478
  exports.fish = fish;
447
479
  exports.fishResponse = fishResponse;
@@ -467,6 +499,7 @@ exports.pageLoad = pageLoad;
467
499
  exports.prompt = prompt;
468
500
  exports.remove = remove;
469
501
  exports.removeSearchParams = removeSearchParams;
502
+ exports.saveFile = saveFile;
470
503
  exports.scriptName = scriptName;
471
504
  exports.setSearchParam = setSearchParam;
472
505
  exports.sleep = sleep;
@@ -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
  /**
@@ -125,6 +128,8 @@ declare function imageLoad(img: HTMLImageElement): Promise<void>;
125
128
  */
126
129
  declare function pageLoad(completely?: boolean): Promise<void>;
127
130
 
131
+ declare function saveFile(blob: Blob, fileName: string): void;
132
+
128
133
  interface FlagBase {
129
134
  name: string;
130
135
  message: string;
@@ -151,4 +156,4 @@ type Options = Record<string, FlagValue>;
151
156
 
152
157
  declare function getOptions(flags: Flag[]): Promise<Options>;
153
158
 
154
- 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, 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
@@ -128,11 +128,11 @@ if (typeof GM !== 'undefined') {
128
128
  infoObject = GM.info;
129
129
  // eslint-disable-next-line unicorn/no-negated-condition
130
130
  }
131
- else if (typeof GM_info !== 'undefined') {
132
- infoObject = GM_info;
131
+ else if (typeof GM_info === 'undefined') {
132
+ infoObject = { script: { name: document.title } };
133
133
  }
134
134
  else {
135
- infoObject = { script: { name: document.title } };
135
+ infoObject = GM_info;
136
136
  }
137
137
  const scriptName = infoObject.script.name;
138
138
  /** The identifier of the script to be used in logging. */
@@ -305,6 +305,27 @@ function removeSearchParams(keys, fullURL) {
305
305
  return updatedURL.join('');
306
306
  }
307
307
 
308
+ async function checkVPN() {
309
+ let pass;
310
+ try {
311
+ await fishXResponse('http://192.168.1.1/index.html', { method: 'HEAD' });
312
+ pass = false;
313
+ }
314
+ catch {
315
+ pass = true;
316
+ }
317
+ if (pass === false) {
318
+ throw new Error('VPN is not enabled!');
319
+ }
320
+ }
321
+ async function checkVPNRandomly() {
322
+ // a 1/10 chance to check.
323
+ if (Math.floor(Math.random() * 10) === 0) {
324
+ await checkVPN();
325
+ console.log('%cPass check for VPN!', 'color: #04da79');
326
+ }
327
+ }
328
+
308
329
  function addStyle(css, parent = document.documentElement) {
309
330
  const style = document.createElement('style');
310
331
  style.setAttribute('type', 'text/css');
@@ -359,6 +380,15 @@ async function pageLoad(completely) {
359
380
  });
360
381
  }
361
382
 
383
+ function saveFile(blob, fileName) {
384
+ const blobURL = URL.createObjectURL(blob);
385
+ const link = document.createElement('a');
386
+ link.href = blobURL;
387
+ link.download = fileName;
388
+ link.dispatchEvent(new MouseEvent('click'));
389
+ window.setTimeout(() => window.URL.revokeObjectURL(blobURL), 1000);
390
+ }
391
+
362
392
  function createFlagMessage(flag) {
363
393
  const { message: messageHeader, values, type } = flag;
364
394
  let message = messageHeader;
@@ -434,4 +464,4 @@ async function getOptions(flags) {
434
464
  return options;
435
465
  }
436
466
 
437
- 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, scriptName, setSearchParam, sleep, tabURL, toString };
467
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeniex/utils",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "author": "JenieX",
5
5
  "homepage": "https://github.com/JenieX/utils",
6
6
  "type": "module",