fix show-more in old UI and simplify generation of targets
This commit is contained in:
parent
74d9a0d8ba
commit
918debe110
|
@ -153,17 +153,16 @@ function showStyles(styles = [], matchUrlIds) {
|
|||
filterAndAppend({container: renderBin}).then(sorter.updateStripes);
|
||||
if (index < sorted.length) {
|
||||
requestAnimationFrame(renderStyles);
|
||||
if (firstRun) setTimeout(recreateStyleTargets, 0, {styles, iconsOnly: true});
|
||||
if (firstRun) setTimeout(getFaviconImgSrc);
|
||||
firstRun = false;
|
||||
return;
|
||||
}
|
||||
if (newUI.enabled && newUI.favicons) {
|
||||
setTimeout(recreateStyleTargets, 0, {iconsOnly: true});
|
||||
}
|
||||
if ('scrollY' in (history.state || {}) && !sessionStorage.justEditedStyleId) {
|
||||
setTimeout(getFaviconImgSrc);
|
||||
if (sessionStorage.justEditedStyleId) {
|
||||
highlightEditedStyle();
|
||||
} else if ('scrollY' in (history.state || {})) {
|
||||
setTimeout(window.scrollTo, 0, 0, history.state.scrollY);
|
||||
}
|
||||
highlightEditedStyle();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,10 +237,10 @@ function createStyleElement({style, name}) {
|
|||
}
|
||||
|
||||
|
||||
function createStyleTargetsElement({entry, style, iconsOnly}) {
|
||||
function createStyleTargetsElement({entry, style}) {
|
||||
const parts = createStyleElement.parts;
|
||||
const entryTargets = $('.targets', entry);
|
||||
const targets = iconsOnly ? entryTargets : parts.targets.cloneNode(true);
|
||||
const targets = parts.targets.cloneNode(true);
|
||||
let container = targets;
|
||||
let numTargets = 0;
|
||||
const displayed = new Set();
|
||||
|
@ -252,15 +251,14 @@ function createStyleTargetsElement({entry, style, iconsOnly}) {
|
|||
continue;
|
||||
}
|
||||
displayed.add(targetValue);
|
||||
const element = iconsOnly ? targets.children[numTargets] : template.appliesToTarget.cloneNode(true);
|
||||
const element = template.appliesToTarget.cloneNode(true);
|
||||
if (!newUI.enabled) {
|
||||
if (numTargets === 10) {
|
||||
container = container.appendChild(template.extraAppliesTo.cloneNode(true));
|
||||
} else if (numTargets > 1) {
|
||||
} else if (numTargets > 0) {
|
||||
container.appendChild(template.appliesToSeparator.cloneNode(true));
|
||||
}
|
||||
}
|
||||
if (!iconsOnly) {
|
||||
element.dataset.type = type;
|
||||
element.appendChild(
|
||||
document.createTextNode(
|
||||
|
@ -268,7 +266,6 @@ function createStyleTargetsElement({entry, style, iconsOnly}) {
|
|||
targetValue +
|
||||
(parts.decorations[type + 'After'] || '')));
|
||||
container.appendChild(element);
|
||||
}
|
||||
numTargets++;
|
||||
}
|
||||
}
|
||||
|
@ -279,9 +276,7 @@ function createStyleTargetsElement({entry, style, iconsOnly}) {
|
|||
}
|
||||
}
|
||||
if (numTargets) {
|
||||
if (!iconsOnly) {
|
||||
entryTargets.parentElement.replaceChild(targets, entryTargets);
|
||||
}
|
||||
} else if (!entry.classList.contains('global') ||
|
||||
!entryTargets.firstElementChild) {
|
||||
if (entryTargets.firstElementChild) {
|
||||
|
@ -293,25 +288,8 @@ function createStyleTargetsElement({entry, style, iconsOnly}) {
|
|||
}
|
||||
|
||||
|
||||
function recreateStyleTargets({styles, iconsOnly = false} = {}) {
|
||||
Promise.resolve(styles || API.getStyles()).then(styles => {
|
||||
for (const style of styles) {
|
||||
const entry = $(ENTRY_ID_PREFIX + style.id);
|
||||
if (entry) {
|
||||
createStyleTargetsElement({
|
||||
entry,
|
||||
style,
|
||||
iconsOnly,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (newUI.enabled && newUI.favicons) {
|
||||
debounce(getFaviconImgSrc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getFaviconImgSrc(container = installed) {
|
||||
if (!newUI.enabled || !newUI.favicons) return;
|
||||
const regexpRemoveNegativeLookAhead = /(\?!([^)]+\))|\(\?![\w(]+[^)]+[\w|)]+)/g;
|
||||
// replace extra characters & all but the first group entry "(abc|def|ghi)xyz" => abcxyz
|
||||
const regexpReplaceExtraCharacters = /[\\(]|((\|\w+)+\))/g;
|
||||
|
@ -557,9 +535,7 @@ function handleUpdate(style, {reason, method} = {}) {
|
|||
animateElement(entry);
|
||||
requestAnimationFrame(() => scrollElementIntoView(entry));
|
||||
}
|
||||
if (newUI.enabled && newUI.favicons) {
|
||||
getFaviconImgSrc(entry);
|
||||
}
|
||||
|
||||
function handleToggledOrCodeOnly() {
|
||||
const newStyleMeta = getStyleWithNoCode(style);
|
||||
|
@ -673,7 +649,7 @@ function switchUI({styleOnly} = {}) {
|
|||
return;
|
||||
}
|
||||
if (missingFavicons) {
|
||||
recreateStyleTargets();
|
||||
debounce(getFaviconImgSrc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user