Skip to content

Latest commit

 

History

History
9 lines (8 loc) · 2.94 KB

fb_whoistyping-js.md

File metadata and controls

9 lines (8 loc) · 2.94 KB
title date categories
Fb_whoIsTyping.Js
2023-11-23
useful-script-en

how to add bookmarklet in chrome
export default { icon: '', name: { en: "Facebook – Who is typing to you?", vi: "Facebook – Who is typing to you?", }, description: { en: "Notify when someone is typing chat to you.", en: "Notify when someone is typing a message for you.", }, whiteList: ["https://*.facebook.com/*", "https://*.messenger.com/*"], onDocumentStart: () => { window.ufs_whoIsTyping_Cached = {}; let textDecoder = new TextDecoder("utf-8"); const WebSocketOrig = window. WebSocket; Window. WebSocket = function fakeConstructor(dt, config) { const websocket_instant = new WebSocketOrig(dt, config); websocket_instant.addEventListener("message", async function(achunk) { let utf8_str = textDecoder.decode(achunk.data); if ( utf8_str.startsWith("1") &&; utf8_str.includes("updateTypingIndicator") ) { console.log(utf8_str); try { let isStartTyping = utf8_str.includes(",true"); let isStopTyping = utf8_str.includes(",false"); let uid = /\\\"(\d+)\\" /g.exec( utf8_str)[1]; if (!( uid in window.ufs_whoIsTyping_Cached)) { let userData = await UsefulScriptGlobalPageContext.Facebook.getUserInfoFromUid( uid ); window.ufs_whoIsTyping_Cached[uid] = userData; } let { name, avatar } = window.ufs_whoIsTyping_Cached[uid]; notifyTypingEvent(uid, name, avatar, isStartTyping); } catch (e) { console.log("ERROR: ", e); } } }); return websocket_instant; }; Window. WebSocket.prototype = WebSocketOrig.prototype; Window. WebSocket.prototype.constructor = window. WebSocket; UsefulScriptGlobalPageContext.Extension.getURL( "scripts/fb_whoIsTyping.css " ).then(UsefulScriptGlobalPageContext.DOM.injectCssFile); function notifyTypingEvent(uid, name, avatar, isTyping) { let divId = "ufs-who-is-typing"; let exist = document.querySelector("#" + divId); if (!exist) { exist = document.createElement("div"); exist.id = divId; exist.innerHTML = ' X – `; exist.querySelector(".ufs-header .ufs-minimize-btn").onclick = (e) => { exist.classList.toggle("collapsed"); }; exist.querySelector(".ufs-header .ufs-clear-btn").onclick = (e) => { if (confirm("Are you sure you want to delete all notifications?")) exist.remove(); }; document.body.appendChild(exist); } let time = new Date().toLocaleTimeString(); let text = '${name}' + ' ${isTyping ? "typing" : "stop typing"} message you.'; let newNoti = document.createElement("div"); newNoti.className = "ufs-noti-item clearfix"; newNoti.innerHTML = ' X ![](https://naturelovers.15w.xyz/blog/fb_whoistyping-js/$%7Bavatar%7D) ${time} ${text} `; newNoti.querySelector(".ufs-close-btn").onclick = () => { newNoti.remove(); if (!exist.querySelector(".ufs-noti-item")) exist.remove(); }; exist.appendChild(newNoti); } }, };