Skip to content

Commit

Permalink
feat: add element selector button
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 committed Oct 6, 2022
1 parent 1a13ce4 commit 9f60bb2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/components/newtab/app/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
</a>
</router-link>
</div>
<hr class="w-8/12 my-4" />
<button
v-tooltip:right.group="$t('home.elementSelector.name')"
class="focus:ring-0"
@click="injectElementSelector"
>
<v-remixicon name="riFocus3Line" />
</button>
<div class="flex-grow"></div>
<ui-popover
v-if="userStore.user"
Expand Down Expand Up @@ -108,16 +116,19 @@
import { ref, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { useToast } from 'vue-toastification';
import browser from 'webextension-polyfill';
import { useUserStore } from '@/stores/user';
import { useWorkflowStore } from '@/stores/workflow';
import { useShortcut, getShortcut } from '@/composable/shortcut';
import { useGroupTooltip } from '@/composable/groupTooltip';
import { communities } from '@/utils/shared';
import { initElementSelector } from '@/newtab/utils/elementSelector';
useGroupTooltip();
const { t } = useI18n();
const toast = useToast();
const router = useRouter();
const userStore = useUserStore();
const workflowStore = useWorkflowStore();
Expand Down Expand Up @@ -189,6 +200,19 @@ function hoverHandler({ target }) {
showHoverIndicator.value = true;
hoverIndicator.value.style.transform = `translate(-50%, ${target.offsetTop}px)`;
}
async function injectElementSelector() {
try {
const [tab] = await browser.tabs.query({ active: true, url: '*://*/*' });
if (!tab) {
toast.error(t('home.elementSelector.noAccess'));
return;
}
await initElementSelector(tab);
} catch (error) {
console.error(error);
}
}
</script>
<style scoped>
.tab.is-active:after {
Expand Down
2 changes: 1 addition & 1 deletion src/newtab/utils/elementSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function makeDashboardFocus() {
});
}

async function initElementSelector(tab = null) {
export async function initElementSelector(tab = null) {
let activeTab = tab;

if (!tab) {
Expand Down

0 comments on commit 9f60bb2

Please sign in to comment.