【问题标题】:GoogleChrome extension that deletes browsing history with one click from an icon谷歌浏览器扩展,一键删除浏览历史
【发布时间】:2012-11-13 11:25:19
【问题描述】:

我正在尝试制作一个 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

提前致谢

【问题讨论】:

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


    【解决方案1】:

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

    之前:

    之后:

    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 以了解所有方法等。

    【讨论】:

    • 谢谢@Sudarshan,这个例子确实给了我一些想法,太糟糕了我无法让它工作,我试图“逆向工程”原生谷歌浏览器选项来清除浏览数据[CTRL +SHIT+DEL 或 Menu/Tools/Clear browser data...] 我还没有读完,但我认为那里可能有一些有用的东西,我还发现了这个goo.gl/SXKpE 这是一个铬开发网站和我也从那里得到了一些想法,但我离解决这个问题还很远:(
    • @Minnen:我已经用工作版本编辑了我的答案,它只会从你的浏览器中删除所有东西(在必要时将标志设置为 false)
    • 谢谢! @Sudarshan,老实说,我没有正确阅读您在answer 中提供的链接,我的过失,您的第一个示例毕竟确实有效,并且该链接包含我需要的所有信息,谢谢!我希望我能给你加分:(,无论如何我会在扩展上添加你的信息作为开发者(如果你同意的话),我会去制作选项面板,这样用户就可以选择他们想要删除的数据.
    猜你喜欢
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-17
    • 2014-07-24
    相关资源
    最近更新 更多