Whisno / Chrome-Text-Customizer

Customize your internet with text replacement strategies.
The Unlicense
8 stars 4 forks source link

Match more than one pattern on an element #1

Open codl opened 9 years ago

codl commented 9 years ago

If more than one pattern matches on an element, only one will be applied

Whisno commented 9 years ago

Hey, my first issue !

That's because replacement actually breaks a text node into 3 (at most) text nodes. Eg. if you replace foo by bar, "azertyfoouiop" becomes "azerty""bar""uiop", so when we try to apply the next replacement, it fails splitting the node which is now shorter than expected.

It's just 3 lines : https://github.com/Whisno/Chrome-Text-Customizer/blob/master/chrome-extension/text_customizer.js#L89

I guess the solution would be to call the normalize method of the parent node. (Update and note for later : the algorithm needs to apply match/replace rules one after another, on each text node, so that regexp.exec result correspont to the actual dom state, after manipulation. Still to be decided : what should happen when there are successive matches on the same string portion ?)

Thanks for the return