0

I have this in the Tampermonkey script header section:

// @require      https://raw.githubusercontent.com/julmot/mark.js/master/dist/mark.js

My marking instance:

   for (var i=0; i<slotValuesRows.length; i++) {
     let targetToMark = new Mark(slotValuesRows[i]);
     targetToMark.mark(["e"],
     {"element": "span",
      "className": "highlight",
      "accuracy": "exactly"});
   }

The "e" do not get highlighted and the tab freezes on page load.

I am a beginner, but am suspecting mark.js just does not work with userscripts.

Is that assumption correct?

MKKirk
  • 49
  • 8
  • 1
    The problem sounds like an infinite loop. Are you using MutationObserver? Or maybe getElementsByTagName('span')? It would grow automatically every time you add a span element. Show us more of the code. – wOxxOm Nov 11 '20 at 04:25
  • @wOxxOm You were right of course my loop is broken: WAS: 0 – MKKirk Nov 11 '20 at 20:56

1 Answers1

0

With the help of the documentation here > 4.2 and @wOxxOm input above, I was able to fix my loop and highlight all "[" in the target elements. Example:

for (var i=0; i<slotValuesRows.length; i++) {
  let targetToMark = new Mark(slotValuesRows[i]);
  targetToMark.mark("[");
}

Summarizing and answering question: Turns out you can add

// @require      https://raw.githubusercontent.com/julmot/mark.js/master/dist/mark.js

to your Greasemonkey/Tampermonkey script and use mark.js. Hope this helps others.

MKKirk
  • 49
  • 8