回答

0

这是可能的解决方案,不是最好的,但总比没有好。

它监视URL的文本剪贴板,并且如果粘贴的URL与当前选项卡中的URL相同 - 我们可以认为它是从多功能框复制的。

background.js

// create element for pasting 
const textEl = document.createElement('textarea'); 
document.body.appendChild(textEl); 

var prevPasted = ''; 
setInterval(function() { 
    // paste text from clipboard to focused textarea 
    textEl.focus(); 
    textEl.value = ''; 
    document.execCommand('paste'); 
    const pastedText = textEl.value; 

    // simple cache check 
    if (pastedText !== prevPasted) { 
     prevPasted = pastedText; 

     if (pastedText.match(/https?:/)) { // you can improve you URL scheme 

      // get the current tab 
      chrome.tabs.query({active: true, currentWindow: true}, function (tabs) { 
       var tab = tabs[0]; 

       // check if current tab has the same URL 
       if (tab.url === pastedText) { 
        console.log('Omnibox URL:', pastedText); 
       } 
      }); 
     } 
    } 
}, 500); 

不要忘了添加权限clipboardRead标签入清单。

相关问题