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