Fix wrapped negative look ahead & extra grouped items

See https://jsbin.com/miyujifaco/edit?js,console
This commit is contained in:
Rob Garrison 2017-12-31 12:59:21 -06:00
parent d278d26553
commit 3f36ecd8e5

View File

@ -294,12 +294,13 @@ function recreateStyleTargets({styles, iconsOnly = false} = {}) {
}); });
} }
function getFaviconImgSrc() { function getFaviconImgSrc() {
const targets = $$('.target', installed); const targets = $$('.target', installed);
const regexpRemoveNegativeLookAhead = /(\?!([^)]+\)))/g; const regexpRemoveNegativeLookAhead = /(\?!([^)]+\))|\(\?![\w(]+[^)]+[\w|)]+)/g;
const regexpMatchRegExp = /\w+[\\.(]+(com|org|co|net|im|io)\b/g; // replace extra characters & all but the first group entry "(abc|def|ghi)xyz" => abcxyz
const regexpReplaceExtraCharacters = /[\\(]/g; 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 = /^.*?:\/\/([^/]+)/; const regexpMatchDomain = /^.*?:\/\/([^/]+)/;
for (const target of targets) { for (const target of targets) {
const type = target.dataset.type; const type = target.dataset.type;
@ -310,8 +311,11 @@ function getFaviconImgSrc() {
} else if (targetValue.includes('chrome-extension:') || targetValue.includes('moz-extension:')) { } else if (targetValue.includes('chrome-extension:') || targetValue.includes('moz-extension:')) {
favicon = OWN_ICON; favicon = OWN_ICON;
} else if (type === 'regexps') { } else if (type === 'regexps') {
favicon = targetValue.replace(regexpRemoveNegativeLookAhead, '').match(regexpMatchRegExp); favicon = targetValue
favicon = favicon ? GET_FAVICON_URL + favicon.shift().replace(regexpReplaceExtraCharacters, '') : ''; .replace(regexpRemoveNegativeLookAhead, '')
.replace(regexpReplaceExtraCharacters, '')
.match(regexpMatchRegExp);
favicon = favicon ? GET_FAVICON_URL + favicon.shift() : '';
} else { } else {
favicon = targetValue.includes('://') && targetValue.match(regexpMatchDomain); favicon = targetValue.includes('://') && targetValue.match(regexpMatchDomain);
favicon = favicon ? GET_FAVICON_URL + favicon[1] : ''; favicon = favicon ? GET_FAVICON_URL + favicon[1] : '';