erosman / support

Support Location for all my extensions
Mozilla Public License 2.0
175 stars 12 forks source link

new extension? replace html #41

Open atomGit opened 5 years ago

atomGit commented 5 years ago

i'm really surprised that there doesn't seem to be any simple extension for replacing html in the entirety of AMO and so i'd like to ask if you might be willing to create one (or know someone that might) since you have developed a couple of add-ons that come close (Edit and Replace)

i'm simply wanting to replace and/or modify html elements - for example, replace <img data-pagespeed-lazy-src="this" with <img src="this"

the ability to use regular expressions would be great as would the ability to replace stuff automatically for a given URL every time it's loaded

i realize this can be done with user-scripts, but that is more complex than i would like, plus one would have to know JS

seems to me a lot of people might find such an add-on very handy and i'd be willing to help with documentation

erosman commented 5 years ago

Replacing DOM elements is possible but that requires good working knowledge of JavaScript from the user. That is the reason a user-script is the obvious choice.

Regular Expressions work on strings of text. In order to replace elements, a totally different method has to be used (not Regular Expressions).

There are scripts (I had written one myself) to replace lazy-loaded images but that has to be adjusted constantly since:

one site might use <img data-pagespeed-lazy-src="this"

other sites might use:

<img data-lazy-src="this"
<img data-lazy="this"
<img data-src="this"
...

That is why such replacements can only work for one site, until they change their code and then the script needs to be updated.

I can include DOM replacement in for example Replace or make an add-on, but as I said, it requires good knowledge of JavaScript from the user to be able to use it.