@sv443-network/userutils 6.1.0 → 6.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @sv443-network/userutils
2
2
 
3
+ ## 6.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0173235: Add property to change the debounce edge in `SelectorObserver` instances
8
+
3
9
  ## 6.1.0
4
10
 
5
11
  ### Minor Changes
@@ -8,7 +8,7 @@
8
8
  // ==UserLibrary==
9
9
  // @name UserUtils
10
10
  // @description Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, manage persistent user configurations, modify the DOM more easily and more
11
- // @version 6.1.0
11
+ // @version 6.2.0
12
12
  // @license MIT
13
13
  // @copyright Sv443 (https://github.com/Sv443)
14
14
 
@@ -512,10 +512,12 @@ var UserUtils = (function (exports) {
512
512
  this.observer = new MutationObserver(() => this.checkAllSelectors());
513
513
  const _a = options, {
514
514
  defaultDebounce,
515
+ defaultDebounceEdge,
515
516
  disableOnNoListeners,
516
517
  enableOnAddListener
517
518
  } = _a, observerOptions = __objRest(_a, [
518
519
  "defaultDebounce",
520
+ "defaultDebounceEdge",
519
521
  "disableOnNoListeners",
520
522
  "enableOnAddListener"
521
523
  ]);
@@ -525,6 +527,7 @@ var UserUtils = (function (exports) {
525
527
  }, observerOptions);
526
528
  this.customOptions = {
527
529
  defaultDebounce: defaultDebounce != null ? defaultDebounce : 0,
530
+ defaultDebounceEdge: defaultDebounceEdge != null ? defaultDebounceEdge : "rising",
528
531
  disableOnNoListeners: disableOnNoListeners != null ? disableOnNoListeners : false,
529
532
  enableOnAddListener: enableOnAddListener != null ? enableOnAddListener : true
530
533
  };
@@ -564,12 +567,8 @@ var UserUtils = (function (exports) {
564
567
  this.disable();
565
568
  }
566
569
  }
567
- debounce(func, time) {
568
- let timeout;
569
- return function(...args) {
570
- clearTimeout(timeout);
571
- timeout = setTimeout(() => func.apply(this, args), time);
572
- };
570
+ debounce(func, time, edge = "falling") {
571
+ return debounce(func, time, edge);
573
572
  }
574
573
  /**
575
574
  * Starts observing the children of the base element for changes to the given {@linkcode selector} according to the set {@linkcode options}
@@ -585,7 +584,8 @@ var UserUtils = (function (exports) {
585
584
  if (options.debounce && options.debounce > 0 || this.customOptions.defaultDebounce && this.customOptions.defaultDebounce > 0) {
586
585
  options.listener = this.debounce(
587
586
  options.listener,
588
- options.debounce || this.customOptions.defaultDebounce
587
+ options.debounce || this.customOptions.defaultDebounce,
588
+ options.debounceEdge || this.customOptions.defaultDebounceEdge
589
589
  );
590
590
  }
591
591
  if (this.listenerMap.has(selector))
package/dist/index.js CHANGED
@@ -492,10 +492,12 @@ var SelectorObserver = class {
492
492
  this.observer = new MutationObserver(() => this.checkAllSelectors());
493
493
  const _a = options, {
494
494
  defaultDebounce,
495
+ defaultDebounceEdge,
495
496
  disableOnNoListeners,
496
497
  enableOnAddListener
497
498
  } = _a, observerOptions = __objRest(_a, [
498
499
  "defaultDebounce",
500
+ "defaultDebounceEdge",
499
501
  "disableOnNoListeners",
500
502
  "enableOnAddListener"
501
503
  ]);
@@ -505,6 +507,7 @@ var SelectorObserver = class {
505
507
  }, observerOptions);
506
508
  this.customOptions = {
507
509
  defaultDebounce: defaultDebounce != null ? defaultDebounce : 0,
510
+ defaultDebounceEdge: defaultDebounceEdge != null ? defaultDebounceEdge : "rising",
508
511
  disableOnNoListeners: disableOnNoListeners != null ? disableOnNoListeners : false,
509
512
  enableOnAddListener: enableOnAddListener != null ? enableOnAddListener : true
510
513
  };
@@ -544,12 +547,8 @@ var SelectorObserver = class {
544
547
  this.disable();
545
548
  }
546
549
  }
547
- debounce(func, time) {
548
- let timeout;
549
- return function(...args) {
550
- clearTimeout(timeout);
551
- timeout = setTimeout(() => func.apply(this, args), time);
552
- };
550
+ debounce(func, time, edge = "falling") {
551
+ return debounce(func, time, edge);
553
552
  }
554
553
  /**
555
554
  * Starts observing the children of the base element for changes to the given {@linkcode selector} according to the set {@linkcode options}
@@ -565,7 +564,8 @@ var SelectorObserver = class {
565
564
  if (options.debounce && options.debounce > 0 || this.customOptions.defaultDebounce && this.customOptions.defaultDebounce > 0) {
566
565
  options.listener = this.debounce(
567
566
  options.listener,
568
- options.debounce || this.customOptions.defaultDebounce
567
+ options.debounce || this.customOptions.defaultDebounce,
568
+ options.debounceEdge || this.customOptions.defaultDebounceEdge
569
569
  );
570
570
  }
571
571
  if (this.listenerMap.has(selector))
package/dist/index.mjs CHANGED
@@ -490,10 +490,12 @@ var SelectorObserver = class {
490
490
  this.observer = new MutationObserver(() => this.checkAllSelectors());
491
491
  const _a = options, {
492
492
  defaultDebounce,
493
+ defaultDebounceEdge,
493
494
  disableOnNoListeners,
494
495
  enableOnAddListener
495
496
  } = _a, observerOptions = __objRest(_a, [
496
497
  "defaultDebounce",
498
+ "defaultDebounceEdge",
497
499
  "disableOnNoListeners",
498
500
  "enableOnAddListener"
499
501
  ]);
@@ -503,6 +505,7 @@ var SelectorObserver = class {
503
505
  }, observerOptions);
504
506
  this.customOptions = {
505
507
  defaultDebounce: defaultDebounce != null ? defaultDebounce : 0,
508
+ defaultDebounceEdge: defaultDebounceEdge != null ? defaultDebounceEdge : "rising",
506
509
  disableOnNoListeners: disableOnNoListeners != null ? disableOnNoListeners : false,
507
510
  enableOnAddListener: enableOnAddListener != null ? enableOnAddListener : true
508
511
  };
@@ -542,12 +545,8 @@ var SelectorObserver = class {
542
545
  this.disable();
543
546
  }
544
547
  }
545
- debounce(func, time) {
546
- let timeout;
547
- return function(...args) {
548
- clearTimeout(timeout);
549
- timeout = setTimeout(() => func.apply(this, args), time);
550
- };
548
+ debounce(func, time, edge = "falling") {
549
+ return debounce(func, time, edge);
551
550
  }
552
551
  /**
553
552
  * Starts observing the children of the base element for changes to the given {@linkcode selector} according to the set {@linkcode options}
@@ -563,7 +562,8 @@ var SelectorObserver = class {
563
562
  if (options.debounce && options.debounce > 0 || this.customOptions.defaultDebounce && this.customOptions.defaultDebounce > 0) {
564
563
  options.listener = this.debounce(
565
564
  options.listener,
566
- options.debounce || this.customOptions.defaultDebounce
565
+ options.debounce || this.customOptions.defaultDebounce,
566
+ options.debounceEdge || this.customOptions.defaultDebounceEdge
567
567
  );
568
568
  }
569
569
  if (this.listenerMap.has(selector))
@@ -17,10 +17,17 @@ type SelectorOptionsCommon = {
17
17
  continuous?: boolean;
18
18
  /** Whether to debounce the listener to reduce calls to `querySelector` or `querySelectorAll` - set undefined or <=0 to disable (default) */
19
19
  debounce?: number;
20
+ /** Whether to call the function at the very first call ("rising" edge) or the very last call ("falling" edge, default) */
21
+ debounceEdge?: "rising" | "falling";
20
22
  };
21
23
  export type SelectorObserverOptions = {
22
24
  /** If set, applies this debounce in milliseconds to all listeners that don't have their own debounce set */
23
25
  defaultDebounce?: number;
26
+ /**
27
+ * If set, applies this debounce edge to all listeners that don't have their own set.
28
+ * Edge = Whether to call the function at the very first call ("rising" edge) or the very last call ("falling" edge, default)
29
+ */
30
+ defaultDebounceEdge?: "rising" | "falling";
24
31
  /** Whether to disable the observer when no listeners are present - default is true */
25
32
  disableOnNoListeners?: boolean;
26
33
  /** Whether to ensure the observer is enabled when a new listener is added - default is true */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sv443-network/userutils",
3
3
  "libName": "UserUtils",
4
- "version": "6.1.0",
4
+ "version": "6.2.0",
5
5
  "description": "Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, manage persistent user configurations, modify the DOM more easily and more",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",