init with tutorial
commit
f236859e05
@ -0,0 +1,6 @@
|
||||
let color = "#3aa757";
|
||||
|
||||
chrome.runtime.onInstalled.addListener(() => {
|
||||
chrome.storage.sync.set({ color });
|
||||
console.log("Default color set to %cgreen", `color: ${color}`);
|
||||
});
|
@ -0,0 +1,13 @@
|
||||
button {
|
||||
height: 30px;
|
||||
width: 30px;
|
||||
outline: none;
|
||||
margin: 10px;
|
||||
border: none;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
button.current {
|
||||
box-shadow: 0 0 0 2px white,
|
||||
0 0 0 4px black;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 495 B |
Binary file not shown.
After Width: | Height: | Size: 814 B |
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "Getting started bla bla",
|
||||
"description": "Test for a Ggl Chrome Extension",
|
||||
"version": "1.0",
|
||||
"manifest_version": 3,
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
},
|
||||
"permissions": [
|
||||
"storage",
|
||||
"activeTab",
|
||||
"scripting"
|
||||
],
|
||||
"options_page": "options.html",
|
||||
"action": {
|
||||
"default_popup": "popup.html",
|
||||
"default_icon": {
|
||||
"16": "/images/get_started16.png",
|
||||
"32": "/images/get_started32.png",
|
||||
"48": "/images/get_started48.png",
|
||||
"128": "/images/get_started128.png"
|
||||
}
|
||||
},
|
||||
"icons": {
|
||||
"16": "/images/get_started16.png",
|
||||
"32": "/images/get_started32.png",
|
||||
"48": "/images/get_started48.png",
|
||||
"128": "/images/get_started128.png"
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<link rel="stylesheet" href="button.css" />
|
||||
<script src="options.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="buttonDiv"></div>
|
||||
<div>
|
||||
<p>Choose a different background color</p>
|
||||
<input type="color" name="color" id="colorPicker" />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,16 @@
|
||||
let page = document.getElementById("buttonDiv");
|
||||
let selectedClassName = "current";
|
||||
|
||||
let colorPicker = document.getElementById("colorPicker");
|
||||
|
||||
colorPicker.addEventListener("change", () => {
|
||||
let color = colorPicker.value;
|
||||
chrome.storage.sync.set({ color });
|
||||
});
|
||||
|
||||
window.addEventListener("load", () => {
|
||||
chrome.storage.sync.get("color", (data) => {
|
||||
let currentColor = data.color;
|
||||
colorPicker.value = currentColor;
|
||||
});
|
||||
});
|
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<link rel="stylesheet" href="button.css" />
|
||||
<script src="popup.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<button id="changeColor"></button>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,21 @@
|
||||
// Init button with user's preferred color
|
||||
let changeColor = document.getElementById("changeColor");
|
||||
|
||||
chrome.storage.sync.get("color", ({ color }) => {
|
||||
changeColor.style.backgroundColor = color;
|
||||
});
|
||||
|
||||
changeColor.addEventListener("click", async () => {
|
||||
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
||||
|
||||
chrome.scripting.executeScript({
|
||||
target: { tabId: tab.id },
|
||||
function: setPageBackgroundColor,
|
||||
});
|
||||
});
|
||||
|
||||
var setPageBackgroundColor = function () {
|
||||
chrome.storage.sync.get("color", ({ color }) => {
|
||||
document.body.style.backgroundColor = color;
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue