nht_cntt

Chặn quảng cáo fb dạng Được tài trợ

Jan 2nd, 2021 (edited)
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         block ads fb
  3. // @namespace    block ads fb
  4. // @version      1
  5. // @description  block ads fb
  6. // @author       NguyenKhong
  7. // @include      https://www.facebook.com/*
  8. // @grant        unsafeWindow
  9. // @run-at       document-start
  10. // ==/UserScript==
  11.  
  12. unsafeWindow.document.addEventListener('DOMContentLoaded', function(){
  13.     function searchNodeAds(node){
  14.         if (node && node.attributes.hasOwnProperty("role") && node.attributes.role.textContent === "feed" ){
  15.             let subNodes = node.querySelectorAll("div[data-pagelet]");
  16.             for(let i = 0; i < subNodes.length; i++){
  17.                 if(subNodes[i].textContent.substr(0, 512).indexOf("Được tài trợ") > -1){
  18.                     subNodes[i].remove();
  19.                 }
  20.             }
  21.         }
  22.         return;
  23.     }
  24.  
  25.     (function injectMutationObserver () {
  26.         var mutationObserver = new MutationObserver(function(mutations) {
  27.             mutations.forEach(function(mutation) {
  28.                 switch (mutation.type) {
  29.                     case "childList":
  30.                         // auto redirect tag a
  31.                         searchNodeAds(mutation.target);
  32.                         return;
  33.                     /*
  34.                     case "attributes":
  35.                         // auto click button
  36.                         if (mutation.target.tagName === "VIDEO" && mutation.attributeName === "src"){
  37.                             //console.log("attributes", mutation);
  38.                             buildMenu(mutation.target);
  39.                         }
  40.                         return;
  41.                         */
  42.                 }
  43.             });
  44.         });
  45.         mutationObserver.observe(unsafeWindow.document.body, {
  46.             attributes: false,
  47.             characterData: false,
  48.             childList: true,
  49.             subtree: true,
  50.             attributeOldValue: false,
  51.             characterDataOldValue: false
  52.         });
  53.     })();
  54. });
Add Comment
Please, Sign In to add comment