Advertisement
DigitalCliques

Bloqueios de dominios do WhatsApp Web

Jun 16th, 2025
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.70 KB | Source Code | 0 0
  1. (function() {
  2.   const blockedDomains = [
  3.     "privatestats.whatsapp.net",
  4.     "dit.whatsapp.net",
  5.     "graph.facebook.com",
  6.     "graph.whatsapp.net",
  7.     "graph.whatsapp.com"
  8.   ];
  9.  
  10.   function isBlocked(url) {
  11.     try {
  12.       const hostname = new URL(url).hostname;
  13.       return blockedDomains.some(dom => hostname === dom || hostname.endsWith("." + dom));
  14.     } catch (e) {
  15.       return false;
  16.     }
  17.   }
  18.  
  19.   // Intercepta fetch
  20.   const origFetch = window.fetch;
  21.   window.fetch = async function(input, init) {
  22.     const url = typeof input === "string" ? input : input.url;
  23.     if (isBlocked(url)) {
  24.       console.warn("[Bloqueado pelo script] fetch para:", url);
  25.       localStorage.setItem("ultBloqueio", JSON.stringify({url, time: Date.now()}));
  26.       return new Response(null, { status: 418, statusText: "Blocked by script" });
  27.     }
  28.     return origFetch.call(this, input, init);
  29.   };
  30.  
  31.   // Intercepta XMLHttpRequest
  32.   const OrigXHR = window.XMLHttpRequest;
  33.   function XHRProxy() {
  34.     const xhr = new OrigXHR();
  35.     const origOpen = xhr.open;
  36.     xhr.open = function(method, url, ...rest) {
  37.       this._url = url;
  38.       return origOpen.call(this, method, url, ...rest);
  39.     };
  40.     xhr.send = function(...args) {
  41.       if (isBlocked(this._url)) {
  42.         console.warn("[Bloqueado pelo script] XHR para:", this._url);
  43.         localStorage.setItem("ultBloqueioXHR", JSON.stringify({url: this._url, time: Date.now()}));
  44.         this.abort();
  45.         return;
  46.       }
  47.       return OrigXHR.prototype.send.apply(this, args);
  48.     };
  49.     return xhr;
  50.   }
  51.   window.XMLHttpRequest = XHRProxy;
  52.  
  53.   console.log("🛡️ Script de bloqueio de domínios de rastreamento do WhatsApp/Facebook ativado.");
  54. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement