Kijiji: Hide Non-Local Listings

Removes ads with only "Canada" or provence name listed as location

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Kijiji: Hide Non-Local Listings
// @description  Removes ads with only "Canada" or provence name listed as location
// @match        https://www.kijiji.ca/b*
// @version      0.1
// @author       mica
// @namespace    greasyfork.org/users/12559
// @license      MIT
// ==/UserScript==

const list = [
    'Canada',
    'Alberta',
    'British Columbia',
    'Manitoba',
    'New Brunswick',
    'Newfoundland',
    'Northwest Territories',
    'Nova Scotia',
    'Ontario',
    'Prince Edward Island',
    'Québec',
    'Saskatchewan',
    'Yukon'
];

const observer = new MutationObserver(() => {
    var elements = document.querySelectorAll('p[data-testid="listing-location"]')
    elements.forEach((element) => {
        if (list.includes(element.innerText)) {
            element.closest('li').style.display = 'none';
        }
    });
});

observer.observe(document.body, {
    childList: true,
    subtree: true
});