mirror of
https://gitee.com/bitdance-team/chrome-extension
synced 2025-10-07 16:35:15 +08:00
增加了铃声,代码注释和优化
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
/* background-color: rgb(51, 11, 116); */
|
/* background-color: rgb(51, 11, 116); */
|
||||||
background: url(../../images/pomo1.png) no-repeat;
|
background: url(../../images/pomo_ocean.jpg) no-repeat;
|
||||||
background-image: "../../";
|
background-image: "../../";
|
||||||
/* color: white; */
|
/* color: white; */
|
||||||
font-family: 'Fira Sans', sans-serif;
|
font-family: 'Fira Sans', sans-serif;
|
||||||
|
@@ -29,6 +29,8 @@ const resetBtn = document.getElementById("reset-btn");
|
|||||||
const endBtn = document.getElementById("end-btn");
|
const endBtn = document.getElementById("end-btn");
|
||||||
const countdownTimer = document.getElementById("countdown");
|
const countdownTimer = document.getElementById("countdown");
|
||||||
|
|
||||||
|
const audio = document.getElementById("audio");
|
||||||
|
//全局唯一的定时器
|
||||||
let timer = null;
|
let timer = null;
|
||||||
|
|
||||||
let minutes, seconds;
|
let minutes, seconds;
|
||||||
@@ -90,11 +92,9 @@ function start() {
|
|||||||
(response) => {
|
(response) => {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
|
||||||
|
|
||||||
startBtn.style.display = "none";
|
startBtn.style.display = "none";
|
||||||
endBtn.style.display = "block";
|
endBtn.style.display = "block";
|
||||||
getTimer();
|
getTimer();
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -120,12 +120,35 @@ function end() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTimer() {
|
function getTimer() {
|
||||||
clearTimer()
|
clearTimer();
|
||||||
timer = setInterval(() => {
|
timer = setInterval(() => {
|
||||||
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
|
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
|
||||||
|
// console.log("pomodata****",pomoData)
|
||||||
|
// const{minutes,seconds,countdownTimer} = pomoData;
|
||||||
countdownTimer.innerHTML = pomoData.countdownTimer;
|
countdownTimer.innerHTML = pomoData.countdownTimer;
|
||||||
|
|
||||||
|
//更新后倒计时判断,如果结束则重新初始化界面
|
||||||
|
if(pomoData.countdownTimer == "00:00"){
|
||||||
|
|
||||||
|
audio.play();
|
||||||
|
chrome.runtime.sendMessage(
|
||||||
|
{
|
||||||
|
status: "init",
|
||||||
|
},
|
||||||
|
(response) => {
|
||||||
|
console.log(response);
|
||||||
|
countdownTimer.innerHTML = "25:00";
|
||||||
|
|
||||||
|
startBtn.style.display = "block";
|
||||||
|
endBtn.style.display = "none";
|
||||||
|
clearTimer();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearTimer() {
|
function clearTimer() {
|
||||||
@@ -167,9 +190,7 @@ resetBtn.addEventListener("click", () => {
|
|||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
//页面反复打开时初始化
|
//页面反复打开时页面初始化
|
||||||
// start();
|
|
||||||
|
|
||||||
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
|
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
|
||||||
console.log(pomoData);
|
console.log(pomoData);
|
||||||
const { status } = pomoData;
|
const { status } = pomoData;
|
||||||
@@ -179,13 +200,12 @@ chrome.storage.sync.get("pomoData", ({ pomoData }) => {
|
|||||||
endBtn.style.display = "block";
|
endBtn.style.display = "block";
|
||||||
getTimer();
|
getTimer();
|
||||||
} else if (status === "paused") {
|
} else if (status === "paused") {
|
||||||
|
|
||||||
startBtn.style.display = "block";
|
startBtn.style.display = "block";
|
||||||
endBtn.style.display = "none";
|
endBtn.style.display = "none";
|
||||||
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
|
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
|
||||||
countdownTimer.innerHTML = pomoData.countdownTimer;
|
countdownTimer.innerHTML = pomoData.countdownTimer;
|
||||||
});
|
});
|
||||||
} else if(status === "init"){
|
} else if (status === "init") {
|
||||||
chrome.runtime.sendMessage({
|
chrome.runtime.sendMessage({
|
||||||
status: "init",
|
status: "init",
|
||||||
});
|
});
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
chrome.runtime.onInstalled.addListener(() => {
|
chrome.runtime.onInstalled.addListener(() => {
|
||||||
// 插件功能安装默认启用
|
// 插件功能安装默认启用
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
|
//初始化数据
|
||||||
pomoData: {
|
pomoData: {
|
||||||
minutes: 24,
|
minutes: 24,
|
||||||
seconds: 60,
|
seconds: 60,
|
||||||
@@ -17,12 +18,9 @@ let pomodoro = "pomodoro";
|
|||||||
|
|
||||||
let array = ["minutes", "seconds", "pause", "countdownTimer", "pbutton"];
|
let array = ["minutes", "seconds", "pause", "countdownTimer", "pbutton"];
|
||||||
|
|
||||||
|
//全局唯一的定时器
|
||||||
let timer = null;
|
let timer = null;
|
||||||
// chorme.runtime.onMessage.addListener(()=>{
|
|
||||||
// chorme.storage.sync.get("pause",({pause})=>{
|
|
||||||
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// 记住 是否暂停、
|
// 记住 是否暂停、
|
||||||
|
|
||||||
@@ -37,7 +35,6 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|||||||
// sendResponse({
|
// sendResponse({
|
||||||
// status:message.status
|
// status:message.status
|
||||||
// })
|
// })
|
||||||
|
|
||||||
countdown({ ...content, status });
|
countdown({ ...content, status });
|
||||||
} else if (status === "paused") {
|
} else if (status === "paused") {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
@@ -59,8 +56,8 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|||||||
//init初始化
|
//init初始化
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
pomoData: {
|
pomoData: {
|
||||||
minutes: 24,
|
minutes: 0,
|
||||||
seconds: 60,
|
seconds: 5,
|
||||||
countdownTimer: "25:00",
|
countdownTimer: "25:00",
|
||||||
status: "start",
|
status: "start",
|
||||||
},
|
},
|
||||||
@@ -74,7 +71,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|||||||
|
|
||||||
// 番茄钟倒计时功能
|
// 番茄钟倒计时功能
|
||||||
function countdown({ minutes, seconds, status }) {
|
function countdown({ minutes, seconds, status }) {
|
||||||
console.log("分秒=============", minutes, seconds);
|
|
||||||
// 设置分钟和秒数
|
// 设置分钟和秒数
|
||||||
// let currentMins = minutes - 1;
|
// let currentMins = minutes - 1;
|
||||||
seconds--;
|
seconds--;
|
||||||
@@ -85,6 +82,7 @@ function countdown({ minutes, seconds, status }) {
|
|||||||
(seconds < 10 ? "0" : "") +
|
(seconds < 10 ? "0" : "") +
|
||||||
seconds;
|
seconds;
|
||||||
// countdownTimer.innerHTML = currentTimer; 拿到
|
// countdownTimer.innerHTML = currentTimer; 拿到
|
||||||
|
console.log("分秒=============", minutes, seconds);
|
||||||
|
|
||||||
chrome.storage.sync.set(
|
chrome.storage.sync.set(
|
||||||
{
|
{
|
||||||
@@ -127,9 +125,6 @@ function countdown({ minutes, seconds, status }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
countdown({ minutes, seconds });
|
countdown({ minutes, seconds,status });
|
||||||
} else if (currentMins === 0) {
|
|
||||||
audio.play();
|
|
||||||
reset();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
gitee_pomodoro/images/pomo_crystal.jpg
Normal file
BIN
gitee_pomodoro/images/pomo_crystal.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
gitee_pomodoro/images/pomo_ocean.jpg
Normal file
BIN
gitee_pomodoro/images/pomo_ocean.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
BIN
gitee_pomodoro/images/pomo_waterfall.jpg
Normal file
BIN
gitee_pomodoro/images/pomo_waterfall.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
Reference in New Issue
Block a user