Javascript 指定URL而不是内容脚本的chrome.events

Javascript 指定URL而不是内容脚本的chrome.events,javascript,google-chrome,javascript-events,google-chrome-extension,Javascript,Google Chrome,Javascript Events,Google Chrome Extension,我正在尝试创建一个扩展,将WAMP文件夹中的php文件重新定向到本地主机url。据我所知,阅读chrome文档的最佳实践是使用chome事件和url过滤器,我现在使用的代码确实有效,但如果可能的话,我更喜欢使用更高效的方式,有人能建议如何使用吗 eventPage.js: var path = window.location.pathname.split( '/www' ); /*get current url and splits it*/ var newpath = "http://loc

我正在尝试创建一个扩展,将WAMP文件夹中的php文件重新定向到本地主机url。据我所知,阅读chrome文档的最佳实践是使用chome事件和url过滤器,我现在使用的代码确实有效,但如果可能的话,我更喜欢使用更高效的方式,有人能建议如何使用吗

eventPage.js:

var path = window.location.pathname.split( '/www' ); /*get current url and splits it*/ 
var newpath = "http://localhost" + path[1];  /*change the varaible to localhost url insted of file/// */
window.open(newpath,"_self"); /*open the new URL in the same tab*/
manifest.json:

{
  "manifest_version": 2,

  "name": "PHP localhost Redirect",
  "version": "1.0",
  "description": "Automatically Redirect a url to localhost if is a php file in the wamp www folder",
  "content_scripts": [
    {
      "matches": ["file:///C:/wamp/www/*.php"],
      "js": ["eventPage.js"]
    }
    ],

  "browser_action": {
    "default_icon": "icon19.png"
  },
  "permissions": ["tabs" , "file:///C:/wamp/www/*"]
}

更好的方法是在manifest.json中添加对特定url的权限,而不是允许所有url。您可以访问以获得更多了解。因此,在本例中,所有操作都将在特定的url上执行,如果该url在manifest.json中注册,请编辑您的问题。文本部分不可读,所以我不明白你在问什么。