Fix: handle styleAdded message in popup
This commit is contained in:
parent
81f3e69574
commit
f85d4de39b
|
@ -25,7 +25,7 @@
|
||||||
if (/^url:/i.test(query)) {
|
if (/^url:/i.test(query)) {
|
||||||
matchUrl = query.slice(query.indexOf(':') + 1).trim();
|
matchUrl = query.slice(query.indexOf(':') + 1).trim();
|
||||||
if (matchUrl) {
|
if (matchUrl) {
|
||||||
return styleManager.getStylesByUrl(matchUrl, true)
|
return styleManager.getStylesByUrl(matchUrl)
|
||||||
.then(results => results.map(r => r.data.id));
|
.then(results => results.map(r => r.data.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,15 +277,17 @@ const styleManager = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get styles matching a URL, including sloppy regexps and excluded items.
|
// get styles matching a URL, including sloppy regexps and excluded items.
|
||||||
function getStylesByUrl(url, noCode = false) {
|
function getStylesByUrl(url, id = null) {
|
||||||
// FIXME: do we want to cache this? Who would like to open popup rapidly
|
// FIXME: do we want to cache this? Who would like to open popup rapidly
|
||||||
// or search the DB with the same URL?
|
// or search the DB with the same URL?
|
||||||
const result = [];
|
const result = [];
|
||||||
for (const style of styles.values()) {
|
const datas = !id ? styles.values.map(s => s.data) :
|
||||||
|
styles.has(id) ? [styles.get(id).data] : [];
|
||||||
|
for (const data of datas) {
|
||||||
let excluded = false;
|
let excluded = false;
|
||||||
let sloppy = false;
|
let sloppy = false;
|
||||||
let sectionMatched = false;
|
let sectionMatched = false;
|
||||||
const match = urlMatchStyle(url, style.data);
|
const match = urlMatchStyle(url, data);
|
||||||
// TODO: enable this when the function starts returning false
|
// TODO: enable this when the function starts returning false
|
||||||
// if (match === false) {
|
// if (match === false) {
|
||||||
// continue;
|
// continue;
|
||||||
|
@ -293,7 +295,7 @@ const styleManager = (() => {
|
||||||
if (match === 'excluded') {
|
if (match === 'excluded') {
|
||||||
excluded = true;
|
excluded = true;
|
||||||
}
|
}
|
||||||
for (const section of style.data.sections) {
|
for (const section of data.sections) {
|
||||||
if (styleCodeEmpty(section.code)) {
|
if (styleCodeEmpty(section.code)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -308,7 +310,7 @@ const styleManager = (() => {
|
||||||
}
|
}
|
||||||
if (sectionMatched) {
|
if (sectionMatched) {
|
||||||
result.push({
|
result.push({
|
||||||
data: noCode ? getStyleWithNoCode(style.data) : style.data,
|
data: getStyleWithNoCode(data),
|
||||||
excluded,
|
excluded,
|
||||||
sloppy
|
sloppy
|
||||||
});
|
});
|
||||||
|
|
|
@ -25,7 +25,7 @@ getActiveTab()
|
||||||
)
|
)
|
||||||
.then(url => Promise.all([
|
.then(url => Promise.all([
|
||||||
(tabURL = URLS.supported(url) ? url : '') &&
|
(tabURL = URLS.supported(url) ? url : '') &&
|
||||||
API.getStylesByUrl(tabURL, true),
|
API.getStylesByUrl(tabURL),
|
||||||
onDOMready().then(initPopup),
|
onDOMready().then(initPopup),
|
||||||
]))
|
]))
|
||||||
.then(([results]) => {
|
.then(([results]) => {
|
||||||
|
@ -506,18 +506,13 @@ function handleUpdate(style) {
|
||||||
}
|
}
|
||||||
if (!tabURL) return;
|
if (!tabURL) return;
|
||||||
// Add an entry when a new style for the current url is installed
|
// Add an entry when a new style for the current url is installed
|
||||||
// FIXME: what does this do?
|
API.getStylesByUrl(tabURL, style.id).then(([style]) => {
|
||||||
// API.getStyles({
|
if (style) {
|
||||||
// matchUrl: tabURL,
|
document.body.classList.remove('blocked');
|
||||||
// stopOnFirst: true,
|
$$.remove('.blocked-info, #no-styles');
|
||||||
// omitCode: true,
|
createStyleElement({style, check: true});
|
||||||
// }).then(([style]) => {
|
}
|
||||||
// if (style) {
|
});
|
||||||
// document.body.classList.remove('blocked');
|
|
||||||
// $$.remove('.blocked-info, #no-styles');
|
|
||||||
// createStyleElement({style, check: true});
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user