From 3f36ecd8e543689b93e8b8eaa29cce9eae6f5f67 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Sun, 31 Dec 2017 12:59:21 -0600 Subject: [PATCH] Fix wrapped negative look ahead & extra grouped items See https://jsbin.com/miyujifaco/edit?js,console --- manage/manage.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/manage/manage.js b/manage/manage.js index 81ad0868..92018467 100644 --- a/manage/manage.js +++ b/manage/manage.js @@ -294,12 +294,13 @@ function recreateStyleTargets({styles, iconsOnly = false} = {}) { }); } - function getFaviconImgSrc() { const targets = $$('.target', installed); - const regexpRemoveNegativeLookAhead = /(\?!([^)]+\)))/g; - const regexpMatchRegExp = /\w+[\\.(]+(com|org|co|net|im|io)\b/g; - const regexpReplaceExtraCharacters = /[\\(]/g; + const regexpRemoveNegativeLookAhead = /(\?!([^)]+\))|\(\?![\w(]+[^)]+[\w|)]+)/g; + // replace extra characters & all but the first group entry "(abc|def|ghi)xyz" => abcxyz + const regexpReplaceExtraCharacters = /[\\(]|((\|\w+)+\))/g; + const domainExt = 'com,org,co,net,im,io,edu,gov,biz,info,de,cn,uk,nl,eu,ru'.split(','); + const regexpMatchRegExp = new RegExp(`[\\w-]+[\\.(]+(${domainExt.join('|')})\\b`, 'g'); const regexpMatchDomain = /^.*?:\/\/([^/]+)/; for (const target of targets) { const type = target.dataset.type; @@ -310,8 +311,11 @@ function getFaviconImgSrc() { } else if (targetValue.includes('chrome-extension:') || targetValue.includes('moz-extension:')) { favicon = OWN_ICON; } else if (type === 'regexps') { - favicon = targetValue.replace(regexpRemoveNegativeLookAhead, '').match(regexpMatchRegExp); - favicon = favicon ? GET_FAVICON_URL + favicon.shift().replace(regexpReplaceExtraCharacters, '') : ''; + favicon = targetValue + .replace(regexpRemoveNegativeLookAhead, '') + .replace(regexpReplaceExtraCharacters, '') + .match(regexpMatchRegExp); + favicon = favicon ? GET_FAVICON_URL + favicon.shift() : ''; } else { favicon = targetValue.includes('://') && targetValue.match(regexpMatchDomain); favicon = favicon ? GET_FAVICON_URL + favicon[1] : '';