3

所以我正在尝试做一个扩展,如果你在地址栏中输入一个推特用户名并按回车,它会转到那个推特页面而不是去谷歌,但它甚至不会触发这个功能,不管我做什么在地址栏中输入。

显现

{
  "manifest_version": 2,

  "name": "Twitter link",
  "description": "Type in a username with @ preceding it to go to that twitter page, ex: @wol_lay would go to https://twitter.com/wol_lay",
  "version": "1.0",

  "permissions": [
    "webRequest",
    "webRequestBlocking",
    "*://*.google.com"
  ],
  "background": {"scripts": ["background.js"]}
}

我的代码

chrome.webRequest.onBeforeRequest.addListener(
  function(details)
  {
    console.log (details.url);
    if (details.url.charAt (0) == '@')
    {
      return {redirectUrl: "https://www.twitter.com/" + details.url.substring(1,details.url.length - 1)};
    }
  },

  {urls: ["<all_urls>"]},

  ["blocking"]
);
4

0 回答 0