Adding RegEx Search and Replace to an Existing Chrome Bookmark Manager Script

People,

I have not done any JS coding before but I got this working OK:

https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/docs/examples/api/bookmarks/basic

and was also able to get the DevTools debugger working with it as well. The question I have for the experienced Devs is: “How difficult would it be to add a RegEx search and replace facility to the script?”.

Thanks,
Phil.

To answer your question literally, not that hard - probably less than 10 lines of code. JavaScript has a few one-command methods that deal with search/replace via regex: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

The problem is that because (it looks like) it’s an extension, it would be a bit of a pain to develop as the workflow for developing plugins is much more involved than simply refreshing the page after saving changes. On line 36 of popup.js, you could probably change anchor.text(bookmarkNode.title); to anchor.text(bookmarkNode.title.replace('REGEX_FIND', 'REPLACE_STRING'));

Unfortunately I don’t have much bandwidth right now, but that might be a good place to start. You’d need to implement a way to get REGEX_FIND and REPLACE_STRING from the user, but that’s could be just a line or two

2 Likes

@tensormonkey ,

Thanks for responding! - I appreciate it.

I will have a look at that.

Yes, I looked at a lot of debugging stuff but there was not much for dealing with extensions but I think I have made some progress . .

OK, will look at that too.

OK, it sounds like it should be doable even if it is my first modification of someone else’s (simple) script - I might play around with search and replace in page first and see how I go there first.

Thanks!

Regards,
Phil.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.