Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name block ads fb
- // @namespace block ads fb
- // @version 1
- // @description block ads fb
- // @author NguyenKhong
- // @include https://www.facebook.com/*
- // @grant unsafeWindow
- // @run-at document-start
- // ==/UserScript==
- unsafeWindow.document.addEventListener('DOMContentLoaded', function(){
- function searchNodeAds(node){
- if (node && node.attributes.hasOwnProperty("role") && node.attributes.role.textContent === "feed" ){
- let subNodes = node.querySelectorAll("div[data-pagelet]");
- for(let i = 0; i < subNodes.length; i++){
- if(subNodes[i].textContent.substr(0, 512).indexOf("Được tài trợ") > -1){
- subNodes[i].remove();
- }
- }
- }
- return;
- }
- (function injectMutationObserver () {
- var mutationObserver = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- switch (mutation.type) {
- case "childList":
- // auto redirect tag a
- searchNodeAds(mutation.target);
- return;
- /*
- case "attributes":
- // auto click button
- if (mutation.target.tagName === "VIDEO" && mutation.attributeName === "src"){
- //console.log("attributes", mutation);
- buildMenu(mutation.target);
- }
- return;
- */
- }
- });
- });
- mutationObserver.observe(unsafeWindow.document.body, {
- attributes: false,
- characterData: false,
- childList: true,
- subtree: true,
- attributeOldValue: false,
- characterDataOldValue: false
- });
- })();
- });
Add Comment
Please, Sign In to add comment