Restore implicit handleUpdate in saveStyle
This commit is contained in:
parent
a6c3424b53
commit
8bcd7f60c5
|
@ -85,8 +85,10 @@ function importFromString(jsonString) {
|
||||||
stats.unchanged.ids.push(oldStyle.id);
|
stats.unchanged.ids.push(oldStyle.id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
saveStyle(item, {notify: false}).then(style => {
|
saveStyle(Object.assign(item, {
|
||||||
handleUpdate(style, {reason: 'import'});
|
reason: 'import',
|
||||||
|
notify: false,
|
||||||
|
})).then(style => {
|
||||||
setTimeout(proceed, 0, resolve);
|
setTimeout(proceed, 0, resolve);
|
||||||
if (!oldStyle) {
|
if (!oldStyle) {
|
||||||
stats.added.names.push(style.name);
|
stats.added.names.push(style.name);
|
||||||
|
@ -160,11 +162,12 @@ function importFromString(jsonString) {
|
||||||
}
|
}
|
||||||
const id = newIds[index++];
|
const id = newIds[index++];
|
||||||
deleteStyle(id, {notify: false}).then(id => {
|
deleteStyle(id, {notify: false}).then(id => {
|
||||||
handleDelete(id);
|
|
||||||
const oldStyle = oldStylesById.get(id);
|
const oldStyle = oldStylesById.get(id);
|
||||||
if (oldStyle) {
|
if (oldStyle) {
|
||||||
saveStyle(Object.assign(oldStyle, {reason: 'undoImport'}), {notify: false})
|
saveStyle(Object.assign(oldStyle, {
|
||||||
.then(handleUpdate)
|
reason: 'undoImport',
|
||||||
|
notify: false,
|
||||||
|
}))
|
||||||
.then(() => setTimeout(undoNextId, 0, resolve));
|
.then(() => setTimeout(undoNextId, 0, resolve));
|
||||||
} else {
|
} else {
|
||||||
setTimeout(undoNextId, 0, resolve);
|
setTimeout(undoNextId, 0, resolve);
|
||||||
|
|
55
manage.js
55
manage.js
|
@ -82,7 +82,7 @@ function showStyles(styles = []) {
|
||||||
const t0 = performance.now();
|
const t0 = performance.now();
|
||||||
while (index < sorted.length && (shouldRenderAll || performance.now() - t0 < 10)) {
|
while (index < sorted.length && (shouldRenderAll || performance.now() - t0 < 10)) {
|
||||||
renderBin.appendChild(createStyleElement(sorted[index++].style));
|
renderBin.appendChild(createStyleElement(sorted[index++].style));
|
||||||
}
|
}
|
||||||
if ($('#search').value) {
|
if ($('#search').value) {
|
||||||
// re-apply filtering on history Back
|
// re-apply filtering on history Back
|
||||||
searchStyles(true, renderBin);
|
searchStyles(true, renderBin);
|
||||||
|
@ -122,8 +122,8 @@ function createStyleElement(style) {
|
||||||
const homepage = template.styleHomepage.cloneNode(true);
|
const homepage = template.styleHomepage.cloneNode(true);
|
||||||
homepage.href = style.url;
|
homepage.href = style.url;
|
||||||
styleName.appendChild(document.createTextNode(' '));
|
styleName.appendChild(document.createTextNode(' '));
|
||||||
styleName.appendChild(homepage);
|
styleName.appendChild(homepage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const targets = new Map(TARGET_TYPES.map(t => [t, new Set()]));
|
const targets = new Map(TARGET_TYPES.map(t => [t, new Set()]));
|
||||||
const decorations = {
|
const decorations = {
|
||||||
|
@ -138,9 +138,9 @@ function createStyleElement(style) {
|
||||||
(decorations[name + 'Before'] || '') +
|
(decorations[name + 'Before'] || '') +
|
||||||
targetValue.trim() +
|
targetValue.trim() +
|
||||||
(decorations[name + 'After'] || ''));
|
(decorations[name + 'After'] || ''));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const appliesTo = $('.applies-to', entry);
|
const appliesTo = $('.applies-to', entry);
|
||||||
appliesTo.firstElementChild.textContent = TARGET_LABEL;
|
appliesTo.firstElementChild.textContent = TARGET_LABEL;
|
||||||
const targetsList = Array.prototype.concat.apply([],
|
const targetsList = Array.prototype.concat.apply([],
|
||||||
|
@ -154,18 +154,18 @@ function createStyleElement(style) {
|
||||||
for (let target of targetsList) {
|
for (let target of targetsList) {
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
container.appendChild(template.appliesToSeparator.cloneNode(true));
|
container.appendChild(template.appliesToSeparator.cloneNode(true));
|
||||||
}
|
}
|
||||||
if (++index == TARGET_LIMIT) {
|
if (++index == TARGET_LIMIT) {
|
||||||
container = appliesTo.appendChild(template.extraAppliesTo.cloneNode(true));
|
container = appliesTo.appendChild(template.extraAppliesTo.cloneNode(true));
|
||||||
}
|
}
|
||||||
const item = template.appliesToTarget.cloneNode(true);
|
const item = template.appliesToTarget.cloneNode(true);
|
||||||
item.textContent = target;
|
item.textContent = target;
|
||||||
container.appendChild(item);
|
container.appendChild(item);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const editLink = $('.style-edit-link', entry);
|
const editLink = $('.style-edit-link', entry);
|
||||||
editLink.href = editLink.getAttribute('href') + style.id;
|
editLink.href = editLink.getAttribute('href') + style.id;
|
||||||
editLink.onclick = EntryOnClick.edit;
|
editLink.onclick = EntryOnClick.edit;
|
||||||
|
|
||||||
$('.enable', entry).onclick = EntryOnClick.toggle;
|
$('.enable', entry).onclick = EntryOnClick.toggle;
|
||||||
|
@ -215,22 +215,21 @@ class EntryOnClick {
|
||||||
}
|
}
|
||||||
|
|
||||||
static update(event) {
|
static update(event) {
|
||||||
const element = getClickedStyleElement(event);
|
const updatedCode = getClickedStyleElement(event).updatedCode;
|
||||||
const updatedCode = element.updatedCode;
|
|
||||||
// update everything but name
|
// update everything but name
|
||||||
delete updatedCode.name;
|
saveStyle(Object.assign(updatedCode, {
|
||||||
updatedCode.id = element.styleId;
|
id: element.styleId,
|
||||||
updatedCode.reason = 'update';
|
name: null,
|
||||||
saveStyle(updatedCode)
|
reason: 'update',
|
||||||
.then(style => handleUpdate(style, {reason: 'update'}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
static delete(event) {
|
static delete(event) {
|
||||||
if (confirm(t('deleteStyleConfirm'))) {
|
if (confirm(t('deleteStyleConfirm'))) {
|
||||||
deleteStyle(getClickedStyleId(event))
|
deleteStyle(getClickedStyleId(event))
|
||||||
.then(handleDelete);
|
.then(handleDelete);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +241,7 @@ function handleUpdate(style, {reason} = {}) {
|
||||||
if (!oldElement) {
|
if (!oldElement) {
|
||||||
installed.appendChild(element);
|
installed.appendChild(element);
|
||||||
} else {
|
} else {
|
||||||
installed.replaceChild(element, oldElement);
|
installed.replaceChild(element, oldElement);
|
||||||
if (reason == 'update') {
|
if (reason == 'update') {
|
||||||
element.classList.add('update-done');
|
element.classList.add('update-done');
|
||||||
$('.update-note', element).innerHTML = t('updateCompleted');
|
$('.update-note', element).innerHTML = t('updateCompleted');
|
||||||
|
@ -270,10 +269,10 @@ function applyUpdateAll() {
|
||||||
|
|
||||||
[...document.querySelectorAll('.can-update .update')]
|
[...document.querySelectorAll('.can-update .update')]
|
||||||
.forEach(button => {
|
.forEach(button => {
|
||||||
// align to the bottom of the visible area if wasn't visible
|
// align to the bottom of the visible area if wasn't visible
|
||||||
button.scrollIntoView(false);
|
button.scrollIntoView(false);
|
||||||
button.click();
|
button.click();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -381,8 +380,8 @@ class Updater {
|
||||||
} else {
|
} else {
|
||||||
this.element.classList.add('no-update');
|
this.element.classList.add('no-update');
|
||||||
$('.update-note', this.element).innerHTML = message || t('updateCheckSucceededNoUpdate');
|
$('.update-note', this.element).innerHTML = message || t('updateCheckSucceededNoUpdate');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
download(url) {
|
download(url) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -489,7 +488,7 @@ function rememberScrollPosition() {
|
||||||
function $(selector, base = document) {
|
function $(selector, base = document) {
|
||||||
if (selector.startsWith('#') && /^#[^,\s]+$/.test(selector)) {
|
if (selector.startsWith('#') && /^#[^,\s]+$/.test(selector)) {
|
||||||
return document.getElementById(selector.slice(1));
|
return document.getElementById(selector.slice(1));
|
||||||
} else {
|
} else {
|
||||||
return base.querySelector(selector);
|
return base.querySelector(selector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
storage.js
16
storage.js
|
@ -250,7 +250,7 @@ function cleanupCachedFilters({force = false} = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function saveStyle(style, {notify = true} = {}) {
|
function saveStyle(style) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
getDatabase(db => {
|
getDatabase(db => {
|
||||||
const tx = db.transaction(['styles'], 'readwrite');
|
const tx = db.transaction(['styles'], 'readwrite');
|
||||||
|
@ -258,8 +258,13 @@ function saveStyle(style, {notify = true} = {}) {
|
||||||
|
|
||||||
const id = style.id !== undefined && style.id !== null ? Number(style.id) : null;
|
const id = style.id !== undefined && style.id !== null ? Number(style.id) : null;
|
||||||
const reason = style.reason;
|
const reason = style.reason;
|
||||||
|
const notify = style.notify !== false;
|
||||||
delete style.method;
|
delete style.method;
|
||||||
delete style.reason;
|
delete style.reason;
|
||||||
|
delete style.notify;
|
||||||
|
if (!style.name) {
|
||||||
|
delete style.name;
|
||||||
|
}
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
|
@ -279,6 +284,9 @@ function saveStyle(style, {notify = true} = {}) {
|
||||||
style, codeIsUpdated, reason,
|
style, codeIsUpdated, reason,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (typeof handleUpdate != 'undefined') {
|
||||||
|
handleUpdate(style, {reason});
|
||||||
|
}
|
||||||
resolve(style);
|
resolve(style);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -303,6 +311,9 @@ function saveStyle(style, {notify = true} = {}) {
|
||||||
if (notify) {
|
if (notify) {
|
||||||
notifyAllTabs({method: 'styleAdded', style, reason});
|
notifyAllTabs({method: 'styleAdded', style, reason});
|
||||||
}
|
}
|
||||||
|
if (typeof handleUpdate != 'undefined') {
|
||||||
|
handleUpdate(style, {reason});
|
||||||
|
}
|
||||||
resolve(style);
|
resolve(style);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -337,6 +348,9 @@ function deleteStyle(id, {notify = true} = {}) {
|
||||||
if (notify) {
|
if (notify) {
|
||||||
notifyAllTabs({method: 'styleDeleted', id});
|
notifyAllTabs({method: 'styleDeleted', id});
|
||||||
}
|
}
|
||||||
|
if (typeof handleDelete != 'undefined') {
|
||||||
|
handleDelete(id);
|
||||||
|
}
|
||||||
resolve(id);
|
resolve(id);
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user