0

I'm looking for a solution to the match pattern rules for making a Google Chrome Extension - I'm trying to block websites such as Pinterest, the problem is that Pinterest has a million TLDs and rather than write out...

"*://pinterest.com/*, *://pinterest.se/*, *://pinterest.co.uk/*.. etc Forever

I'm trying to block all of Pinterest's Top Level Domains.

Using "*://pinterest.*/*" or "*://*.pinterest.*/*" does not work.

var blockedUrls = [ "*://*.pinterest.se/*, *://*.pinterest.com/*"];


var host = "https://www.google.com"


chrome.webRequest.onBeforeRequest.addListener(
function(details) {
     return {redirectUrl: host };
},
{
    urls:blockedUrls,

    types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["blocking"]
);

The above code works. Anyone got any idea how to do this, any nudge in the right direction would be appreciated. Many Thanks.

1 Answers1

0

In the documentation you have this example:

chrome.webRequest.onBeforeRequest.addListener(function(details) {
          return {cancel: details.url.indexOf("://www.evil.com/") != -1};
        },
        {urls: ["<all_urls>"]},
        ["blocking"]);

Just change www.evil.com/ by pinterest. and it will block all pinterest.* pages. If you want to block other subdomains like m.pinterest.com or images.pinterest.com (I don't know if these even exist) you could use RegExp.

Iván Nokonoko
  • 4,888
  • 2
  • 19
  • 27