Skip to content

Easier way to specify blocklistPattern #2342

@onguarde

Description

@onguarde

I'm using the helper function below to ease specifying the URL without having to escape etc. Should this be a built in function? Seems like a such a common use case, and is unnecessarily complicated for beginners.

// this works,
// settings.blocklistPattern = /.*mail\.google\.com.*|.*catanuniverse\.com.*|.*gist\.github\.com.*|.*excel\.officeapps\.live\.com.*|.*hp\.sharepoint\.com.*/

function createBlocklistPattern(urls) {
    const escapedPatterns = urls.map(url => 
        `.*${url.replace(/\./g, '\\.')}.*`
    );
    return new RegExp(escapedPatterns.join('|'));
}

const urlList = [
    'google.com',
    'catanuniverse.com',
    'gist.github.com',
    'excel.officeapps.live.com',
    'hp.sharepoint.com'
];

settings.blocklistPattern = createBlocklistPattern(urlList);

// does not work,
// settings.blacklistPattern = /.*mail.google.com.*|.*inbox.google.com.*|trello.com|duolingo.com|youtube.com|udemy.com|localhost/i;
// settings.blocklistPattern = /((calendar|mail).google|trello|duolingo|youtube|udemy).com/i

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions