URL-mode in manager's search and popup's manage button
* in manager use search query like url:https://github.com/openstyles/stylus * in popup shift-click or right-click on manager button opens it and applies the filter
This commit is contained in:
parent
6ce8ce0425
commit
fb7f7d5471
|
@ -425,6 +425,10 @@
|
||||||
"message": "More Options",
|
"message": "More Options",
|
||||||
"description": "Subheading for options section on manage page."
|
"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": {
|
"popupStylesFirst": {
|
||||||
"message": "Styles before commands",
|
"message": "Styles before commands",
|
||||||
"description": "Label for the checkbox controlling section order in the popup."
|
"description": "Label for the checkbox controlling section order in the popup."
|
||||||
|
@ -457,6 +461,10 @@
|
||||||
"message": "Search contents",
|
"message": "Search contents",
|
||||||
"description": "Label for the search filter textbox on the Manage styles page"
|
"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": {
|
"sectionAdd": {
|
||||||
"message": "Add another section",
|
"message": "Add another section",
|
||||||
"description": "Label for the button to add a section"
|
"description": "Label for the button to add a section"
|
||||||
|
|
|
@ -164,6 +164,7 @@
|
||||||
<span i18n-text="manageOnlyUpdates"></span>
|
<span i18n-text="manageOnlyUpdates"></span>
|
||||||
</label>
|
</label>
|
||||||
<input id="search" type="search" i18n-placeholder="searchStyles" spellcheck="false"
|
<input id="search" type="search" i18n-placeholder="searchStyles" spellcheck="false"
|
||||||
|
i18n-title="searchStylesTooltip"
|
||||||
data-filter=":not(.not-matching)"
|
data-filter=":not(.not-matching)"
|
||||||
data-filter-hide=".not-matching">
|
data-filter-hide=".not-matching">
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
|
@ -8,6 +8,11 @@ const filtersSelector = {
|
||||||
numTotal: 0,
|
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 () {
|
HTMLSelectElement.prototype.adjustWidth = function () {
|
||||||
const parent = this.parentNode;
|
const parent = this.parentNode;
|
||||||
const singleSelect = this.cloneNode(false);
|
const singleSelect = this.cloneNode(false);
|
||||||
|
@ -22,6 +27,9 @@ HTMLSelectElement.prototype.adjustWidth = function () {
|
||||||
|
|
||||||
onDOMready().then(onBackgroundReady).then(() => {
|
onDOMready().then(onBackgroundReady).then(() => {
|
||||||
$('#search').oninput = searchStyles;
|
$('#search').oninput = searchStyles;
|
||||||
|
if (urlFilterParam) {
|
||||||
|
$('#search').value = 'url:' + urlFilterParam;
|
||||||
|
}
|
||||||
|
|
||||||
$$('select[id$=".invert"]').forEach(el => {
|
$$('select[id$=".invert"]').forEach(el => {
|
||||||
const slave = $('#' + el.id.replace('.invert', ''));
|
const slave = $('#' + el.id.replace('.invert', ''));
|
||||||
|
@ -306,7 +314,10 @@ function showFiltersStats({immediately} = {}) {
|
||||||
|
|
||||||
function searchStyles({immediately, container}) {
|
function searchStyles({immediately, container}) {
|
||||||
const searchElement = $('#search');
|
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 || '';
|
const queryPrev = searchElement.lastValue || '';
|
||||||
if (query === queryPrev && !immediately && !container) {
|
if (query === queryPrev && !immediately && !container) {
|
||||||
return;
|
return;
|
||||||
|
@ -317,15 +328,18 @@ function searchStyles({immediately, container}) {
|
||||||
}
|
}
|
||||||
searchElement.lastValue = query;
|
searchElement.lastValue = query;
|
||||||
|
|
||||||
const searchInVisible = queryPrev && query.includes(queryPrev);
|
const searchInVisible = !urlMode && queryPrev && query.includes(queryPrev);
|
||||||
const entries = container && container.children || container ||
|
const entries = container && container.children || container ||
|
||||||
(searchInVisible ? $$('.entry:not(.hidden)') : installed.children);
|
(searchInVisible ? $$('.entry:not(.hidden)') : installed.children);
|
||||||
|
const siteStyleIds = urlMode &&
|
||||||
|
new Set(BG.filterStyles({matchUrl: query}).map(style => style.id));
|
||||||
let needsRefilter = false;
|
let needsRefilter = false;
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
let isMatching = !query;
|
let isMatching = !query;
|
||||||
if (!isMatching) {
|
if (!isMatching) {
|
||||||
const style = BG.cachedStyles.byId.get(entry.styleId) || {};
|
const style = urlMode ? siteStyleIds.has(entry.styleId) :
|
||||||
isMatching = Boolean(style && (
|
BG.cachedStyles.byId.get(entry.styleId) || {};
|
||||||
|
isMatching = urlMode ? style : Boolean(style && (
|
||||||
isMatchingText(style.name) ||
|
isMatchingText(style.name) ||
|
||||||
style.url && isMatchingText(style.url) ||
|
style.url && isMatchingText(style.url) ||
|
||||||
isMatchingStyle(style)));
|
isMatchingStyle(style)));
|
||||||
|
|
|
@ -99,7 +99,7 @@
|
||||||
<!-- Actions -->
|
<!-- Actions -->
|
||||||
<div id="popup-options">
|
<div id="popup-options">
|
||||||
<button id="popup-manage-button" i18n-text="openManage"
|
<button id="popup-manage-button" i18n-text="openManage"
|
||||||
data-href="manage.html" i18n-title="optionsOpenManager"></button>
|
data-href="manage.html" i18n-title="popupManageTooltip"></button>
|
||||||
<button id="popup-options-button" i18n-text="openOptionsPopup"></button>
|
<button id="popup-options-button" i18n-text="openOptionsPopup"></button>
|
||||||
<button id="popup-shortcuts-button" class="chromium-only"
|
<button id="popup-shortcuts-button" class="chromium-only"
|
||||||
i18n-text="shortcuts"
|
i18n-text="shortcuts"
|
||||||
|
|
|
@ -89,7 +89,11 @@ function initPopup(url) {
|
||||||
setupLivePrefs();
|
setupLivePrefs();
|
||||||
|
|
||||||
$('#find-styles-link').onclick = handleEvent.openURLandHide;
|
$('#find-styles-link').onclick = handleEvent.openURLandHide;
|
||||||
$('#popup-manage-button').onclick = handleEvent.openURLandHide;
|
Object.assign($('#popup-manage-button'), {
|
||||||
|
onclick: handleEvent.openManager,
|
||||||
|
onmouseup: handleEvent.openManager,
|
||||||
|
oncontextmenu: handleEvent.openManager,
|
||||||
|
});
|
||||||
|
|
||||||
$('#popup-options-button').onclick = () => {
|
$('#popup-options-button').onclick = () => {
|
||||||
chrome.runtime.openOptionsPage();
|
chrome.runtime.openOptionsPage();
|
||||||
|
@ -386,6 +390,16 @@ Object.assign(handleEvent, {
|
||||||
openURL({url: this.href || this.dataset.href})
|
openURL({url: this.href || this.dataset.href})
|
||||||
.then(window.close);
|
.then(window.close);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
openManager(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (!this.eventHandled) {
|
||||||
|
this.eventHandled = true;
|
||||||
|
this.dataset.href += event.shiftKey || event.button === 2 ?
|
||||||
|
'?url=' + encodeURIComponent(tabURL) : '';
|
||||||
|
handleEvent.openURLandHide.call(this, event);
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user