Guest User

Untitled

a guest
Oct 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. //create the menu itens
  2. chrome.contextMenus.create({
  3. "title": "Cache: Last Hour",
  4. "onclick": function () {
  5. clear("Cache", 1000 * 60 * 60)
  6. }
  7. });
  8. chrome.contextMenus.create({
  9. "title": "Cache: Last Day",
  10. "onclick": function () {
  11. clear("Cache", 1000 * 60 * 60 * 24)
  12. }
  13. });
  14. chrome.contextMenus.create({
  15. "title": "Cache: Last Week",
  16. "onclick": function () {
  17. clear("Cache", 1000 * 60 * 60 * 24 * 7)
  18. }
  19. });
  20. chrome.contextMenus.create({
  21. "title": "Cache: All Time",
  22. "onclick": function () {
  23. clear("Cache", 0)
  24. }
  25. });
  26.  
  27. chrome.contextMenus.create({
  28. "type": "separator"
  29. });
  30.  
  31. chrome.contextMenus.create({
  32. "title": "History: Last Hour",
  33. "onclick": function () {
  34. clear("History", 1000 * 60 * 60)
  35. }
  36. });
  37. chrome.contextMenus.create({
  38. "title": "History: Last Day",
  39. "onclick": function () {
  40. clear("History", 1000 * 60 * 60 * 24)
  41. }
  42. });
  43. chrome.contextMenus.create({
  44. "title": "History: Last Week",
  45. "onclick": function () {
  46. clear("History", 1000 * 60 * 60 * 24 * 7)
  47. }
  48. });
  49. chrome.contextMenus.create({
  50. "title": "History: All Time",
  51. "onclick": function () {
  52. clear("History", 0)
  53. }
  54. });
  55.  
  56. chrome.contextMenus.create({
  57. "type": "separator"
  58. });
  59.  
  60. chrome.contextMenus.create({
  61. "title": "Cookies: Last Hour",
  62. "onclick": function () {
  63. clear("Cookies", 1000 * 60 * 60)
  64. }
  65. });
  66. chrome.contextMenus.create({
  67. "title": "Cookies: Last Day",
  68. "onclick": function () {
  69. clear("Cookies", 1000 * 60 * 60 * 24)
  70. }
  71. });
  72. chrome.contextMenus.create({
  73. "title": "Cookies: Last Week",
  74. "onclick": function () {
  75. clear("Cookies", 1000 * 60 * 60 * 24 * 7)
  76. }
  77. });
  78. chrome.contextMenus.create({
  79. "title": "Cookies: All Time",
  80. "onclick": function () {
  81. clear("Cookies", 0)
  82. }
  83. });
  84.  
  85. //clear function
  86. function clear(what, time) { //function to clear the cache
  87. var date;
  88. if (time === 0) { //if time is 0 then is to clear all
  89. date = 0;
  90. } else { //else calculate since
  91. var date = (new Date()).getTime() - time;
  92. }
  93.  
  94. switch (what) { //
  95. case "Cache":
  96. chrome.browsingData.removeCache({
  97. "since": date
  98. });
  99. break;
  100. case "Cookies":
  101. chrome.browsingData.removeCookies({
  102. "since": date
  103. });
  104. break;
  105. case "History":
  106. chrome.browsingData.removeHistory({
  107. "since": date
  108. });
  109. break;
  110. }
  111. }
Add Comment
Please, Sign In to add comment