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