@whitesev/utils 2.3.2 → 2.3.4

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/dist/index.cjs.js CHANGED
@@ -1755,6 +1755,8 @@ class Httpx {
1755
1755
  data: details.data || this.context.#defaultDetails.data,
1756
1756
  redirect: details.redirect || this.context.#defaultDetails.redirect,
1757
1757
  cookie: details.cookie || this.context.#defaultDetails.cookie,
1758
+ cookiePartition: details.cookiePartition ||
1759
+ this.context.#defaultDetails.cookiePartition,
1758
1760
  binary: details.binary || this.context.#defaultDetails.binary,
1759
1761
  nocache: details.nocache || this.context.#defaultDetails.nocache,
1760
1762
  revalidate: details.revalidate || this.context.#defaultDetails.revalidate,
@@ -1856,6 +1858,15 @@ class Httpx {
1856
1858
  else {
1857
1859
  result.fetchInit = details.fetchInit;
1858
1860
  }
1861
+ // 处理新的cookiePartition
1862
+ if (typeof result.cookiePartition === "object" &&
1863
+ result.cookiePartition != null) {
1864
+ if (Reflect.has(result.cookiePartition, "topLevelSite") &&
1865
+ typeof result.cookiePartition.topLevelSite !== "string") {
1866
+ // topLevelSite必须是字符串
1867
+ Reflect.deleteProperty(result.cookiePartition, "topLevelSite");
1868
+ }
1869
+ }
1859
1870
  return result;
1860
1871
  },
1861
1872
  /**
@@ -2345,6 +2356,7 @@ class Httpx {
2345
2356
  data: void 0,
2346
2357
  redirect: void 0,
2347
2358
  cookie: void 0,
2359
+ cookiePartition: void 0,
2348
2360
  binary: void 0,
2349
2361
  nocache: void 0,
2350
2362
  revalidate: void 0,
@@ -3104,6 +3116,9 @@ class Log {
3104
3116
  autoClearConsole: false,
3105
3117
  logMaxCount: 999,
3106
3118
  };
3119
+ /**
3120
+ * 颜色配置
3121
+ */
3107
3122
  #msgColorDetails = [
3108
3123
  "font-weight: bold; color: cornflowerblue",
3109
3124
  "font-weight: bold; color: cornflowerblue",
@@ -3111,16 +3126,16 @@ class Log {
3111
3126
  "font-weight: bold; color: cornflowerblue",
3112
3127
  ];
3113
3128
  /**
3114
- * @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串
3129
+ * @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
3115
3130
  * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
3116
3131
  */
3117
- constructor(_GM_info_, console = window.console) {
3118
- if (typeof _GM_info_ === "string") {
3119
- this.tag = _GM_info_;
3132
+ constructor(__GM_info, console = window.console) {
3133
+ if (typeof __GM_info === "string") {
3134
+ this.tag = __GM_info;
3120
3135
  }
3121
- else if (typeof _GM_info_ === "object" &&
3122
- typeof _GM_info_?.script?.name === "string") {
3123
- this.tag = _GM_info_.script.name;
3136
+ else if (typeof __GM_info === "object" &&
3137
+ typeof __GM_info?.script?.name === "string") {
3138
+ this.tag = __GM_info.script.name;
3124
3139
  }
3125
3140
  this.#console = console;
3126
3141
  }
@@ -3195,24 +3210,33 @@ class Log {
3195
3210
  let { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
3196
3211
  let tagName = this.tag;
3197
3212
  let that = this;
3198
- function consoleMsg(_msg_) {
3199
- if (typeof _msg_ === "string") {
3200
- that.#console.log(`%c[${tagName}%c-%c${callerName}%c]%c %s`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, _msg_);
3213
+ /** tag的html输出格式 */
3214
+ let tagNameHTML = `%c[${tagName}%c`;
3215
+ /** 调用的函数名的html输出格式 */
3216
+ let callerNameHTML = `%c${callerName}%c]%c`;
3217
+ callerName.trim() !== "" && (callerNameHTML = "-" + callerNameHTML);
3218
+ /**
3219
+ * 输出消息到控制台
3220
+ * @param message
3221
+ */
3222
+ function consoleMsg(message) {
3223
+ if (typeof message === "string") {
3224
+ that.#console.log(`${tagNameHTML}${callerNameHTML} %s`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
3201
3225
  }
3202
- else if (typeof _msg_ === "number") {
3203
- that.#console.log(`%c[${tagName}%c-%c${callerName}%c]%c %d`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, _msg_);
3226
+ else if (typeof message === "number") {
3227
+ that.#console.log(`${tagNameHTML}${callerNameHTML} %d`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
3204
3228
  }
3205
- else if (typeof _msg_ === "object") {
3206
- that.#console.log(`%c[${tagName}%c-%c${callerName}%c]%c %o`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, _msg_);
3229
+ else if (typeof message === "object") {
3230
+ that.#console.log(`${tagNameHTML}${callerNameHTML} %o`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
3207
3231
  }
3208
3232
  else {
3209
- that.#console.log(_msg_);
3233
+ that.#console.log(message);
3210
3234
  }
3211
3235
  }
3212
3236
  if (Array.isArray(msg)) {
3213
- msg.forEach((item) => {
3214
- consoleMsg(item);
3215
- });
3237
+ for (let index = 0; index < msg.length; index++) {
3238
+ consoleMsg(msg[index]);
3239
+ }
3216
3240
  }
3217
3241
  else {
3218
3242
  consoleMsg(msg);
@@ -3224,67 +3248,67 @@ class Log {
3224
3248
  }
3225
3249
  /**
3226
3250
  * 控制台-普通输出
3227
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
3228
- * @param color 输出的颜色
3229
- * @param otherStyle 其它CSS
3251
+ * @param args 需要输出的内容
3252
+ * @example
3253
+ * log.info("输出信息","输出信息2","输出信息3","输出")
3230
3254
  */
3231
- info(msg, color = this.#details.infoColor, otherStyle) {
3255
+ info(...args) {
3232
3256
  if (this.#disable)
3233
3257
  return;
3234
- this.printContent.call(this, msg, color, otherStyle);
3258
+ this.printContent(args, this.#details.infoColor);
3235
3259
  }
3236
3260
  /**
3237
3261
  * 控制台-警告输出
3238
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
3239
- * @param color 输出的颜色
3240
- * @param otherStyle 其它CSS
3262
+ * @param args 需要输出的内容
3263
+ * @example
3264
+ * log.warn("输出警告","输出警告2","输出警告3","输出警告4")
3241
3265
  */
3242
- warn(msg, color = this.#details.warnColor, otherStyle = "background: #FEF6D5;padding: 4px 6px 4px 0px;") {
3266
+ warn(...args) {
3243
3267
  if (this.#disable)
3244
3268
  return;
3245
- this.printContent.call(this, msg, color, otherStyle);
3269
+ this.printContent(args, this.#details.warnColor, "background: #FEF6D5;padding: 4px 6px 4px 0px;");
3246
3270
  }
3247
3271
  /**
3248
3272
  * 控制台-错误输出
3249
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
3250
- * @param color 输出的颜色
3251
- * @param otherStyle 其它CSS
3273
+ * @param args 需要输出的内容
3274
+ * @example
3275
+ * log.error("输出错误","输出错误2","输出错误3","输出错误4")
3252
3276
  */
3253
- error(msg, color = this.#details.errorColor, otherStyle) {
3277
+ error(...args) {
3254
3278
  if (this.#disable)
3255
3279
  return;
3256
- this.printContent.call(this, msg, color, otherStyle);
3280
+ this.printContent(args, this.#details.errorColor);
3257
3281
  }
3258
3282
  /**
3259
3283
  * 控制台-成功输出
3260
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
3261
- * @param color 输出的颜色
3262
- * @param otherStyle 其它CSS
3284
+ * @param args 需要输出的内容
3285
+ * @example
3286
+ * log.success("输出成功")
3263
3287
  */
3264
- success(msg, color = this.#details.successColor, otherStyle) {
3288
+ success(...args) {
3265
3289
  if (this.#disable)
3266
3290
  return;
3267
- this.printContent.call(this, msg, color, otherStyle);
3291
+ this.printContent(args, this.#details.successColor);
3268
3292
  }
3269
3293
  /**
3270
3294
  * 控制台-输出表格
3271
- * @param msg
3272
- * @param color 输出的颜色
3273
- * @param otherStyle 其它CSS
3295
+ * @param msg 需要输出的内容
3274
3296
  * @example
3275
3297
  * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
3276
3298
  */
3277
- table(msg, color = this.#details.infoColor, otherStyle = "") {
3299
+ table(msg) {
3278
3300
  if (this.#disable)
3279
3301
  return;
3280
3302
  this.checkClearConsole();
3281
3303
  let stack = new Error().stack.split("\n");
3282
3304
  stack.splice(0, 1);
3283
3305
  let errorStackParse = this.parseErrorStack(stack);
3306
+ /** 堆栈函数名 */
3284
3307
  let stackFunctionName = errorStackParse.name;
3308
+ /** 堆栈位置 */
3285
3309
  let stackFunctionNamePosition = errorStackParse.position;
3286
3310
  let callerName = stackFunctionName;
3287
- this.#console.log(`%c[${this.tag}%c-%c${callerName}%c]%c`, ...this.#msgColorDetails, `color: ${color};${otherStyle}`);
3311
+ this.#console.log(`%c[${this.tag}%c-%c${callerName}%c]%c`, ...this.#msgColorDetails, `color: ${this.#details.infoColor};`);
3288
3312
  this.#console.table(msg);
3289
3313
  if (this.#details.debug) {
3290
3314
  this.#console.log(stackFunctionNamePosition);
@@ -3928,7 +3952,7 @@ class Utils {
3928
3952
  this.windowApi = new WindowApi(option);
3929
3953
  }
3930
3954
  /** 版本号 */
3931
- version = "2024.9.10";
3955
+ version = "2024.9.28";
3932
3956
  addStyle(cssText) {
3933
3957
  if (typeof cssText !== "string") {
3934
3958
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");