Skip to content

Instantly share code, notes, and snippets.

@DylanKojiCheslin
Forked from IzumiSy/manifest.json
Created May 29, 2022 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DylanKojiCheslin/216586c1699cd995c73bead0d0476ff0 to your computer and use it in GitHub Desktop.
Save DylanKojiCheslin/216586c1699cd995c73bead0d0476ff0 to your computer and use it in GitHub Desktop.
Chrome.storage.sync example
{
"name": "SyncExtension",
"version": "0.1",
"manifest_version": 2,
"description": "Storage Sync Extension",
"permissions": [ "storage" ],
"browser_action": {
"default_popup": "popup.html"
}
}
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
</head>
<body>
<div id="data"></div>
<input type="text" id="text"></input>
<button id="set">Set</button>
<script src="popup.js"></script>
</body>
</html>
// popup.js
document.body.onload = function() {
chrome.storage.sync.get("data", function(items) {
if (!chrome.runtime.error) {
console.log(items);
document.getElementById("data").innerText = items.data;
}
});
}
document.getElementById("set").onclick = function() {
var d = document.getElementById("text").value;
chrome.storage.sync.set({ "data" : d }, function() {
if (chrome.runtime.error) {
console.log("Runtime error.");
}
});
window.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment