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);
}
});
还没有评论,来说两句吧...