Facebook Ad Preferences Cleaner

Automatically removes Facebook Ad "preferences" upon loading https://www.facebook.com/ds/preferences/

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Facebook Ad Preferences Cleaner
// @namespace    https://www.facebook.com/ds/preferences/
// @version      1.01
// @description  Automatically removes Facebook Ad "preferences" upon loading https://www.facebook.com/ds/preferences/
// @author       JustSomeGuy
// @include      https://www.facebook.com/ds/preferences/
// @grant        none
// @license      MIT
// @donation     https://www.paypal.com/paypalme/iappreciateyoutoo
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function () {
        openContainer();
        removeInterests();
    });

    var removeInterests = setInterval(function() {
        var removeDiv = getDivContainer();
        if (typeof removeDiv !== 'undefined') {
            seeMore();
            removeDiv.click();
        } else {
            clearInterval(removeInterests);
            console.log(getCategory());
            if (getCategory() !== "Removed interests") {
                location.reload();
            }
        }
    }, 250);


    function getDivContainer() {
        var baseLoc = document.getElementsByTagName('iframe')[0];
        var containerMap = [1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1];
        baseLoc = baseLoc.contentWindow.document;
        for (var i = 0, len = containerMap.length; i < len; i++) {
            baseLoc = baseLoc.childNodes[containerMap[i]];
        }
        for (var i = 0, len = baseLoc.children.length; i < len; i++) {
            if (baseLoc.childNodes[i].childNodes[0].childNodes[0].childNodes[0].childNodes[1].innerHTML == "Remove") {
                return baseLoc.childNodes[i].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
            }
        }
    }

    function getCategory() {
        var categoryLoc = document.getElementsByTagName('iframe')[0];
        var containerMap = [1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        categoryLoc = categoryLoc.contentWindow.document;

        for (var i = 0, len = containerMap.length; i < len; i++) {
            categoryLoc = categoryLoc.childNodes[containerMap[i]];
        }
        return categoryLoc.innerHTML;
    }

    function seeMore() {
        var baseLoc = document.getElementsByTagName('iframe')[0];
        var containerMap = [1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 2];

        baseLoc = baseLoc.contentWindow.document;
        for (var i = 0, len = containerMap.length; i < len; i++) {
            baseLoc = baseLoc.childNodes[containerMap[i]];
        }

        setTimeout(function() {
            if (typeof(baseLoc) == 'undefined' || baseLoc == null) {
                return;
            } else {
                baseLoc.click();
                seeMore();
            }
        }, 100);
    }

    function openContainer() {
        var baseLoc = document.getElementsByTagName('iframe')[0];
        var containerMap = [1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1];
        baseLoc = baseLoc.contentWindow.document;
        for (var i = 0, len = containerMap.length; i < len; i++) {
            baseLoc = baseLoc.childNodes[containerMap[i]];
        }

        if (baseLoc.parentNode.childNodes[2].classList.contains('hidden_elem')) {
            baseLoc.click();
        }
    }
})();