pervert-monkey 1.0.18 → 1.0.20

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.
Files changed (55) hide show
  1. package/README.md +4 -4
  2. package/dist/core/pervertmonkey.core.es.d.ts +12 -15
  3. package/dist/core/pervertmonkey.core.es.js +39 -45
  4. package/dist/core/pervertmonkey.core.es.js.map +1 -1
  5. package/dist/core/pervertmonkey.core.umd.js +39 -45
  6. package/dist/core/pervertmonkey.core.umd.js.map +1 -1
  7. package/dist/test/test.user.js +10301 -0
  8. package/dist/userscripts/3hentai.user.js +2 -2
  9. package/dist/userscripts/camgirlfinder.user.js +2 -2
  10. package/dist/userscripts/camwhores.user.js +2 -2
  11. package/dist/userscripts/e-hentai.user.js +2 -2
  12. package/dist/userscripts/ebalka.user.js +2 -2
  13. package/dist/userscripts/eporner.user.js +2 -2
  14. package/dist/userscripts/erome.user.js +2 -2
  15. package/dist/userscripts/eroprofile.user.js +2 -2
  16. package/dist/userscripts/javhdporn.user.js +2 -2
  17. package/dist/userscripts/missav.user.js +2 -2
  18. package/dist/userscripts/motherless.user.js +2 -2
  19. package/dist/userscripts/namethatporn.user.js +2 -2
  20. package/dist/userscripts/nhentai.user.js +2 -2
  21. package/dist/userscripts/obmenvsem.user.js +3 -3
  22. package/dist/userscripts/pornhub.user.js +3 -3
  23. package/dist/userscripts/spankbang.user.js +2 -2
  24. package/dist/userscripts/thisvid.user.js +33 -27
  25. package/dist/userscripts/xhamster.user.js +3 -3
  26. package/dist/userscripts/xvideos.user.js +3 -3
  27. package/package.json +4 -4
  28. package/src/core/data-handler/data-filter.ts +4 -4
  29. package/src/core/data-handler/data-manager.ts +5 -5
  30. package/src/core/infinite-scroll/index.ts +2 -9
  31. package/src/core/parsers/thumb-data-parser.ts +5 -4
  32. package/src/core/parsers/thumbs-parser.ts +9 -10
  33. package/src/core/rules/index.ts +9 -10
  34. package/src/userscripts/index.ts +1 -1
  35. package/src/userscripts/scripts/3hentai.ts +1 -1
  36. package/src/userscripts/scripts/camgirlfinder.ts +1 -1
  37. package/src/userscripts/scripts/camwhores.ts +1 -1
  38. package/src/userscripts/scripts/e-hentai.ts +1 -1
  39. package/src/userscripts/scripts/ebalka.ts +1 -1
  40. package/src/userscripts/scripts/eporner.ts +1 -1
  41. package/src/userscripts/scripts/erome.ts +1 -1
  42. package/src/userscripts/scripts/eroprofile.ts +1 -1
  43. package/src/userscripts/scripts/javhdporn.ts +1 -1
  44. package/src/userscripts/scripts/missav.ts +1 -1
  45. package/src/userscripts/scripts/motherless.ts +1 -1
  46. package/src/userscripts/scripts/namethatporn.ts +1 -1
  47. package/src/userscripts/scripts/nhentai.ts +1 -2
  48. package/src/userscripts/scripts/obmenvsem.ts +2 -2
  49. package/src/userscripts/scripts/pornhub.ts +3 -3
  50. package/src/userscripts/scripts/spankbang.ts +1 -1
  51. package/src/userscripts/scripts/thisvid.ts +43 -35
  52. package/src/userscripts/scripts/xhamster.ts +2 -2
  53. package/src/userscripts/scripts/xvideos.ts +2 -2
  54. package/src/utils/dom/index.ts +17 -15
  55. package/src/utils/parsers/index.ts +1 -1
package/README.md CHANGED
@@ -7,14 +7,14 @@
7
7
 
8
8
  ## Userscripts
9
9
  ```shell
10
- src/userscripts/scripts # dev
11
- dist/userscripts # build
10
+ src/userscripts/scripts # dev
11
+ dist/userscripts # build
12
12
  ```
13
13
 
14
14
  ## Build
15
15
  ```shell
16
- npm run build # build core
17
- npm run build:userscripts # build userscripts
16
+ npm run build # build core
17
+ npm run build:u # build userscripts
18
18
  ```
19
19
 
20
20
  ## Dev
@@ -7,7 +7,7 @@ import { Subject } from 'rxjs';
7
7
 
8
8
  declare type AnyFunction = (...args: any[]) => any;
9
9
 
10
- export declare function checkHomogenity<T extends HTMLElement>(a: T, b: T, options: {
10
+ export declare function areElementsAlike<T extends HTMLElement>(a: T, b: T, options: {
11
11
  id?: boolean;
12
12
  className?: boolean;
13
13
  }): boolean;
@@ -28,7 +28,7 @@ export declare type DataElement = {
28
28
  export declare class DataFilter {
29
29
  private rules;
30
30
  filters: Map<string, () => DataFilterFnRendered>;
31
- filterMapping: Record<string, string>;
31
+ filterDepsMapping: Record<string, string>;
32
32
  constructor(rules: Rules);
33
33
  static isFiltered(e: HTMLElement): boolean;
34
34
  createCssFilters(wrapper?: (cssRule: string) => string): void;
@@ -69,7 +69,7 @@ export declare class DataManager {
69
69
  data: Map<string, DataElement>;
70
70
  private lazyImgLoader;
71
71
  dataFilter: DataFilter;
72
- constructor(rules: Rules, containerHomogenity?: Parameters<typeof checkHomogenity>[2] | undefined);
72
+ constructor(rules: Rules, containerHomogenity?: Parameters<typeof areElementsAlike>[2] | undefined);
73
73
  applyFilters(filters?: Record<string, boolean>, offset?: number): Promise<void>;
74
74
  filterAll(offset?: number): Promise<void>;
75
75
  parseData(html: HTMLElement, container?: HTMLElement, removeDuplicates?: boolean, shouldLazify?: boolean): Promise<void>;
@@ -223,8 +223,6 @@ export declare function fetchWith<T extends JSON | string | HTMLElement>(input:
223
223
 
224
224
  export declare function findNextSibling<T extends Element = HTMLElement>(e: T): Element | null;
225
225
 
226
- export declare function findSelfOrChild<T extends HTMLElement>(element: T, selector: string): T | null;
227
-
228
226
  /**
229
227
  * Converts a duration string (e.g., "1h 22min 3sec") to HH:MM:SS format.
230
228
  * @param timeStr - The duration string to format.
@@ -237,12 +235,11 @@ declare type GeneratorResult = {
237
235
  offset: number;
238
236
  };
239
237
 
240
- export declare function getCommonParents(elements: HTMLCollection | HTMLElement[]): HTMLElement[];
238
+ export declare function getCommonParents<T extends HTMLElement>(elements: Iterable<T>): HTMLElement[];
241
239
 
242
240
  export declare function getPaginationStrategy(options: Partial<PaginationStrategy>): PaginationStrategy;
243
241
 
244
242
  export declare class InfiniteScroller {
245
- enabled: boolean;
246
243
  paginationOffset: number;
247
244
  rules: Rules;
248
245
  private observer?;
@@ -381,7 +378,7 @@ export declare function parseHtml(html: string): HTMLElement;
381
378
 
382
379
  export declare function parseIntegerOr(n: string | number, or: number): number;
383
380
 
384
- export declare function parseNumberWithLetter(str: string): number;
381
+ export declare function parseNumericAbbreviation(str: string): number;
385
382
 
386
383
  export declare function parseUrl(s: HTMLAnchorElement | Location | URL | string): URL;
387
384
 
@@ -391,6 +388,8 @@ export declare function querySelectorLast<T extends Element = HTMLElement>(root:
391
388
 
392
389
  export declare function querySelectorLastNumber(selector: string, e?: ParentNode): number;
393
390
 
391
+ export declare function querySelectorOrSelf<T extends Element = HTMLElement>(element: T, selector: string): T | null;
392
+
394
393
  export declare function querySelectorText(e: ParentNode, selector?: string): string;
395
394
 
396
395
  export declare function range(size: number, start?: number, step?: number): number[];
@@ -408,17 +407,17 @@ export declare function removeClassesAndDataAttributes(element: HTMLElement, key
408
407
  export declare function replaceElementTag(e: HTMLElement, tagName: string): HTMLElement;
409
408
 
410
409
  export declare class Rules {
410
+ thumbs: Parameters<typeof ThumbsParser.create>[0];
411
+ thumbsParser: ThumbsParser;
411
412
  thumb: Parameters<typeof ThumbDataParser.create>[0];
412
413
  thumbDataParser: ThumbDataParser;
413
414
  thumbImg: Parameters<typeof ThumbImgParser.create>[0];
414
415
  thumbImgParser: ThumbImgParser;
415
- thumbs: Parameters<typeof ThumbsParser.create>[0];
416
- thumbsParser: ThumbsParser;
417
416
  containerSelector: string | (() => HTMLElement);
418
417
  containerSelectorLast?: string;
419
418
  get container(): HTMLElement;
420
419
  intersectionObservableSelector?: string;
421
- get intersectionObservable(): "" | Element | null | undefined;
420
+ get intersectionObservable(): HTMLElement | null | undefined;
422
421
  get observable(): HTMLElement;
423
422
  paginationStrategyOptions: Partial<PaginationStrategy>;
424
423
  paginationStrategy: PaginationStrategy;
@@ -501,13 +500,11 @@ export declare class ThumbImgParser {
501
500
  }
502
501
 
503
502
  export declare class ThumbsParser {
504
- containerSelector: string;
505
503
  selector: string;
506
504
  strategy: 'default' | 'auto';
507
505
  transform?: (thumb: HTMLElement) => void;
508
- static create(options: Partial<Pick<ThumbsParser, "selector" | "strategy" | "transform">> | undefined, containerSelector: string): ThumbsParser & Partial<Pick<ThumbsParser, "selector" | "strategy" | "transform">>;
509
- constructor(containerSelector: string);
510
- getThumbs(html: HTMLElement): HTMLElement[];
506
+ static create(options?: Partial<Pick<ThumbsParser, 'selector' | 'strategy' | 'transform'>>): ThumbsParser & Partial<Pick<ThumbsParser, "selector" | "strategy" | "transform">>;
507
+ getThumbs(container: HTMLElement): HTMLElement[];
511
508
  }
512
509
 
513
510
  export declare class Tick {
@@ -172,15 +172,19 @@ function watchDomChangesWithThrottle(element, callback, throttle = 1e3, times =
172
172
  observer.observe(element, options);
173
173
  return observer;
174
174
  }
175
- function findSelfOrChild(element, selector) {
176
- if (element.matches(selector)) {
175
+ function querySelectorOrSelf(element, selector) {
176
+ var _a3;
177
+ if ((_a3 = element.matches) == null ? void 0 : _a3.call(element, selector)) {
177
178
  return element;
178
179
  }
179
180
  return element.querySelector(selector);
180
181
  }
181
182
  function querySelectorLast(root = document, selector) {
182
183
  const nodes = root.querySelectorAll(selector);
183
- return nodes.length > 0 ? nodes[nodes.length - 1] : void 0;
184
+ if (nodes.length < 1) {
185
+ return querySelectorOrSelf(root, selector) || void 0;
186
+ }
187
+ return nodes[nodes.length - 1];
184
188
  }
185
189
  function querySelectorLastNumber(selector, e = document) {
186
190
  var _a3;
@@ -190,7 +194,7 @@ function querySelectorLastNumber(selector, e = document) {
190
194
  function querySelectorText(e, selector) {
191
195
  var _a3;
192
196
  if (typeof selector !== "string") return "";
193
- const text = ((_a3 = e.querySelector(selector)) == null ? void 0 : _a3.innerText) || "";
197
+ const text = ((_a3 = querySelectorOrSelf(e, selector)) == null ? void 0 : _a3.innerText) || "";
194
198
  return sanitizeStr(text);
195
199
  }
196
200
  function parseHtml(html) {
@@ -226,19 +230,16 @@ function removeClassesAndDataAttributes(element, keyword) {
226
230
  });
227
231
  }
228
232
  function getCommonParents(elements) {
229
- const parents = Array.from(elements).map((e) => e.parentElement).filter((parent) => parent !== null);
230
- return [...new Set(parents)];
233
+ return Map.groupBy(elements, (e) => e.parentElement).keys().filter((e) => e !== null).toArray();
231
234
  }
232
235
  function findNextSibling(e) {
233
236
  if (e.nextElementSibling) return e.nextElementSibling;
234
237
  if (e.parentElement) return findNextSibling(e.parentElement);
235
238
  return null;
236
239
  }
237
- function checkHomogenity(a2, b2, options) {
240
+ function areElementsAlike(a2, b2, options) {
238
241
  if (!a2 || !b2) return false;
239
- if (options.id) {
240
- if (a2.id !== b2.id) return false;
241
- }
242
+ if (options.id && a2.id !== b2.id) return false;
242
243
  if (options.className) {
243
244
  const ca2 = a2.className;
244
245
  const cb = b2.className;
@@ -437,7 +438,7 @@ function parseIntegerOr(n, or2) {
437
438
  const num = Number(n);
438
439
  return Number.isSafeInteger(num) ? num : or2;
439
440
  }
440
- function parseNumberWithLetter(str) {
441
+ function parseNumericAbbreviation(str) {
441
442
  var _a3;
442
443
  const multipliers = { k: 1e3, m: 1e6 };
443
444
  const match = str.trim().match(/([\d., ]+)(\w)?/);
@@ -552,7 +553,7 @@ const defaultDataFilterFns = {
552
553
  class DataFilter {
553
554
  constructor(rules) {
554
555
  __publicField(this, "filters", /* @__PURE__ */ new Map());
555
- __publicField(this, "filterMapping", {});
556
+ __publicField(this, "filterDepsMapping", {});
556
557
  __publicField(this, "customDataFilterFns", {});
557
558
  this.rules = rules;
558
559
  this.registerFilters(rules.customDataFilterFns);
@@ -583,12 +584,12 @@ class DataFilter {
583
584
  );
584
585
  dataFilterFn.deps.push(customSelectorName);
585
586
  dataFilterFn.deps.forEach((name) => {
586
- Object.assign(this.filterMapping, { [name]: customSelectorName });
587
+ Object.assign(this.filterDepsMapping, { [name]: customSelectorName });
587
588
  });
588
589
  this.filters.set(customSelectorName, dataFilterFn.renderFn(this.rules.store.state));
589
590
  }
590
591
  selectFilters(filters) {
591
- const selectedFilters = Object.keys(filters).filter((k2) => k2 in this.filterMapping).map((k2) => this.filterMapping[k2]).map((k2) => this.filters.get(k2));
592
+ const selectedFilters = Object.keys(filters).filter((k2) => k2 in this.filterDepsMapping).map((k2) => this.filterDepsMapping[k2]).map((k2) => this.filters.get(k2));
592
593
  return selectedFilters;
593
594
  }
594
595
  }
@@ -645,12 +646,12 @@ class DataManager {
645
646
  const homogenity = !!this.containerHomogenity;
646
647
  for (const thumbElement of thumbs) {
647
648
  const url = this.rules.thumbDataParser.getUrl(thumbElement);
648
- const isHomogenic = homogenity && !checkHomogenity(
649
+ const isNotHomogenic = homogenity && !areElementsAlike(
649
650
  parent,
650
651
  thumbElement.parentElement,
651
652
  this.containerHomogenity
652
653
  );
653
- if (!url || this.data.has(url) || parent !== container && (parent == null ? void 0 : parent.contains(thumbElement)) || isHomogenic) {
654
+ if (!url || this.data.has(url) || parent !== container && (parent == null ? void 0 : parent.contains(thumbElement)) || isNotHomogenic) {
654
655
  if (removeDuplicates) thumbElement.remove();
655
656
  continue;
656
657
  }
@@ -1954,14 +1955,13 @@ function takeUntil(notifier) {
1954
1955
  }
1955
1956
  class InfiniteScroller {
1956
1957
  constructor(options) {
1957
- __publicField(this, "enabled", true);
1958
1958
  __publicField(this, "paginationOffset", 1);
1959
1959
  __publicField(this, "rules");
1960
1960
  __publicField(this, "observer");
1961
1961
  __publicField(this, "paginationGenerator");
1962
1962
  __publicField(this, "subject", new Subject());
1963
1963
  __publicField(this, "generatorConsumer", async () => {
1964
- if (!this.enabled) return false;
1964
+ if (!this.rules.store.state.infiniteScrollEnabled) return true;
1965
1965
  const { value, done } = await this.paginationGenerator.next();
1966
1966
  if (done) return false;
1967
1967
  const { url, offset } = value;
@@ -2027,9 +2027,8 @@ class InfiniteScroller {
2027
2027
  }
2028
2028
  }
2029
2029
  static create(rules) {
2030
- const enabled = rules.store.state.infiniteScrollEnabled;
2031
2030
  rules.store.state.$paginationLast = rules.paginationStrategy.getPaginationLast();
2032
- const infiniteScroller = new InfiniteScroller({ enabled, rules });
2031
+ const infiniteScroller = new InfiniteScroller({ rules });
2033
2032
  rules.store.state.$paginationOffset = infiniteScroller.paginationOffset;
2034
2033
  infiniteScroller.subject.subscribe((x2) => {
2035
2034
  if (x2.type === "scroll") {
@@ -2040,9 +2039,6 @@ class InfiniteScroller {
2040
2039
  });
2041
2040
  }
2042
2041
  });
2043
- rules.store.stateSubject.subscribe(() => {
2044
- infiniteScroller.enabled = rules.store.state.infiniteScrollEnabled;
2045
- });
2046
2042
  return infiniteScroller;
2047
2043
  }
2048
2044
  }
@@ -3080,7 +3076,7 @@ class ThumbDataParser {
3080
3076
  return { title, duration };
3081
3077
  }
3082
3078
  getUrl(thumb) {
3083
- return (thumb.querySelector("a[href]") || thumb).href;
3079
+ return querySelectorOrSelf(thumb, "a[href]").href;
3084
3080
  }
3085
3081
  preprocessCustomThumbDataSelectors() {
3086
3082
  if (!this.selectors) return;
@@ -3101,7 +3097,7 @@ class ThumbDataParser {
3101
3097
  getThumbDataWith(thumb, { type, selector }) {
3102
3098
  var _a3;
3103
3099
  if (type === "boolean") {
3104
- return !!thumb.querySelector(selector);
3100
+ return !!querySelectorOrSelf(thumb, selector);
3105
3101
  }
3106
3102
  if (type === "string") {
3107
3103
  return sanitizeStr(((_a3 = querySelectorLast(thumb, selector)) == null ? void 0 : _a3.innerText) || "");
@@ -3111,7 +3107,7 @@ class ThumbDataParser {
3111
3107
  }
3112
3108
  if (type === "float") {
3113
3109
  const value = querySelectorText(thumb, selector);
3114
- return parseNumberWithLetter(value);
3110
+ return parseNumericAbbreviation(value);
3115
3111
  }
3116
3112
  return Number.parseInt(querySelectorText(thumb, selector));
3117
3113
  }
@@ -3180,24 +3176,21 @@ class ThumbImgParser {
3180
3176
  }
3181
3177
  }
3182
3178
  class ThumbsParser {
3183
- constructor(containerSelector) {
3179
+ constructor() {
3184
3180
  __publicField(this, "selector", ".thumb");
3185
3181
  __publicField(this, "strategy", "default");
3186
3182
  __publicField(this, "transform");
3187
- this.containerSelector = containerSelector;
3188
3183
  }
3189
- static create(options = {}, containerSelector) {
3190
- return Object.assign(new ThumbsParser(containerSelector), options);
3184
+ static create(options = {}) {
3185
+ return Object.assign(new ThumbsParser(), options);
3191
3186
  }
3192
- getThumbs(html) {
3193
- if (!html) return [];
3194
- let thumbs;
3187
+ getThumbs(container) {
3188
+ if (!container) return [];
3195
3189
  if (this.strategy === "auto") {
3196
3190
  if (typeof this.selector !== "string") return [];
3197
- const container = html.querySelector(this.containerSelector);
3198
- thumbs = [...(container == null ? void 0 : container.children) || []];
3191
+ return [...(container == null ? void 0 : container.children) || []];
3199
3192
  }
3200
- thumbs = Array.from(html.querySelectorAll(this.selector));
3193
+ const thumbs = Array.from(container.querySelectorAll(this.selector));
3201
3194
  if (typeof this.transform === "function") {
3202
3195
  thumbs.forEach(this.transform);
3203
3196
  }
@@ -9866,12 +9859,12 @@ function getSelectorFnsFromScheme(xs2) {
9866
9859
  }
9867
9860
  class Rules {
9868
9861
  constructor(options) {
9862
+ __publicField(this, "thumbs", {});
9863
+ __publicField(this, "thumbsParser");
9869
9864
  __publicField(this, "thumb", {});
9870
9865
  __publicField(this, "thumbDataParser");
9871
9866
  __publicField(this, "thumbImg", {});
9872
9867
  __publicField(this, "thumbImgParser");
9873
- __publicField(this, "thumbs", {});
9874
- __publicField(this, "thumbsParser");
9875
9868
  __publicField(this, "containerSelector", ".container");
9876
9869
  __publicField(this, "containerSelectorLast");
9877
9870
  __publicField(this, "intersectionObservableSelector");
@@ -9895,9 +9888,9 @@ class Rules {
9895
9888
  __publicField(this, "onResetCallback");
9896
9889
  if (this.isEmbedded) throw Error("Embedded is not supported");
9897
9890
  Object.assign(this, options);
9891
+ this.thumbsParser = ThumbsParser.create(this.thumbs);
9898
9892
  this.thumbDataParser = ThumbDataParser.create(this.thumb);
9899
9893
  this.thumbImgParser = ThumbImgParser.create(this.thumbImg);
9900
- this.thumbsParser = ThumbsParser.create(this.thumbs, this.containerSelector);
9901
9894
  this.paginationStrategy = getPaginationStrategy(this.paginationStrategyOptions);
9902
9895
  this.store = this.createStore();
9903
9896
  this.gui = this.createGui();
@@ -9908,15 +9901,16 @@ class Rules {
9908
9901
  }
9909
9902
  get container() {
9910
9903
  if (typeof this.containerSelectorLast === "string") {
9911
- return querySelectorLast(document, this.containerSelectorLast);
9904
+ return querySelectorLast(document.body, this.containerSelectorLast);
9912
9905
  }
9913
9906
  if (typeof this.containerSelector === "string") {
9914
- return document.querySelector(this.containerSelector);
9907
+ return querySelectorOrSelf(document.body, this.containerSelector);
9915
9908
  }
9916
9909
  return this.containerSelector();
9917
9910
  }
9918
9911
  get intersectionObservable() {
9919
- return this.intersectionObservableSelector && document.querySelector(this.intersectionObservableSelector);
9912
+ if (!this.intersectionObservableSelector) return void 0;
9913
+ return document.querySelector(this.intersectionObservableSelector);
9920
9914
  }
9921
9915
  get observable() {
9922
9916
  return this.intersectionObservable || this.paginationStrategy.getPaginationElement();
@@ -10010,7 +10004,7 @@ export {
10010
10004
  ThumbImgParser,
10011
10005
  ThumbsParser,
10012
10006
  Tick,
10013
- checkHomogenity,
10007
+ areElementsAlike,
10014
10008
  chunks,
10015
10009
  circularShift,
10016
10010
  containMutation,
@@ -10022,7 +10016,6 @@ export {
10022
10016
  fetchText,
10023
10017
  fetchWith,
10024
10018
  findNextSibling,
10025
- findSelfOrChild,
10026
10019
  formatTimeToHHMMSS,
10027
10020
  getCommonParents,
10028
10021
  getPaginationStrategy,
@@ -10034,10 +10027,11 @@ export {
10034
10027
  parseDataParams,
10035
10028
  parseHtml,
10036
10029
  parseIntegerOr,
10037
- parseNumberWithLetter,
10030
+ parseNumericAbbreviation,
10038
10031
  parseUrl,
10039
10032
  querySelectorLast,
10040
10033
  querySelectorLastNumber,
10034
+ querySelectorOrSelf,
10041
10035
  querySelectorText,
10042
10036
  range,
10043
10037
  removeClassesAndDataAttributes,