From d6461c0473e014dfe88378867bd8731dd7498d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zen=C3=A7=20Bilgili?= Date: Fri, 31 Jul 2020 10:59:03 +0300 Subject: [PATCH] Add fnc to launch every site under a category --- README.md | 8 +++++--- js/script.js | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c4abf0d..88de902 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/js/script.js b/js/script.js index 2b289a0..e69ee9b 100644 --- a/js/script.js +++ b/js/script.js @@ -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 });