code cosmetics: entry id prefix => named constant
This commit is contained in:
parent
65d625fddf
commit
1aa5c11b10
15
manage.js
15
manage.js
|
@ -7,6 +7,9 @@ const filtersSelector = {
|
||||||
unhide: '',
|
unhide: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ENTRY_ID_PREFIX_RAW = 'style-';
|
||||||
|
const ENTRY_ID_PREFIX = '#' + ENTRY_ID_PREFIX_RAW;
|
||||||
|
|
||||||
const newUI = {
|
const newUI = {
|
||||||
enabled: prefs.get('manage.newUI'),
|
enabled: prefs.get('manage.newUI'),
|
||||||
favicons: prefs.get('manage.newUI.favicons'),
|
favicons: prefs.get('manage.newUI.favicons'),
|
||||||
|
@ -140,7 +143,7 @@ function showStyles(styles = []) {
|
||||||
if (newUI.enabled && newUI.favicons) {
|
if (newUI.enabled && newUI.favicons) {
|
||||||
debounce(handleEvent.loadFavicons, 16);
|
debounce(handleEvent.loadFavicons, 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -175,7 +178,7 @@ function createStyleElement({style, name}) {
|
||||||
parts.homepage.href = parts.homepage.title = style.url || '';
|
parts.homepage.href = parts.homepage.title = style.url || '';
|
||||||
|
|
||||||
const entry = parts.entry.cloneNode(true);
|
const entry = parts.entry.cloneNode(true);
|
||||||
entry.id = 'style-' + style.id;
|
entry.id = ENTRY_ID_PREFIX_RAW + style.id;
|
||||||
entry.styleId = style.id;
|
entry.styleId = style.id;
|
||||||
entry.styleNameLowerCase = name || style.name.toLocaleLowerCase();
|
entry.styleNameLowerCase = name || style.name.toLocaleLowerCase();
|
||||||
entry.styleMeta = getStyleWithNoCode(style);
|
entry.styleMeta = getStyleWithNoCode(style);
|
||||||
|
@ -400,7 +403,7 @@ Object.assign(handleEvent, {
|
||||||
|
|
||||||
function handleUpdate(style, {reason, method} = {}) {
|
function handleUpdate(style, {reason, method} = {}) {
|
||||||
let entry;
|
let entry;
|
||||||
let oldEntry = $('#style-' + style.id);
|
let oldEntry = $(ENTRY_ID_PREFIX + style.id);
|
||||||
if (oldEntry && method == 'styleUpdated') {
|
if (oldEntry && method == 'styleUpdated') {
|
||||||
handleToggledOrCodeOnly();
|
handleToggledOrCodeOnly();
|
||||||
}
|
}
|
||||||
|
@ -449,7 +452,7 @@ function handleUpdate(style, {reason, method} = {}) {
|
||||||
|
|
||||||
|
|
||||||
function handleDelete(id) {
|
function handleDelete(id) {
|
||||||
const node = $('#style-' + id);
|
const node = $(ENTRY_ID_PREFIX + id);
|
||||||
if (node) {
|
if (node) {
|
||||||
node.remove();
|
node.remove();
|
||||||
if (node.matches('.can-update')) {
|
if (node.matches('.can-update')) {
|
||||||
|
@ -519,7 +522,7 @@ function switchUI({styleOnly} = {}) {
|
||||||
if (missingFavicons) {
|
if (missingFavicons) {
|
||||||
getStylesSafe().then(styles => {
|
getStylesSafe().then(styles => {
|
||||||
for (const style of styles) {
|
for (const style of styles) {
|
||||||
const entry = $('#style-' + style.id);
|
const entry = $(ENTRY_ID_PREFIX + style.id);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
createStyleTargetsElement({entry, style, postponeFavicons: true});
|
createStyleTargetsElement({entry, style, postponeFavicons: true});
|
||||||
}
|
}
|
||||||
|
@ -621,7 +624,7 @@ function checkUpdate(entry, {single = true} = {}) {
|
||||||
|
|
||||||
|
|
||||||
function reportUpdateState(state, style, details) {
|
function reportUpdateState(state, style, details) {
|
||||||
const entry = $('#style-' + style.id);
|
const entry = $(ENTRY_ID_PREFIX + style.id);
|
||||||
entry.classList.remove('checking-update');
|
entry.classList.remove('checking-update');
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case BG.updater.UPDATED:
|
case BG.updater.UPDATED:
|
||||||
|
|
15
popup.js
15
popup.js
|
@ -5,6 +5,9 @@ let installed;
|
||||||
let tabURL;
|
let tabURL;
|
||||||
const handleEvent = {};
|
const handleEvent = {};
|
||||||
|
|
||||||
|
const ENTRY_ID_PREFIX_RAW = 'style-';
|
||||||
|
const ENTRY_ID_PREFIX = '#' + ENTRY_ID_PREFIX_RAW;
|
||||||
|
|
||||||
getActiveTabRealURL().then(url => {
|
getActiveTabRealURL().then(url => {
|
||||||
tabURL = URLS.supported.test(url) ? url : '';
|
tabURL = URLS.supported.test(url) ? url : '';
|
||||||
Promise.all([
|
Promise.all([
|
||||||
|
@ -215,7 +218,7 @@ function createStyleElement({
|
||||||
const entry = template.style.cloneNode(true);
|
const entry = template.style.cloneNode(true);
|
||||||
entry.setAttribute('style-id', style.id);
|
entry.setAttribute('style-id', style.id);
|
||||||
Object.assign(entry, {
|
Object.assign(entry, {
|
||||||
id: 'style-' + style.id,
|
id: ENTRY_ID_PREFIX_RAW + style.id,
|
||||||
styleId: style.id,
|
styleId: style.id,
|
||||||
className: entry.className + ' ' + (style.enabled ? 'enabled' : 'disabled'),
|
className: entry.className + ' ' + (style.enabled ? 'enabled' : 'disabled'),
|
||||||
onmousedown: handleEvent.maybeEdit,
|
onmousedown: handleEvent.maybeEdit,
|
||||||
|
@ -223,7 +226,7 @@ function createStyleElement({
|
||||||
|
|
||||||
const checkbox = $('.checker', entry);
|
const checkbox = $('.checker', entry);
|
||||||
Object.assign(checkbox, {
|
Object.assign(checkbox, {
|
||||||
id: 'style-' + style.id,
|
id: ENTRY_ID_PREFIX_RAW + style.id,
|
||||||
checked: style.enabled,
|
checked: style.enabled,
|
||||||
onclick: handleEvent.toggle,
|
onclick: handleEvent.toggle,
|
||||||
});
|
});
|
||||||
|
@ -236,7 +239,7 @@ function createStyleElement({
|
||||||
|
|
||||||
const styleName = $('.style-name', entry);
|
const styleName = $('.style-name', entry);
|
||||||
Object.assign(styleName, {
|
Object.assign(styleName, {
|
||||||
htmlFor: 'style-' + style.id,
|
htmlFor: ENTRY_ID_PREFIX_RAW + style.id,
|
||||||
onclick: handleEvent.name,
|
onclick: handleEvent.name,
|
||||||
});
|
});
|
||||||
styleName.checkbox = checkbox;
|
styleName.checkbox = checkbox;
|
||||||
|
@ -248,7 +251,7 @@ function createStyleElement({
|
||||||
|
|
||||||
invokeOrPostpone(!postponeDetect, detectSloppyRegexps, {entry, style});
|
invokeOrPostpone(!postponeDetect, detectSloppyRegexps, {entry, style});
|
||||||
|
|
||||||
const oldElement = $('#style-' + style.id);
|
const oldElement = $(ENTRY_ID_PREFIX + style.id);
|
||||||
if (oldElement) {
|
if (oldElement) {
|
||||||
oldElement.parentNode.replaceChild(entry, oldElement);
|
oldElement.parentNode.replaceChild(entry, oldElement);
|
||||||
} else {
|
} else {
|
||||||
|
@ -368,7 +371,7 @@ Object.assign(handleEvent, {
|
||||||
|
|
||||||
|
|
||||||
function handleUpdate(style) {
|
function handleUpdate(style) {
|
||||||
if ($('#style-' + style.id)) {
|
if ($(ENTRY_ID_PREFIX + style.id)) {
|
||||||
createStyleElement({style});
|
createStyleElement({style});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -381,7 +384,7 @@ function handleUpdate(style) {
|
||||||
|
|
||||||
|
|
||||||
function handleDelete(id) {
|
function handleDelete(id) {
|
||||||
$$('#style-' + id).forEach(el => el.remove());
|
$$(ENTRY_ID_PREFIX + id).forEach(el => el.remove());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user