Link to Facebook Ad Library

try to take over the world!

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Link to Facebook Ad Library
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.facebook.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    let url = document.URL
    let re1 = /&id=(\d+)/
    let re2 = /facebook\.com\/(\d+)/
    let page_id1 = url.match(re1)
    let page_id2 = url.match(re2)
    console.log("page_id2",page_id1)
    if (page_id1) {
        let ad_url=`https://www.facebook.com/ads/library/?active_status=all&ad_type=all&country=ALL&view_all_page_id=${page_id1[1]}&sort_data[direction]=desc&sort_data[mode]=relevancy_monthly_grouped`
        window.open(ad_url, "_blank")
    } else {
        let ad_url=`https://www.facebook.com/ads/library/?active_status=all&ad_type=all&country=ALL&view_all_page_id=${page_id2[1]}&sort_data[direction]=desc&sort_data[mode]=relevancy_monthly_grouped`
        window.open(ad_url, "_blank")
    }

})();