4

我正在尝试制作一个 google chrome 扩展程序,只需单击 url 栏旁边的图标即可删除所有浏览历史记录,这是我在 google chrome 上的第一个扩展程序,我已经为 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

提前致谢

4

1 回答 1

4

我写了一个浏览数据 API 的简单演示,它可以帮助你从这里挑选。删除可能需要一些时间,因此您必须等待"All data is Deleted..."分机控制台中的消息进行确认。

前:

在此处输入图像描述

后:

在此处输入图像描述

清单.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;

有关更多信息,请参阅浏览数据 API以了解所有方法等。

于 2012-11-26T02:06:25.843 回答