Chrome扩展学习Demo:chrome.*API的使用

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:12   1256   0

直接上方法

// 点击浏览器右上角插件图标时作出反应。
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);
  }
});

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP