From bd117b8fd73b78f9f95b3c029094803e21ca0f3a Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Thu, 17 Jan 2019 06:40:52 -0600 Subject: [PATCH] Build & save injection order values --- manage/manage-actions.js | 28 ++++++++++++++++------------ manage/manage-ui.js | 16 +++++++++++++++- manage/manage.css | 1 + 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/manage/manage-actions.js b/manage/manage-actions.js index cb58dfd8..84770583 100644 --- a/manage/manage-actions.js +++ b/manage/manage-actions.js @@ -54,7 +54,10 @@ function onRuntimeMessage(msg) { default: return; } - setTimeout(sorter.updateStripes, 0, {onlyWhenColumnsChanged: true}); + setTimeout(() => { + sorter.updateStripes({onlyWhenColumnsChanged: true}); + updateInjectionOrder(); + }, 0, ); } @@ -395,6 +398,7 @@ function handleDelete(id) { btnApply.dataset.value = Number(btnApply.dataset.value) - 1; } showFiltersStats(); + updateInjectionOrder(); } } @@ -487,17 +491,17 @@ function removeSelection() { } function updateInjectionOrder() { - const entries = [...installed.children]; - entries.shift(); // remove header - // console.log(entries[1].styleMeta.id, entries[1].styleMeta.injectionOrder) - - entries.forEach((entry, index) => { - entry.styleMeta.injectionOrder = index + 1; - $('.entry-id', entry).textContent = index + 1; - }); - sorter.update(); - - // TODO: Update database + if (installed.dataset.sort === 'order') { + const entries = [...installed.children]; + entries.shift(); // remove header + entries.forEach((entry, index) => { + entry.styleMeta.injectionOrder = index + 1; + $('.entry-id', entry).textContent = index + 1; + UI.injectionXref[entry.styleMeta.id] = index + 1; + }); + sorter.update(); + // TODO: Update database + } } function lazyLoad() { diff --git a/manage/manage-ui.js b/manage/manage-ui.js index 3c4b9c50..02464654 100644 --- a/manage/manage-ui.js +++ b/manage/manage-ui.js @@ -17,6 +17,8 @@ const UI = { faviconsGray: prefs.get('manage.newUI.faviconsGray'), targets: prefs.get('manage.newUI.targets'), + injectionXref: {}, + labels: { 'usercss': { is: ({style}) => typeof style.usercssData !== 'undefined', @@ -44,6 +46,18 @@ const UI = { showStyles: (styles = [], matchUrlIds) => { UI.addHeaderLabels(); + + // map injection order of styles + if (styles && styles.length && !styles.every(s => s.injectionOrder)) { + UI.injectionXref = styles + .sort((a, b) => ((a.injectionOrder || a.id) - (b.injectionOrder || b.id))) + .map((s, index) => (s.injectionOrder = index + 1)) + .reduce((acc, s) => { + acc[s.id] = s.injectionOrder; + return acc; + }, {}); + } + const sorted = sorter.sort({ styles: styles.map(style => ({ style, @@ -138,7 +152,7 @@ const UI = { (style.updateUrl ? ' updatable' : '') + (style.usercssData ? ' usercss' : ''); - $('.entry-id', entry).textContent = style.injectionOrder || style.id; + $('.entry-id', entry).textContent = style.injectionOrder || UI.injectionXref[style.id]; let el = $('.entry-homepage', entry); el.classList.toggle('invisible', !style.url); el.href = style.url || ''; diff --git a/manage/manage.css b/manage/manage.css index 74abb7a7..f3520470 100644 --- a/manage/manage.css +++ b/manage/manage.css @@ -120,6 +120,7 @@ a:hover { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } } +.entry-header a:hover .svg-icon, .entry a:hover .svg-icon, .svg-icon:hover { fill: var(--entry-icon-hover-color);