Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 删除历史chrome扩展_Javascript_Json_Google Chrome_Google Chrome Extension_Popup - Fatal编程技术网

Javascript 删除历史chrome扩展

Javascript 删除历史chrome扩展,javascript,json,google-chrome,google-chrome-extension,popup,Javascript,Json,Google Chrome,Google Chrome Extension,Popup,我正在尝试创建一个简单的Chrome扩展,删除选定的浏览历史属性。我已经学习了一些教程,并且考虑到我对JS、JSON和HTML都是新手,所以我尽量使编程尽可能简单。此外,由于我找不到任何地方来编译我的代码,所以很难指出我的错误。有谁能看一下我的代码,告诉我出了什么问题吗?我只是想学习,所以我想要的是一个解释以及位。然而,任何事情都有帮助。以下是我的弹出窗口和清单: manifest.json: { "name": "1-Click Clear", "description": "1 click

我正在尝试创建一个简单的Chrome扩展,删除选定的浏览历史属性。我已经学习了一些教程,并且考虑到我对JS、JSON和HTML都是新手,所以我尽量使编程尽可能简单。此外,由于我找不到任何地方来编译我的代码,所以很难指出我的错误。有谁能看一下我的代码,告诉我出了什么问题吗?我只是想学习,所以我想要的是一个解释以及位。然而,任何事情都有帮助。以下是我的弹出窗口和清单:

manifest.json:

{

"name": "1-Click Clear",
"description": "1 click and your Chrome history is cleared!",
"version": "1.0",

"manifest_version": 2,

"browser_action":{
"default_icon": "icon.png",
"default_popup": "popup.html"
},

"permissions":[
    "history",
    "topSites",
    "browsingData"
]



}
popup.html:

<!DOCTYPE html>
<html>
<body>

<form>
  <input type="checkbox" name="history" value="male"> Delete History<br>
  <input type="checkbox" name="cookies" value="female"> Delete Cookies<br>
  <input type="checkbox" name="cache" value="other"> Delete Cache <br>  
  <input type="checkbox" name="passwords" value="female"> Delete Passwords <br>
</form> 
<br>

<button type = "submit" id = "all"> <b>Clear All Above</b></button>
 <button type = "submit" id = "chosen"> <b>Clear Chosen</b></button>



</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="popup.js"></script>
<form>
  <input type="checkbox" name="history" value="male"> Delete History<br>
  <input type="checkbox" name="cookies" value="female"> Delete Cookies<br>
  <input type="checkbox" name="cache" value="other"> Delete Cache <br>  
  <input type="checkbox" name="passwords" value="female"> Delete Passwords <br>
</form> 
<br>

<button type = "submit" id = "all"> <b>Clear All Above</b></button>
 <button type = "submit" id = "chosen"> <b>Clear Chosen</b></button>



</body>
</html>
已编辑的popup.js:

var callback = function(){};
var millisecondsPerMonth = 1000 * 60 * 60 * 24 * 7 * 4;

var oneMonthAgo = (new Date()).getTime() - millisecondsPerMonth;

function clear()
{
    if(document.getElementsByName("history").checked)
    {
    chrome.browsingData.removeHistory({"since": oneMonthAgo}, callback);
    }
    if(document.getElementsByName("cookies").checked)
    {
         chrome.browsingData.removeCookies({"since": oneMonthAgo}, callback);
    }
    if(document.getElementsByName("cache").checked)
    {
        chrome.browsingData.removeCache({"since": oneMonthAgo}, callback);
    }
    if(document.getElementsByName("passwords").checked)
    {
        chrome.browsingData.removePasswords({"since": oneMonthAgo}, callback);
    }
}

function clearAll()
{
    chrome.browsingData.removeHistory({"since": oneMonthAgo}, callback);
chrome.browsingData.removeCookies({"since": oneMonthAgo}, callback);
    chrome.browsingData.removeCache({"since": oneMonthAgo}, callback);
chrome.browsingData.removePasswords({"since": oneMonthAgo}, callback);
}


var doc = document.getElementById('chosen');
if(doc)
{
    doc.addEventListener('click',clear);
}
var doc = document.getElementById('all');
if(doc)
{
    doc.addEventListener('click',clearAll);
}
已编辑的popup.html:

<!DOCTYPE html>
<html>
<body>

<form>
  <input type="checkbox" name="history" value="male"> Delete History<br>
  <input type="checkbox" name="cookies" value="female"> Delete Cookies<br>
  <input type="checkbox" name="cache" value="other"> Delete Cache <br>  
  <input type="checkbox" name="passwords" value="female"> Delete Passwords <br>
</form> 
<br>

<button type = "submit" id = "all"> <b>Clear All Above</b></button>
 <button type = "submit" id = "chosen"> <b>Clear Chosen</b></button>



</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="popup.js"></script>
<form>
  <input type="checkbox" name="history" value="male"> Delete History<br>
  <input type="checkbox" name="cookies" value="female"> Delete Cookies<br>
  <input type="checkbox" name="cache" value="other"> Delete Cache <br>  
  <input type="checkbox" name="passwords" value="female"> Delete Passwords <br>
</form> 
<br>

<button type = "submit" id = "all"> <b>Clear All Above</b></button>
 <button type = "submit" id = "chosen"> <b>Clear Chosen</b></button>



</body>
</html>

删除历史记录
删除Cookies
删除缓存
删除密码

清除以上所有内容 精选
你不必编译任何东西,但你应该在popup.html中包含你的Javascript代码,也就是说,
请回答以下问题:寻求调试帮助的问题(“此代码为什么不工作?”)必须包括:►想要的行为,►特定的问题或错误,以及►在问题本身中复制它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:“如何创建”,以及。错误的对象文字语法,请使用文档中所示的大括号:
{“自”:oneMonthAgo}
{since:oneMonthAgo}
(可以省略键名的引号)。要查看错误,请右键单击弹出窗口并选择“检查”,这将打开devtools,然后查看控制台。@IvánNokonoko好的,我在中添加了这个,谢谢@wOxxOm好的,非常感谢我修复了语法,并使用控制台调试了一些下一个bug。但是,现在它没有显示任何错误,但是扩展没有执行任何操作。它不会删除任何内容。我将重新发布更改后的代码,供任何人查看,提前谢谢。