Skip to content

Instantly share code, notes, and snippets.

@mikhailsdv
Last active December 1, 2022 02:05
Show Gist options
  • Save mikhailsdv/bd2518c1e1da86fb47e33cb989bea410 to your computer and use it in GitHub Desktop.
Save mikhailsdv/bd2518c1e1da86fb47e33cb989bea410 to your computer and use it in GitHub Desktop.
Closes dead WhatsApp windows and quickly opens chats by url
// ==UserScript==
// @name WhatsApp window manager
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Closes dead WhatsApp windows and quickly opens chats by url
// @author mikhailsdv
// @match https://*.whatsapp.com/*
// @grant window.close
// ==/UserScript==
(function() {
"use strict"
const linkToChat = document.querySelector("#fallback_block h4 a[href^='https://web.whatsapp']")
if (linkToChat) {
setTimeout(() => {
location.href = linkToChat.href
}, 100)
}
else {
setInterval(() => {
const el = document.querySelector("._2Nr6U")
if (el && /^Приложение WhatsApp|^WhatsApp is open in another/.test(el.innerText)) {
window.close()
}
}, 2000)
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment