Chrome擴展學習Demo:chrome.*API的使用

直接上方法

// 點擊瀏覽器右上角插件圖標時作出反應。
chrome.browserAction.onClicked.addListener(function (tab) {
  console.log('currentTab:', tab);
});
// 獲取存在、未過期並且匹配給定信息的所有 Cookie。
chrome.cookies.getAll({url: "https://easy.lagou.com"}, function (e) {console.log(e)})

// 使用 chrome.storage API 存儲、獲取用戶數據,追蹤用戶數據的更改。
chrome.storage.sync.set({key: value}, function () {
  console.log('Value is set to ' + value);
});
chrome.storage.sync.get(['key'], function (result) {
  console.log('Value currently is ' + result.key);
});
chrome.storage.local.set({key: value}, function () {
  console.log('Value is set to ' + value);
});
chrome.storage.local.get(['key'], function (result) {
  console.log('Value currently is ' + result.key);
});
chrome.storage.sync.clear();
chrome.storage.local.clear();
chrome.storage.onChanged.addListener(function (changes, namespace) {
  for (key in changes) {
    var storageChange = changes[key];
    console.log('存儲鍵“%s”(位於“%s”命名空間中)已更改。' +
      '原來的值爲“%s”,新的值爲“%s”。',
      key,
      namespace,
      storageChange.oldValue,
      storageChange.newValue);
  }
});

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章