Add tab communication

This commit is contained in:
Rob Garrison 2018-07-15 12:59:51 -05:00
parent 983a7bc219
commit bfe54ab4c4
5 changed files with 22 additions and 5 deletions

View File

@ -298,7 +298,6 @@ function filterStylesInternal({
const filtered = asHash ? {length: 0} : [];
const needSections = asHash || matchUrl !== null;
const matchUrlBase = matchUrl && matchUrl.includes('#') && matchUrl.split('#', 1)[0];
let style;
for (let i = 0; (style = styles[i]); i++) {
if ((enabled === null || style.enabled === enabled)
@ -483,9 +482,14 @@ function getApplicableSections({
// but the spec is outdated and doesn't account for SPA sites
// so we only respect it in case of url("http://exact.url/without/hash")
}) {
if (!skipUrlCheck && !URLS.supported(matchUrl) || omitCode !== false && isPageExcluded(matchUrl, style.exclusions)) {
const excluded = isPageExcluded(matchUrl, style.exclusions);
if (!skipUrlCheck && !URLS.supported(matchUrl) || omitCode !== false && excluded) {
return [];
}
// Show excluded style in popup
if (excluded) {
return [''];
}
const sections = [];
for (const section of style.sections) {
const {urls, domains, urlPrefixes, regexps, code} = section;

View File

@ -190,6 +190,12 @@ function onRuntimeMessage(request) {
case 'editDeleteText':
document.execCommand('delete');
break;
case 'exclusionsUpdated':
debounce(() => exclusions.update({
list: Object.keys(request.style.exclusions),
isUpdating: false
}), 100);
break;
}
}

View File

@ -16,13 +16,17 @@ const exclusions = (() => {
// get exclusions from a select element
function get() {
exclusions.list = {};
const list = {};
$$('#excluded-wrap input').forEach(input => {
const url = input.value;
if (url && validExclusionRegex.test(url)) {
exclusions.list[url] = createRegExp(url);
list[url] = createRegExp(url);
}
});
exclusions.list = Object.keys(list).sort().reduce((acc, ex) => {
acc[ex] = list[ex];
return acc;
}, {});
return exclusions.list;
}
@ -54,7 +58,7 @@ const exclusions = (() => {
const block = $('#excluded-wrap');
block.textContent = '';
const container = document.createDocumentFragment();
list.forEach(value => {
list.sort().forEach(value => {
addExclusionEntry({container, value});
});
block.appendChild(container);
@ -158,6 +162,7 @@ const exclusions = (() => {
style.exclusions = exclusionList;
style.reason = 'exclusionsUpdated';
API.saveStyle(style);
notifyAllTabs({method: 'exclusionsUpdated', style, id});
});
}

View File

@ -162,6 +162,7 @@ const popupExclusions = (() => {
entry.styleMeta = style;
entry.classList.toggle('excluded', isExcluded(tabURL, style.exclusions));
}
notifyAllTabs({method: 'exclusionsUpdated', style, id: entry.styleId});
}
return Promise.resolve();
}

View File

@ -35,6 +35,7 @@ function onRuntimeMessage(msg) {
switch (msg.method) {
case 'styleAdded':
case 'styleUpdated':
case 'exclusionsUpdated':
if (msg.reason === 'editPreview') return;
handleUpdate(msg.style);
break;