Add: implement sloppy regexp indicator
This commit is contained in:
parent
36e13f88f0
commit
e67b7f4f36
|
@ -319,6 +319,10 @@ html[style*="border"] .entry:nth-child(11):before {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 90%;
|
font-size: 90%;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.regexp-partial .regexp-problem-indicator {
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.regexp-partial .actions,
|
.regexp-partial .actions,
|
||||||
|
@ -329,6 +333,8 @@ html[style*="border"] .entry:nth-child(11):before {
|
||||||
#regexp-explanation {
|
#regexp-explanation {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
padding: .5rem;
|
padding: .5rem;
|
||||||
|
|
|
@ -17,18 +17,21 @@ const ENTRY_ID_PREFIX = '#' + ENTRY_ID_PREFIX_RAW;
|
||||||
|
|
||||||
toggleSideBorders();
|
toggleSideBorders();
|
||||||
|
|
||||||
getActiveTab().then(tab =>
|
getActiveTab()
|
||||||
FIREFOX && tab.url === 'about:blank' && tab.status === 'loading'
|
.then(tab =>
|
||||||
? getTabRealURLFirefox(tab)
|
FIREFOX && tab.url === 'about:blank' && tab.status === 'loading'
|
||||||
: getTabRealURL(tab)
|
? getTabRealURLFirefox(tab)
|
||||||
).then(url => Promise.all([
|
: getTabRealURL(tab)
|
||||||
(tabURL = URLS.supported(url) ? url : '') &&
|
)
|
||||||
API.getStylesInfoByUrl(tabURL),
|
.then(url => Promise.all([
|
||||||
onDOMready().then(initPopup),
|
(tabURL = URLS.supported(url) ? url : '') &&
|
||||||
])).then(([results]) => {
|
API.getStylesInfoByUrl(tabURL),
|
||||||
console.log(results);
|
onDOMready().then(initPopup),
|
||||||
showStyles(results.map(r => Object.assign(r.data, r)));
|
]))
|
||||||
}).catch(console.error);
|
.then(([results]) => {
|
||||||
|
showStyles(results.map(r => Object.assign(r.data, r)));
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
|
||||||
msg.onExtension(onRuntimeMessage);
|
msg.onExtension(onRuntimeMessage);
|
||||||
|
|
||||||
|
@ -230,27 +233,12 @@ function showStyles(styles) {
|
||||||
const container = document.createDocumentFragment();
|
const container = document.createDocumentFragment();
|
||||||
styles.forEach(style => createStyleElement({style, container}));
|
styles.forEach(style => createStyleElement({style, container}));
|
||||||
installed.appendChild(container);
|
installed.appendChild(container);
|
||||||
setTimeout(detectSloppyRegexps, 100, styles);
|
|
||||||
|
|
||||||
// FIXME: detect sloppy regexp?
|
|
||||||
// API.getStyles({
|
|
||||||
// matchUrl: tabURL,
|
|
||||||
// strictRegexp: false,
|
|
||||||
// omitCode: true,
|
|
||||||
// }).then(unscreenedStyles => {
|
|
||||||
// for (const style of unscreenedStyles) {
|
|
||||||
// if (!styles.find(({id}) => id === style.id)) {
|
|
||||||
// createStyleElement({style, check: true});
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
window.dispatchEvent(new Event('showStyles:done'));
|
window.dispatchEvent(new Event('showStyles:done'));
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function createStyleElement({
|
function createStyleElement({
|
||||||
style,
|
style,
|
||||||
check = false,
|
|
||||||
container = installed,
|
container = installed,
|
||||||
}) {
|
}) {
|
||||||
let entry = $(ENTRY_ID_PREFIX + style.id);
|
let entry = $(ENTRY_ID_PREFIX + style.id);
|
||||||
|
@ -294,6 +282,11 @@ function createStyleElement({
|
||||||
$('.disable', entry).onclick = handleEvent.toggle;
|
$('.disable', entry).onclick = handleEvent.toggle;
|
||||||
$('.delete', entry).onclick = handleEvent.delete;
|
$('.delete', entry).onclick = handleEvent.delete;
|
||||||
$('.configure', entry).onclick = handleEvent.configure;
|
$('.configure', entry).onclick = handleEvent.configure;
|
||||||
|
|
||||||
|
const indicator = template.regexpProblemIndicator.cloneNode(true);
|
||||||
|
indicator.appendChild(document.createTextNode('!'));
|
||||||
|
indicator.onclick = handleEvent.indicator;
|
||||||
|
$('.main-controls', entry).appendChild(indicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
style = Object.assign(entry.styleMeta, style);
|
style = Object.assign(entry.styleMeta, style);
|
||||||
|
@ -314,9 +307,10 @@ function createStyleElement({
|
||||||
const styleName = $('.style-name', entry);
|
const styleName = $('.style-name', entry);
|
||||||
styleName.lastChild.textContent = style.name;
|
styleName.lastChild.textContent = style.name;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (styleName.scrollWidth > styleName.clientWidth + 1) {
|
styleName.title = entry.styleMeta.sloppy ?
|
||||||
styleName.title = styleName.textContent;
|
t('styleNotAppliedRegexpProblemTooltip') :
|
||||||
}
|
styleName.scrollWidth > styleName.clientWidth + 1 ?
|
||||||
|
styleName.textContent : '';
|
||||||
});
|
});
|
||||||
|
|
||||||
const config = $('.configure', entry);
|
const config = $('.configure', entry);
|
||||||
|
@ -330,7 +324,8 @@ function createStyleElement({
|
||||||
style.usercssData && Object.keys(style.usercssData.vars || {}).length ?
|
style.usercssData && Object.keys(style.usercssData.vars || {}).length ?
|
||||||
'' : 'none';
|
'' : 'none';
|
||||||
|
|
||||||
if (check) detectSloppyRegexps([style]);
|
entry.classList.toggle('not-applied', style.excluded || style.sloppy);
|
||||||
|
entry.classList.toggle('regexp-partial', style.sloppy);
|
||||||
|
|
||||||
if (entry.parentNode !== container) {
|
if (entry.parentNode !== container) {
|
||||||
container.appendChild(entry);
|
container.appendChild(entry);
|
||||||
|
@ -532,32 +527,6 @@ function handleDelete(id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function detectSloppyRegexps(styles) {
|
|
||||||
API.detectSloppyRegexps({
|
|
||||||
matchUrl: tabURL,
|
|
||||||
ids: styles.map(({id}) => id),
|
|
||||||
}).then(results => {
|
|
||||||
for (const {id, applied, skipped, hasInvalidRegexps} of results) {
|
|
||||||
const entry = $(ENTRY_ID_PREFIX + id);
|
|
||||||
if (!entry) continue;
|
|
||||||
if (!applied) {
|
|
||||||
entry.classList.add('not-applied');
|
|
||||||
$('.style-name', entry).title = t('styleNotAppliedRegexpProblemTooltip');
|
|
||||||
}
|
|
||||||
if (skipped || hasInvalidRegexps) {
|
|
||||||
entry.classList.toggle('regexp-partial', Boolean(skipped));
|
|
||||||
entry.classList.toggle('regexp-invalid', Boolean(hasInvalidRegexps));
|
|
||||||
const indicator = template.regexpProblemIndicator.cloneNode(true);
|
|
||||||
indicator.appendChild(document.createTextNode(entry.skipped || '!'));
|
|
||||||
indicator.onclick = handleEvent.indicator;
|
|
||||||
$('.main-controls', entry).appendChild(indicator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function getTabRealURLFirefox(tab) {
|
function getTabRealURLFirefox(tab) {
|
||||||
// wait for FF tab-on-demand to get a real URL (initially about:blank), 5 sec max
|
// wait for FF tab-on-demand to get a real URL (initially about:blank), 5 sec max
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user