Skip to content

Instantly share code, notes, and snippets.

@gklein
Last active December 2, 2021 08:38
Show Gist options
  • Save gklein/5309212da89a5c5b936746ff0cf8acf3 to your computer and use it in GitHub Desktop.
Save gklein/5309212da89a5c5b936746ff0cf8acf3 to your computer and use it in GitHub Desktop.
javascript: (function() { var re = /^\+?(972|0)(\-)?0?([5]{1}\d)\-?(\d{7})$/; var val=prompt("Phone Number #","");var phone=val.replace(re,'972$3$4');location="https://wa.me/"+escape(phone);})()
@asaf4747
Copy link

Thanks for this super useful bookmarklet.
Whatsapp has recently changed their web API, and now the bookmarklet redirects to a page that requires two clicks to actually send a message.

The new URL structure seem to be
https://web.whatsapp.com/send?phone=

Could you please try to offer a way to resolve this and return to "one-click" so it will be less cumbersome? Thanks!!

@gklein
Copy link
Author

gklein commented Oct 23, 2019

Thanks for this super useful bookmarklet.
Whatsapp has recently changed their web API, and now the bookmarklet redirects to a page that requires two clicks to actually send a message.

The new URL structure seem to be
https://web.whatsapp.com/send?phone=

Could you please try to offer a way to resolve this and return to "one-click" so it will be less cumbersome? Thanks!!

It seem that the right way to trigger "click to chat" is with with https://wa.me

See: https://faq.whatsapp.com/en/iphone/26000030/?category=5245251

I've now updated the bookmarklet so you can give it a try.

@asaf4747
Copy link

Thanks for this super useful bookmarklet.
Whatsapp has recently changed their web API, and now the bookmarklet redirects to a page that requires two clicks to actually send a message.
The new URL structure seem to be
https://web.whatsapp.com/send?phone=
Could you please try to offer a way to resolve this and return to "one-click" so it will be less cumbersome? Thanks!!

It seem that the right way to trigger "click to chat" is with with https://wa.me

See: https://faq.whatsapp.com/en/iphone/26000030/?category=5245251

I've now updated the bookmarklet so you can give it a try.

I checked and the new "wa.me" version does not work anymore, at all. Better to resort to the old version.

@asaf4747
Copy link

Thanks for this super useful bookmarklet.
Whatsapp has recently changed their web API, and now the bookmarklet redirects to a page that requires two clicks to actually send a message.

The new URL structure seem to be
https://web.whatsapp.com/send?phone=

Could you please try to offer a way to resolve this and return to "one-click" so it will be less cumbersome? Thanks!!

Please scratch that previous one, I didn't have Whatsapp local client installed before. I just installed it and it works like a charm!

@asaf4747
Copy link

Bookmarklet does not work - clicking it does not trigger the pop-up window

Checked today on the following versions of Chrome:
Version 78.0.3904.97 (Official Build) (64-bit)
Version 79.0.3941.4 (Official Build) dev (64-bit)

Can you please check and resolve?

@baslie
Copy link

baslie commented May 15, 2020

Thank you, @gklein!
I wrote my version of phone processing — https://gist.github.com/baslie/6091c3e5bc1439e3b3c3e33b8bfafee2.

The bookmarklet works as follows:

  1. Save the code in bookmarks, for example as "Phone to WhatsApp".
  2. Highlight the phone number on the page.
  3. Press "Phone to WhatsApp".

The only thing I need help is how to validate the phone number. I need the script to add the missing prefixes itself (e.g. country codes).

@gklein
Copy link
Author

gklein commented May 15, 2020

Thank you, @gklein!
I wrote my version of phone processing — https://gist.github.com/baslie/6091c3e5bc1439e3b3c3e33b8bfafee2.

The bookmarklet works as follows:

  1. Save the code in bookmarks, for example as "Phone to WhatsApp".
  2. Highlight the phone number on the page.
  3. Press "Phone to WhatsApp".

The only thing I need help is how to validate the phone number. I need the script to add the missing prefixes itself (e.g. country codes).

You can use replace() with a regular expression in order to adapt the phone number to the required format.

@baslie
Copy link

baslie commented May 15, 2020

Thank you, @gklein!
I wrote my version of phone processing — https://gist.github.com/baslie/6091c3e5bc1439e3b3c3e33b8bfafee2.
The bookmarklet works as follows:

  1. Save the code in bookmarks, for example as "Phone to WhatsApp".
  2. Highlight the phone number on the page.
  3. Press "Phone to WhatsApp".

The only thing I need help is how to validate the phone number. I need the script to add the missing prefixes itself (e.g. country codes).

You can use replace() with a regular expression in order to adapt the phone number to the required format.

Yeap, of course :) I need more practice with REGEXPs

@gklein
Copy link
Author

gklein commented May 15, 2020

Thank you, @gklein!
I wrote my version of phone processing — https://gist.github.com/baslie/6091c3e5bc1439e3b3c3e33b8bfafee2.
The bookmarklet works as follows:

  1. Save the code in bookmarks, for example as "Phone to WhatsApp".
  2. Highlight the phone number on the page.
  3. Press "Phone to WhatsApp".

The only thing I need help is how to validate the phone number. I need the script to add the missing prefixes itself (e.g. country codes).

You can use replace() with a regular expression in order to adapt the phone number to the required format.

Yeap, of course :) I need more practice with REGEXPs

Try this one:
https://www.youtube.com/watch?v=ZfQFUJhPqMM

Good luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment