Skip to content

Commit

Permalink
chore: extract to helper
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Mar 28, 2019
1 parent a71054c commit 6bc9ebb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/renderer/content-scripts-injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
const { runInThisContext } = require('vm')

const escapePattern = function (pattern) {
return pattern.split('*').map(x => x.replace(/[\\^$+?.()|[\]{}]/g, '\\$&'))).join('.*')
}

// Check whether pattern matches.
// https://developer.chrome.com/extensions/match_patterns
const matchesPattern = function (pattern) {
if (pattern === '<all_urls>') return true
const regexp = new RegExp(`^${pattern.split('*').map(x => x.replace(/[\\^$+?.()|[\]{}]/g, '\\$&'))).join('.*')}$`)
const regexp = new RegExp(`^${escapePattern(pattern)}$`)
const url = `${location.protocol}//${location.host}${location.pathname}`
return url.match(regexp)
}
Expand Down

0 comments on commit 6bc9ebb

Please sign in to comment.