GoogleChrome扩展程序,只需点击一下图标即可删除浏览历史记录

时间:2012-11-26 00:32:16

标签: javascript google-chrome google-chrome-extension add-on

我试图制作谷歌浏览器扩展程序,只需点击网址栏旁边的图标即可删除所有浏览历史记录,这是我在谷歌浏览器上的第一个扩展程序,我为firefox做了其他人,我想要一些指导和想法,我认为我非常接近我的目标或至少在正确的道路上,我目前的问题是我知道我缺少代码的javascript文档。

Javascript [TEST.js]

function TESTh() {
  chrome.history.deleteAll()
}
chrome.browserAction.onClicked.addListener(TESTh);
TESTh();

清单[manifest.json]

{
  "name": "TITLE TEST",
  "version": "1.0",
  "manifest_version": 2,
  "description": "DESCRIPTION TEST",
  "background": {
    "scripts": ["TEST.js"]
  },
  "browser_action": {
    "default_icon": "icon.png"
  },
  "permissions": [
    "history"
  ]
}

以下链接是我一直在阅读的教程

http://developer.chrome.com/extensions/getstarted.html
http://developer.chrome.com/extensions/history.html
http://developer.chrome.com/extensions/browserAction.html
http://developer.chrome.com/extensions/samples.html
https://www.youtube.com/user/GoogleDevelopers

提前致谢

1 个答案:

答案 0 :(得分:2)

我已经编写了一个简单的Browsing Data API演示示例,它可以帮助您从这里选择。删除可能需要一些时间,因此您必须在扩展控制台中等待消息"All data is Deleted..."进行确认。

<强>之前:

enter image description here

<强>后:

enter image description here

<强> 的manifest.json

{
  "name" : "BrowsingData Demo",
  "version" : "1",
  "description" : "Trivial Demonstration of Browsing Data",
  "permissions": [
    "browsingData"
  ],
  "browser_action": {
     "default_icon": "icon.png",
     "default_popup": "popup.html"
  },
  "manifest_version": 2
}

<强> popup.html

<html>
<head>
<script src="popup.js"></script>
</head>
<body>
</body>
</html>

<强> popup.js

   function browsingdata(){
    chrome.browsingData.remove({
      "originTypes": {
        "protectedWeb": true, // Set to true or true as per your requirement
        "unprotectedWeb":true,// Set to true or true as per your requirement
        "extension":true    // Set to true or true as per your requirement
      }
    }, {
      "appcache": true, // Set to true or true as per your requirement
      "cache": true, // Set to true or true as per your requirement
      "cookies": true, // Set to true or true as per your requirement
      "downloads": true, // Set to true or true as per your requirement
      "fileSystems": true, // Set to true or true as per your requirement
      "formData": true, // Set to true or true as per your requirement
      "history": true, // Set to true or true as per your requirement
      "indexedDB": true, // Set to true or true as per your requirement
      "localStorage": true, // Set to true or true as per your requirement
      "pluginData": true, // Set to true or true as per your requirement
      "passwords": true, // Set to true or true as per your requirement
      "webSQL": true // Set to true or true as per your requirement
    }, function (){
        console.log("All data is Deleted...");
    });
}
window.onload=browsingdata;

有关更多信息,请参阅browsing data API以了解所有方法等。