0

I'm just starting to work with the WebExtension API (on Safari rather than Chrome), and I've gotten as far as having the extension show a button in the popover ui and on clicking it the content.js script will replace any given word on a page with another given word.

This works great, but I'd like to have another button in the popover ui that easily reverses this replace call. Currently I just have it perform the same replace function but in reverse, but I'm wondering if there's a way to reverse all extension actions performed without having to define them a second time, and without simply refreshing the page to revert all changes.

Hope this makes sense, would appreciate any pointers anyone could give!

srb7
  • 337
  • 2
  • 9
  • There's no such API. – wOxxOm Sep 11 '21 at 12:00
  • What do you mean with: "without having to define them a second time" ? – Robbi Sep 11 '21 at 13:09
  • @Robbi so if my popover ui allows the user to enter a find term and enter a replace term and perform several text replacements on the website they have open, I would need to keep track of all of these in order to reverse the replacements. What I would prefer is a way to turn the extension off from inside the popover ui, and have it be turned back on while retaining the information the user entered. – srb7 Sep 11 '21 at 19:19

1 Answers1

0

You didn't show us the code with which you make the replacements, but if you want to revolve the process a possible solution could be to wrap every single word\sentence you want to replace within a tag (e.g. span) and adding to it a property which "remember" the sostituted value. I usually do something like this:

<span class="myExtensionId_className" data-previuosValue="foo">bar</span>
Robbi
  • 1,254
  • 2
  • 8
  • 11
  • Thanks! I think this would be the best workaround - but as far as you know there isn't a way to disable the extension from a toggle in the popover ui? The only way to do it that I know of is to get to the browsers extensions page and turn it off from there – srb7 Sep 13 '21 at 08:35
  • The effects of a content script on a page are not reversible even if you manually turn off or uninstall the extension. If you don't trust, you can do a test by your own. It would be like to separate flour and water from an already cooked bread. – Robbi Sep 13 '21 at 19:24