开发者

Omnibox API | Open specific window on specific keyword

开发者 https://www.devze.com 2023-03-06 05:56 出处:网络
I\'m trying to create an omnibox shortcut, so when a user types cp command or cp command 2 it will open either window 1, or window 2, but instead it opens both windows on \"cp\" or \"cp {anything here

I'm trying to create an omnibox shortcut, so when a user types cp command or cp command 2 it will open either window 1, or window 2, but instead it opens both windows on "cp" or "cp {anything here}".

Have I missed something from the API?

background.html

<script>
chrome.omnibox.onInputChanged.addListener(
  function sharePage(tweet, suggest) {
    suggest([
      {content: "tweet", description: "Share on Twitter"}
    ]);
  });
//
chrome.omnibox.onInputEntered.addListener(
  function sharePage(tweet) {
      chrome.tabs.getSelected(null, function (tab) {
      var url = "https://twitter.com/home?status=Check%20out%20" + encodeURIComponent(tab.url) + "%20via @Chromeplete"
    chrome.tabs.create ({"url": url});
  });
 });
</script>
<script>
chrome.omnibox.onInputChanged.addListener(
  function sharePage(post, suggest) {
    suggest([
      {content: "post", description: "Share on Facebook"}
    ]);
  });
//
chrome.omnibox.onInputEntered.addListener(
  function sharePage(post) {
      ch开发者_开发问答rome.tabs.getSelected(null, function (tab) {
      var url = "https://www.facebook.com/sharer.php?u" + encodeURIComponent(tab.url) + "&appid=127651283979691"
    chrome.tabs.create ({"url": url});
  });
 });
</script>


Should be something like this:

chrome.omnibox.onInputChanged.addListener(function(text, suggest) {
    suggest([
      {content: "tweet", description: "Share on Twitter"},
      {content: "post", description: "Share on Facebook"}
    ]);
});
//
chrome.omnibox.onInputEntered.addListener(function(text) {
      chrome.tabs.getSelected(null, function (tab) {
          if(text == "tweet") {
              var url = "https://twitter.com/home?status=Check%20out%20" + encodeURIComponent(tab.url) + "%20via @Chromeplete";
              chrome.tabs.create ({"url": url});
          } else if(text == "post") {
              var url = "https://www.facebook.com/sharer.php?u" + encodeURIComponent(tab.url) + "&appid=127651283979691";
              chrome.tabs.create ({"url": url});
          }

      });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消