Add: return excluded/sloppy state in getStylesInfoByUrl
This commit is contained in:
parent
f6ce78f55b
commit
36e13f88f0
|
@ -26,7 +26,7 @@
|
|||
matchUrl = query.slice(query.indexOf(':') + 1).trim();
|
||||
if (matchUrl) {
|
||||
return styleManager.getStylesInfoByUrl(matchUrl)
|
||||
.then(styles => styles.map(style => style.id));
|
||||
.then(results => results.map(r => r.data.id));
|
||||
}
|
||||
}
|
||||
if (query.startsWith('/') && /^\/(.+?)\/([gimsuy]*)$/.test(query)) {
|
||||
|
|
|
@ -277,9 +277,42 @@ const styleManager = (() => {
|
|||
}
|
||||
|
||||
function getStylesInfoByUrl(url) {
|
||||
const sections = getSectionsByUrl(url);
|
||||
return Object.keys(sections)
|
||||
.map(k => getStyleWithNoCode(styles.get(Number(k)).data));
|
||||
// FIXME: do we want to cache this? Who would like to rapidly using popup
|
||||
// or searching the DB with the same URL?
|
||||
const result = [];
|
||||
for (const style of styles.values()) {
|
||||
let excluded = false;
|
||||
let sloppy = false;
|
||||
let sectionMatched = false;
|
||||
const match = urlMatchStyle(url, style.data);
|
||||
if (match === false) {
|
||||
continue;
|
||||
}
|
||||
if (match === 'excluded') {
|
||||
excluded = true;
|
||||
}
|
||||
for (const section of style.data.sections) {
|
||||
if (styleCodeEmpty(section.code)) {
|
||||
continue;
|
||||
}
|
||||
const match = urlMatchSection(url, section);
|
||||
if (match) {
|
||||
if (match === 'sloppy') {
|
||||
sloppy = true;
|
||||
}
|
||||
sectionMatched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (sectionMatched) {
|
||||
result.push({
|
||||
data: getStyleWithNoCode(style.data),
|
||||
excluded,
|
||||
sloppy
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function getSectionsByUrl(url, filter) {
|
||||
|
|
|
@ -25,9 +25,10 @@ getActiveTab().then(tab =>
|
|||
(tabURL = URLS.supported(url) ? url : '') &&
|
||||
API.getStylesInfoByUrl(tabURL),
|
||||
onDOMready().then(initPopup),
|
||||
])).then(([styles]) => {
|
||||
showStyles(styles);
|
||||
});
|
||||
])).then(([results]) => {
|
||||
console.log(results);
|
||||
showStyles(results.map(r => Object.assign(r.data, r)));
|
||||
}).catch(console.error);
|
||||
|
||||
msg.onExtension(onRuntimeMessage);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user