PageSourceSearch

https://tjpa.jus.br/PortalExterno/resources/lib/hr.js

js tjpa.jus.br collected 2026-10-02 07:34:42 UTC 2,955 bytes, 86 lines download raw bytes

1/* HR.js | https://mburakerman.github.io/hrjs/ | @mburakerman | License: MIT */
2/**
3 * @param el - The element you want to target.
4 * @param options - This is an object that contains the options.
5 */
6(function () {
7  class HR {
8    constructor(el, options = {}) {
9      this.el = document.querySelectorAll(el);
10      this.options = options;
11      this.defaultOptions = {
12        highlight: null,
13        replaceWith: null,
14        backgroundColor: "rgb(255, 222, 112)",
15      };
16    }
17
18    #setBackgroundColor(selector) {
19      const dataHR = selector.querySelectorAll("[data-hr]");
20      for (let i = 0; i < dataHR.length; i++) {
21        dataHR[i].style.backgroundColor = this.defaultOptions.backgroundColor;
22        if (this.options?.backgroundColor) {
23          dataHR[i].style.backgroundColor = this.options.backgroundColor;
24        }
25      }
26    }
27
28    hr() {
29      for (let i = 0; i < this.el.length; i++) {
30        if (!this.options?.replaceWith && this.options?.highlight) {
31          if (Array.isArray(this.options.highlight)) {
32            for (let m = 0; m < this.options.highlight.length; m++) {
33              this.el[i].innerHTML = this.el[i].innerHTML.replace(
34                new RegExp("(" + this.options.highlight[m] + ")", "gi"),
35                "<span data-hr>$1</span>"
36              );
37            }
38          } else {
39            this.el[i].innerHTML = this.el[i].innerHTML.replace(
40              new RegExp("(" + this.options.highlight + ")", "i"),
41              "<span data-hr>$1</span>"
42            );
43          }
44
45          this.#setBackgroundColor(this.el[i]);
46        }
47
48        if (
49          this.options?.highlight &&
50          this.options.highlight !== null &&
51          this.options?.replaceWith &&
52          this.options.replaceWith !== null
53        ) {
54          if (
55            Array.isArray(this.options.highlight) &&
56            Array.isArray(this.options.replaceWith)
57          ) {
58            for (let n = 0; n < this.options.highlight.length; n++) {
59              if (typeof this.options.replaceWith[n] !== "undefined") {
60                this.el[i].innerHTML = this.el[i].innerHTML.replace(
61                  new RegExp(this.options.highlight[n], "gi"),
62                  "<span data-hr>" + this.options.replaceWith[n] + "</span>"
63                );
64              }
65            }
66          } else {
67            this.el[i].innerHTML = this.el[i].innerHTML.replace(
68              new RegExp(this.options.highlight, "gi"),
69              "<span data-hr>" + this.options.replaceWith + "</span>"
70            );
71          }
72
73          this.#setBackgroundColor(this.el[i]);
74        }
75      }
76    }
77  }
78
79  if (typeof module !== "undefined" && typeof module.exports !== "undefined") {
80    module.exports = HR;
81  } else if (typeof define === "function" && define.amd) {
82    define([], () => HR);
83  } else {
84    window.HR = HR;
85  }
86})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.