多功能框 API |针对特定关键字打开特定窗口

发布于 2024-11-07 04:45:02 字数 1226 浏览 1 评论 0原文

我正在尝试创建一个多功能框快捷方式,因此当用户键入 cp command 或 cp command 2 时,它将打开窗口 1 或窗口 2,但它会打开两个窗口都位于“cp”或“cp {此处任何内容}”上。

我是否错过了 API 中的某些内容?

背景.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) {
      chrome.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>

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) {
      chrome.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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千纸鹤带着心事 2024-11-14 04:45:02

应该是这样的:

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});
          }

      });
});

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});
          }

      });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文