Add fnc to launch every site under a category

This commit is contained in:
Özenç Bilgili 2020-07-31 10:59:03 +03:00
parent 80f38fee0c
commit d6461c0473
2 changed files with 39 additions and 8 deletions

View File

@ -16,9 +16,11 @@ Based on [Cade Scroggins](https://github.com/cadejscroggins)'s [Tilde](https://g
Most of the features are carried over from the original source.
Few of the added features are:
- Added a "Quick Launch" functionality, which launches all the sites with `quickLaunch` property set to `true` upon entering `q!`.
- Color theme can now be inverted easily by either editing config or using `invert!` command.
- Added an option to show launch keys instead of icons again. Either edit config or type `keys!`.
- A launch category functionality, which launches every site in a category. Enter a category index number followed by `!`, i.e. `2!` would launch everything under the second category.
- A "Quick Launch" functionality, which launches every site with `quickLaunch` property set to `true` upon entering `q!`.
- An invertible color theme. Either edit config or use `invert!` command.
- Show image or SVG as bookmark icon
- An option to show launch keys instead of icons. Either edit config or type `keys!`.
## Usage

View File

@ -333,6 +333,7 @@ class Help {
this._handleKeydown = this._handleKeydown.bind(this);
this.toggle = this.toggle.bind(this);
this.launch = this.launch.bind(this);
this.launchCategory = this.launchCategory.bind(this);
this._inputEl = $.el('#search-input');
this._inputElVal = '';
this._suggester = options.suggester;
@ -358,11 +359,26 @@ class Help {
this.hide();
this.toggle(true);
$.bodyClassAdd('help');
for (let i = 0; i < CONFIG.commands.length; i++) {
if (CONFIG.commands[i].quickLaunch === true) {
window.open(CONFIG.commands[i].url);
}
}
CONFIG.commands.forEach(command => {
if(command.quickLaunch) window.open(command.url);
});
}
launchCategory(){
const categorySet = new Set();
CONFIG.commands.forEach(command => {
if(command.category) categorySet.add(command.category);
});
const targetCategoryIndex = $.el('#search-input').value.replace('!', '');
const targetCategory = Array.from(categorySet)[targetCategoryIndex - 1];
CONFIG.commands.forEach(command => {
if(targetCategory && command.category === targetCategory) window.open(command.url);
});
}
_buildAndAppendLists() {
@ -897,6 +913,7 @@ class Form {
this._suggester = options.suggester;
this._toggleHelp = options.toggleHelp;
this._quickLaunch = options.quickLaunch;
this._categoryLaunch = options.categoryLaunch;
this._clearPreview = this._clearPreview.bind(this);
this._handleInput = this._handleInput.bind(this);
this._handleKeydown = this._handleKeydown.bind(this);
@ -953,12 +970,21 @@ class Form {
this._inputEl.focus();
}
_isCategoryLaunch(num){
if(/^\d/.test(num[0]) && num[1] === '!'){
return true
} else {
return false;
}
}
_handleInput() {
const newQuery = this._inputEl.value;
const isHelp = newQuery === '?';
const isLaunch = newQuery === 'q!';
const isInvert = newQuery === 'invert!';
const isShowKeys = newQuery === 'keys!';
const isCategoryLaunch = this._isCategoryLaunch(newQuery);
const { isKey } = this._parseQuery(newQuery);
this._inputElVal = newQuery;
this._suggester.suggest(newQuery);
@ -968,9 +994,11 @@ class Form {
if (isLaunch) this._quickLaunch();
if (isInvert) this._invertConfig();
if (isShowKeys) this._showKeysConfig();
if (isCategoryLaunch) this._categoryLaunch();
if (this._instantRedirect && isKey) this._submitWithValue(newQuery);
}
_handleKeydown(e) {
if ($.isUp(e) || $.isDown(e) || $.isRemove(e)) return;
@ -1080,6 +1108,7 @@ const form = new Form({
suggester,
toggleHelp: help.toggle,
quickLaunch: help.launch,
categoryLaunch: help.launchCategory,
invertedColors: CONFIG.invertedColors,
showKeys: CONFIG.showKeys
});