@jeniex/utils 1.0.26 → 1.1.2

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
@@ -125,18 +125,7 @@ function capitalize(sentence) {
125
125
  return capitalizeWord(sentence);
126
126
  }
127
127
 
128
- let infoObject;
129
- if (typeof GM !== 'undefined') {
130
- infoObject = GM.info;
131
- // eslint-disable-next-line unicorn/no-negated-condition
132
- }
133
- else if (typeof GM_info === 'undefined') {
134
- infoObject = { script: { name: document.title } };
135
- }
136
- else {
137
- infoObject = GM_info;
138
- }
139
- const scriptName = infoObject.script.name;
128
+ const scriptName = GM.info.script.name;
140
129
  /** The identifier of the script to be used in logging. */
141
130
  const logId = `[${scriptName}]:`;
142
131
  /** The initial tab URL on the script run. */
@@ -261,8 +250,7 @@ function $$(selectors, parent) {
261
250
  * @param fullURL If provided, it will be our target, otherwise it is the current location.
262
251
  */
263
252
  function getSearchParam(key, fullURL) {
264
- const { search } = new URL(fullURL ?? window.location.href);
265
- const searchParams = new URLSearchParams(search);
253
+ const { searchParams } = new URL(fullURL ?? window.location.href);
266
254
  const value = searchParams.get(key);
267
255
  if (value === null) {
268
256
  return undefined;
@@ -373,7 +361,7 @@ async function imageLoad(img) {
373
361
  * Waits for the page to load.
374
362
  * @param completely Whether or not to wait for resources to load as well.
375
363
  */
376
- async function pageLoad(completely = false) {
364
+ async function pageLoad(completely) {
377
365
  return new Promise((resolve) => {
378
366
  if (document.readyState === 'complete') {
379
367
  resolve();
@@ -471,6 +459,16 @@ async function getOptions(flags) {
471
459
  return options;
472
460
  }
473
461
 
462
+ function customizeConsole(debug = false) {
463
+ const base = window.console;
464
+ return {
465
+ log: base.log.bind(base, logId),
466
+ warn: base.warn.bind(base, logId),
467
+ error: base.error.bind(base, logId),
468
+ debug: debug ? base.log.bind(base, logId) : noop,
469
+ };
470
+ }
471
+
474
472
  exports.$ = $;
475
473
  exports.$$ = $$;
476
474
  exports.addStyle = addStyle;
@@ -480,6 +478,7 @@ exports.capitalize = capitalize;
480
478
  exports.checkVPN = checkVPN;
481
479
  exports.checkVPNRandomly = checkVPNRandomly;
482
480
  exports.confirm = confirm;
481
+ exports.customizeConsole = customizeConsole;
483
482
  exports.fish = fish;
484
483
  exports.fishResponse = fishResponse;
485
484
  exports.fishX = fishX;
@@ -160,4 +160,13 @@ type Options = Record<string, FlagValue>;
160
160
 
161
161
  declare function getOptions(flags: Flag[]): Promise<Options>;
162
162
 
163
- 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 };
163
+ interface CustomizedConsole {
164
+ log: Console['log'];
165
+ warn: Console['warn'];
166
+ error: Console['error'];
167
+ debug: Console['debug'];
168
+ }
169
+
170
+ declare function customizeConsole(debug?: boolean): CustomizedConsole;
171
+
172
+ export { $, $$, Flag, Fn, Nullable, Prettify, addStyle, alert, asserted, capitalize, checkVPN, checkVPNRandomly, confirm, customizeConsole, 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
@@ -123,18 +123,7 @@ function capitalize(sentence) {
123
123
  return capitalizeWord(sentence);
124
124
  }
125
125
 
126
- let infoObject;
127
- if (typeof GM !== 'undefined') {
128
- infoObject = GM.info;
129
- // eslint-disable-next-line unicorn/no-negated-condition
130
- }
131
- else if (typeof GM_info === 'undefined') {
132
- infoObject = { script: { name: document.title } };
133
- }
134
- else {
135
- infoObject = GM_info;
136
- }
137
- const scriptName = infoObject.script.name;
126
+ const scriptName = GM.info.script.name;
138
127
  /** The identifier of the script to be used in logging. */
139
128
  const logId = `[${scriptName}]:`;
140
129
  /** The initial tab URL on the script run. */
@@ -259,8 +248,7 @@ function $$(selectors, parent) {
259
248
  * @param fullURL If provided, it will be our target, otherwise it is the current location.
260
249
  */
261
250
  function getSearchParam(key, fullURL) {
262
- const { search } = new URL(fullURL ?? window.location.href);
263
- const searchParams = new URLSearchParams(search);
251
+ const { searchParams } = new URL(fullURL ?? window.location.href);
264
252
  const value = searchParams.get(key);
265
253
  if (value === null) {
266
254
  return undefined;
@@ -371,7 +359,7 @@ async function imageLoad(img) {
371
359
  * Waits for the page to load.
372
360
  * @param completely Whether or not to wait for resources to load as well.
373
361
  */
374
- async function pageLoad(completely = false) {
362
+ async function pageLoad(completely) {
375
363
  return new Promise((resolve) => {
376
364
  if (document.readyState === 'complete') {
377
365
  resolve();
@@ -469,4 +457,14 @@ async function getOptions(flags) {
469
457
  return options;
470
458
  }
471
459
 
472
- 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 };
460
+ function customizeConsole(debug = false) {
461
+ const base = window.console;
462
+ return {
463
+ log: base.log.bind(base, logId),
464
+ warn: base.warn.bind(base, logId),
465
+ error: base.error.bind(base, logId),
466
+ debug: debug ? base.log.bind(base, logId) : noop,
467
+ };
468
+ }
469
+
470
+ export { $, $$, addStyle, alert, asserted, capitalize, checkVPN, checkVPNRandomly, confirm, customizeConsole, 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.26",
3
+ "version": "1.1.2",
4
4
  "author": "JenieX",
5
5
  "homepage": "https://github.com/JenieX/utils",
6
6
  "type": "module",