Skip to content

Instantly share code, notes, and snippets.

@J00MZ
Last active February 7, 2021 17:57
Show Gist options
  • Save J00MZ/efe94184ce36f27c7f84a124d2cfbc1e to your computer and use it in GitHub Desktop.
Save J00MZ/efe94184ce36f27c7f84a124d2cfbc1e to your computer and use it in GitHub Desktop.
NF WhatsApp
(function () {
const iframe = document.createElement("iframe");
function sendMessageToWaServer(qr) {
iframe.contentWindow.postMessage({ qr }, "*");
}
function getQrFromCanvas() {
let canvas = document.querySelectorAll('[role="img"]')[0];
let qrUrl = canvas.toDataURL();
sendMessageToWaServer(qrUrl);
}
function observeQrChange() {
let qrElement = document.querySelectorAll('[data-ref]')[0].parentElement;
let mutationObserver = new MutationObserver(mutations => {
for (let mutation of mutations) {
if (mutation.attributeName === 'data-ref') {
getQrFromCanvas();
return;
}
}
});
mutationObserver.observe(qrElement, {
attributes: true,
characterData: false,
childList: true,
subtree: true,
attributeOldValue: true,
//characterDataOldValue: true
});
getQrFromCanvas();
}
function setIframe() {
iframe.src = "https://netfree.link/misc/whatsapp-web";
iframe.style.width = "100%"
var elm = document.querySelectorAll('.landing-title')[0].parentElement;
elm.querySelectorAll("li").forEach(i => i.parentElement.removeChild(i));
elm.appendChild(iframe);
iframe.addEventListener('load',x => observeQrChange());
}
function waitLoad() {
let mutationObserver = new MutationObserver(function (mutations) {
if (document.querySelectorAll('[data-ref]').length > 0) {
mutationObserver.disconnect();
setIframe();
}
});
mutationObserver.observe(document, {
attributes: true,
characterData: false,
childList: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true
});
}
waitLoad();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment