diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 8e5600f6..09d94e64 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -425,6 +425,10 @@ "message": "More Options", "description": "Subheading for options section on manage page." }, + "popupManageTooltip": { + "message": "Shift-click or right-click opens manager with styles applicable for current site", + "description": "Tooltip for the 'Manage' button in the popup." + }, "popupStylesFirst": { "message": "Styles before commands", "description": "Label for the checkbox controlling section order in the popup." @@ -457,6 +461,10 @@ "message": "Search contents", "description": "Label for the search filter textbox on the Manage styles page" }, + "searchStylesTooltip": { + "message": "To show styles for a URL, prefix it with 'url:'\nFor example, url:https://github.com/openstyles/stylus", + "description": "Label for the search filter textbox on the Manage styles page" + }, "sectionAdd": { "message": "Add another section", "description": "Label for the button to add a section" diff --git a/manage.html b/manage.html index f28bb414..bd6f73d8 100644 --- a/manage.html +++ b/manage.html @@ -164,6 +164,7 @@ diff --git a/manage/filters.js b/manage/filters.js index 9ef5de75..8d96b601 100644 --- a/manage/filters.js +++ b/manage/filters.js @@ -8,6 +8,11 @@ const filtersSelector = { numTotal: 0, }; +const urlFilterParam = new URLSearchParams(location.search).get('url'); +if (location.search) { + history.replaceState(0, document.title, location.origin + location.pathname); +} + HTMLSelectElement.prototype.adjustWidth = function () { const parent = this.parentNode; const singleSelect = this.cloneNode(false); @@ -22,6 +27,9 @@ HTMLSelectElement.prototype.adjustWidth = function () { onDOMready().then(onBackgroundReady).then(() => { $('#search').oninput = searchStyles; + if (urlFilterParam) { + $('#search').value = 'url:' + urlFilterParam; + } $$('select[id$=".invert"]').forEach(el => { const slave = $('#' + el.id.replace('.invert', '')); @@ -306,7 +314,10 @@ function showFiltersStats({immediately} = {}) { function searchStyles({immediately, container}) { const searchElement = $('#search'); - const query = searchElement.value.toLocaleLowerCase(); + const urlMode = /^\s*url:/i.test(searchElement.value); + const query = urlMode + ? searchElement.value.replace(/^\s*url:/i, '').trim() + : searchElement.value.toLocaleLowerCase(); const queryPrev = searchElement.lastValue || ''; if (query === queryPrev && !immediately && !container) { return; @@ -317,15 +328,18 @@ function searchStyles({immediately, container}) { } searchElement.lastValue = query; - const searchInVisible = queryPrev && query.includes(queryPrev); + const searchInVisible = !urlMode && queryPrev && query.includes(queryPrev); const entries = container && container.children || container || (searchInVisible ? $$('.entry:not(.hidden)') : installed.children); + const siteStyleIds = urlMode && + new Set(BG.filterStyles({matchUrl: query}).map(style => style.id)); let needsRefilter = false; for (const entry of entries) { let isMatching = !query; if (!isMatching) { - const style = BG.cachedStyles.byId.get(entry.styleId) || {}; - isMatching = Boolean(style && ( + const style = urlMode ? siteStyleIds.has(entry.styleId) : + BG.cachedStyles.byId.get(entry.styleId) || {}; + isMatching = urlMode ? style : Boolean(style && ( isMatchingText(style.name) || style.url && isMatchingText(style.url) || isMatchingStyle(style))); diff --git a/popup.html b/popup.html index 8fae9043..b4945dfc 100644 --- a/popup.html +++ b/popup.html @@ -99,7 +99,7 @@