@@ -3,6 +3,7 @@ import Browser from 'webextension-polyfill';
33import { getLogseqCopliotConfig } from '../../config' ;
44import { removeUrlHash } from '@/utils' ;
55import { setExtensionBadge } from './utils' ;
6+ import { debounce } from 'lodash' ;
67
78const logseqClient = new LogseqClient ( ) ;
89
@@ -31,8 +32,12 @@ const quickCapture = async (data: string) => {
3132 const activeTab = tab [ 0 ] ;
3233 const url = `logseq://x-callback-url/quickCapture?title=${
3334 activeTab . title
34- } &url=${ encodeURIComponent ( activeTab . url ! ) } &content=${ encodeURIComponent ( data ) } `;
35+ } &url=${ encodeURIComponent ( activeTab . url ! ) } &content=${ encodeURIComponent (
36+ data ,
37+ ) } `;
3538 Browser . tabs . update ( activeTab . id , { url : url } ) ;
39+
40+ debounceBadgeSearch ( activeTab . url , activeTab . id ) ;
3641} ;
3742
3843Browser . runtime . onInstalled . addListener ( ( ) => {
@@ -46,15 +51,15 @@ Browser.runtime.onInstalled.addListener(() => {
4651Browser . tabs . onActivated . addListener ( ( activeInfo ) => {
4752 const promise = new Promise ( async ( ) => {
4853 const tab = await Browser . tabs . get ( activeInfo . tabId ) ;
49- await badgeSearch ( tab . url , activeInfo . tabId ) ;
54+ await debounceBadgeSearch ( tab . url , activeInfo . tabId ) ;
5055 } ) ;
5156 promise . catch ( ( err ) => console . error ( err ) ) ;
5257} ) ;
5358
5459Browser . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
5560 if ( tab . active && changeInfo . status === 'complete' ) {
5661 const promise = new Promise ( async ( ) => {
57- await badgeSearch ( tab . url , tabId ) ;
62+ await debounceBadgeSearch ( tab . url , tabId ) ;
5863 } ) ;
5964 promise . catch ( ( err ) => console . error ( err ) ) ;
6065 }
@@ -68,6 +73,8 @@ const badgeSearch = async (url: string | undefined, tabId: number) => {
6873 await setExtensionBadge ( resultCount , tabId ) ;
6974} ;
7075
76+ const debounceBadgeSearch = debounce ( badgeSearch , 200 ) ;
77+
7178Browser . contextMenus . create ( {
7279 id : 'quick-capture' ,
7380 title : 'Quick Capture' ,
0 commit comments