chrome清除緩存插件

1. 簡(jiǎn)介

可以清除全部緩存數(shù)據(jù)。

2. 插件代碼

2.1 代碼結(jié)構(gòu)

Paste_Image.png

2.2 manifest.json

{
  "name": "Chrome緩存清理插件",
  "description": "Chrome緩存清理插件",
  "version": "2.0",
  "permissions": ["*://*/*", "tabs", "activeTab", "browsingData"],
  "background": {
    "scripts": ["background.js", "jquery.js"],
    "persistent": false
  },
  "browser_action": {
    "default_title": "Chrome緩存清理插件",
    "default_popup": "popup.html"
  },
  "manifest_version": 2
}

2.3 popup.html

<html>
    <head>
        <script src="jquery.js"></script>
        <script src="popup.js"></script>
    </head>
    <body style="width: 100px">
        <div style="margin-bottom:15px">
            <span>清除chrome緩存工具</span>
        </div>
         <div>
            <button id="clearCache">清除緩存</button>
        </div>
    </body>
</html>

2.4 popup.js

$(function() {
    $('#clearCache').click(function() {
        var port = chrome.extension.connect({
            name: 'Clear Cache'
        });
        port.postMessage('clearCache');
        port.onMessage.addListener(function(msg) {
            if(msg === 'ok') {
                alert("done");
            } else {
                alert("Something bad happened.");
            }
        });
    });
});

2.5 background.js

chrome.extension.onConnect.addListener(function(port) {
    port.onMessage.addListener(function(msg) {
            if(msg === 'clearCache') {
            clearCache();
            port.postMessage('ok');
        } else {
          // do nothing
        }
    });
});

/**
 * 清除緩存
 */
function clearCache() {
    chrome.browsingData.remove({
            'since': 0
        }
      , {
            'appcache': true
          , 'cache': true
          , 'cookies': true
          , 'downloads': true
          , 'fileSystems': true
          , 'formData': true
          , 'history': true
          , 'indexedDB': true
          , 'localStorage': true
          , 'pluginData': true
          , 'passwords': true
          , 'webSQL': true
      }
    , function() {
        // do nothing...
    });
}

2.6 jquery.js

如果需要在background.js里面引用jquery.js,那么下載一個(gè)jquery.js文件放進(jìn)目錄里即可,記得在permission配置的scripts選項(xiàng)添加jquery.js引用。

3. 安裝方法

chajian_by_lucasluo.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容