Only call favicon function for newUI

This commit is contained in:
Rob Garrison 2017-12-31 00:59:10 -06:00
parent b6c89b90a0
commit 59ebd30ec2

View File

@ -288,46 +288,46 @@ function recreateStyleTargets({styles, iconsOnly = false} = {}) {
}); });
} }
} }
debounce(getFaviconImgSrc); if (newUI.favicons) {
debounce(getFaviconImgSrc);
}
}); });
} }
function getFaviconImgSrc() { function getFaviconImgSrc() {
if (newUI.favicons) { const targets = $$('.target', installed);
const targets = $$('.target', installed); const regexpRemoveNegativeLookAhead = /(\?!([^)]+\)))/g;
const regexpRemoveNegativeLookAhead = /(\?!([^)]+\)))/g; const regexpMatchRegExp = /\w+[\\.(]+(com|org|co|net|im|io)\b/g;
const regexpMatchRegExp = /\w+[\\.(]+(com|org|co|net|im|io)\b/g; const regexpReplaceExtraCharacters = /[\\(]/g;
const regexpReplaceExtraCharacters = /[\\(]/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; const targetValue = target.textContent;
const targetValue = target.textContent; let favicon = '';
let favicon = ''; if (type === 'domains') {
if (type === 'domains') { favicon = GET_FAVICON_URL + targetValue;
favicon = GET_FAVICON_URL + targetValue; } else if (targetValue.startsWith('chrome-extension:') || targetValue.startsWith('moz-extension:')) {
} else if (targetValue.startsWith('chrome-extension:') || targetValue.startsWith('moz-extension:')) { favicon = OWN_ICON;
favicon = OWN_ICON; } else if (type === 'regexps') {
} else if (type === 'regexps') { favicon = targetValue.replace(regexpRemoveNegativeLookAhead, '').match(regexpMatchRegExp);
favicon = targetValue.replace(regexpRemoveNegativeLookAhead, '').match(regexpMatchRegExp); favicon = favicon ? GET_FAVICON_URL + favicon.shift().replace(regexpReplaceExtraCharacters, '') : '';
favicon = favicon ? GET_FAVICON_URL + favicon.shift().replace(regexpReplaceExtraCharacters, '') : ''; } 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] : ''; }
} if (favicon) {
if (favicon) { const img = target.children[0];
const img = target.children[0]; if (!img || img.localName !== 'img') {
if (!img || img.localName !== 'img') { target.insertAdjacentElement('afterbegin', document.createElement('img'))
target.insertAdjacentElement('afterbegin', document.createElement('img')) .dataset.src = favicon;
.dataset.src = favicon; } else if ((img.dataset.src || img.src) !== favicon) {
} else if ((img.dataset.src || img.src) !== favicon) { img.src = '';
img.src = ''; img.dataset.src = favicon;
img.dataset.src = favicon;
}
} }
} }
handleEvent.loadFavicons();
} }
handleEvent.loadFavicons();
} }