mirror of
https://gitee.com/bitdance-team/chrome-extension
synced 2025-01-10 13:48:14 +08:00
【重大Bug】解决Git自动合并导致番茄钟代码混乱问题,出现问题的commit: 2cf513d
This commit is contained in:
parent
dcd8d152cc
commit
9ec752892c
@ -1,15 +1,15 @@
|
||||
// 用户首次安装插件时执行一次,后面不会再重新执行(除非用户重新安装插件)
|
||||
chrome.runtime.onInstalled.addListener(() => {
|
||||
// 插件功能安装默认启用
|
||||
chrome.storage.sync.set({
|
||||
//初始化数据
|
||||
pomoData: {
|
||||
minutes: 24,
|
||||
seconds: 60,
|
||||
countdownTimer: "25:00",
|
||||
status: "init",
|
||||
},
|
||||
});
|
||||
// 插件功能安装默认启用
|
||||
chrome.storage.sync.set({
|
||||
//初始化数据
|
||||
pomoData: {
|
||||
minutes: 24,
|
||||
seconds: 60,
|
||||
countdownTimer: "25:00",
|
||||
status: "init",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
let minutes, seconds;
|
||||
@ -22,120 +22,66 @@ let array = ["minutes", "seconds", "pause", "countdownTimer", "pbutton"];
|
||||
let timer = null;
|
||||
|
||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
console.log(`进入 assets\html\pomodoro\background.js 中的onMessage Listener`)
|
||||
if (message.senderId !== "pomo") {
|
||||
// 抛给下一个Listener
|
||||
sendResponse();
|
||||
}
|
||||
|
||||
const { status, content } = message;
|
||||
|
||||
if (status === "start") {
|
||||
// sendResponse({
|
||||
// status:message.status
|
||||
// })
|
||||
countdown({...content, status });
|
||||
} else if (status === "paused") {
|
||||
clearTimeout(timer);
|
||||
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
|
||||
console.log(pomoData);
|
||||
chrome.storage.sync.set({ pomoData: {...pomoData, status: "paused" } });
|
||||
});
|
||||
} else if (status === "reset") {
|
||||
clearTimeout(timer);
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
minutes: 24,
|
||||
seconds: 60,
|
||||
countdownTimer: "25:00",
|
||||
status: "init",
|
||||
},
|
||||
});
|
||||
chrome.browserAction.setBadgeText({ text: "" });
|
||||
} else if (status === "init") {
|
||||
//init初始化
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
minutes: 24,
|
||||
seconds: 60,
|
||||
countdownTimer: "25:00",
|
||||
status: "init",
|
||||
},
|
||||
});
|
||||
} else {
|
||||
//playend 初始化
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
minutes: 24,
|
||||
seconds: 60,
|
||||
countdownTimer: "25:00",
|
||||
status: "playend",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//创建结束通知:待完成
|
||||
|
||||
chrome.storage.sync.set({
|
||||
status,
|
||||
});
|
||||
//后台播放完成提示音乐
|
||||
if (message.action === "play") {
|
||||
// audio.play();
|
||||
}
|
||||
sendResponse();
|
||||
console.log(`进入 assets\html\pomodoro\background.js 中的onMessage Listener`)
|
||||
if (message.senderId !== "pomo") {
|
||||
// 抛给下一个Listener
|
||||
sendResponse();
|
||||
}
|
||||
|
||||
const { status, content } = message;
|
||||
|
||||
if (status === "start") {
|
||||
// sendResponse({
|
||||
// status:message.status
|
||||
// })
|
||||
countdown({ ...content, status });
|
||||
// sendResponse({
|
||||
// status:message.status
|
||||
// })
|
||||
countdown({...content, status });
|
||||
} else if (status === "paused") {
|
||||
clearTimeout(timer);
|
||||
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
|
||||
console.log(pomoData);
|
||||
chrome.storage.sync.set({ pomoData: { ...pomoData, status: "paused" } });
|
||||
});
|
||||
clearTimeout(timer);
|
||||
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
|
||||
console.log(pomoData);
|
||||
chrome.storage.sync.set({ pomoData: {...pomoData, status: "paused" } });
|
||||
});
|
||||
} else if (status === "reset") {
|
||||
clearTimeout(timer);
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
minutes: 24,
|
||||
seconds: 60,
|
||||
countdownTimer: "25:00",
|
||||
status: "init",
|
||||
},
|
||||
});
|
||||
chrome.browserAction.setBadgeText({ text: "" });
|
||||
clearTimeout(timer);
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
minutes: 24,
|
||||
seconds: 60,
|
||||
countdownTimer: "25:00",
|
||||
status: "init",
|
||||
},
|
||||
});
|
||||
chrome.browserAction.setBadgeText({ text: "" });
|
||||
} else if (status === "init") {
|
||||
//init初始化
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
minutes: 24,
|
||||
seconds: 60,
|
||||
countdownTimer: "25:00",
|
||||
status: "init"
|
||||
},
|
||||
});
|
||||
//init初始化
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
minutes: 24,
|
||||
seconds: 60,
|
||||
countdownTimer: "25:00",
|
||||
status: "init",
|
||||
},
|
||||
});
|
||||
} else {
|
||||
//playend 初始化
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
minutes: 24,
|
||||
seconds: 60,
|
||||
countdownTimer: "25:00",
|
||||
status: "playend",
|
||||
},
|
||||
});
|
||||
//playend 初始化
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
minutes: 24,
|
||||
seconds: 60,
|
||||
countdownTimer: "25:00",
|
||||
status: "playend",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//创建结束通知:待完成
|
||||
chrome.storage.sync.set({
|
||||
status,
|
||||
});
|
||||
|
||||
//后台播放完成提示音乐
|
||||
if (status === "playend") {
|
||||
// audio.play();
|
||||
console.log("playend***")
|
||||
if (message.action === "play") {
|
||||
// audio.play();
|
||||
}
|
||||
sendResponse();
|
||||
console.log(`离开 assets\html\pomodoro\background.js 中的onMessage Listener`)
|
||||
@ -144,37 +90,31 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
|
||||
// 番茄钟倒计时功能
|
||||
function countdown({ minutes, seconds, status }) {
|
||||
// 设置分钟和秒数
|
||||
// let currentMins = minutes - 1;
|
||||
seconds--;
|
||||
let currentTimer =
|
||||
(minutes < 10 ? "0" : "") +
|
||||
minutes +
|
||||
":" +
|
||||
(seconds < 10 ? "0" : "") +
|
||||
seconds;
|
||||
// countdownTimer.innerHTML = currentTimer; 拿到
|
||||
console.log("分秒=============", minutes, seconds);
|
||||
// 设置分钟和秒数
|
||||
// let currentMins = minutes - 1;
|
||||
seconds--;
|
||||
let currentTimer =
|
||||
(minutes < 10 ? "0" : "") +
|
||||
minutes +
|
||||
":" +
|
||||
(seconds < 10 ? "0" : "") +
|
||||
seconds;
|
||||
// countdownTimer.innerHTML = currentTimer; 拿到
|
||||
console.log("分秒=============", minutes, seconds);
|
||||
|
||||
//番茄钟结束桌面提醒
|
||||
if(currentTimer === "00:00"){
|
||||
showPomoNotification();
|
||||
}
|
||||
|
||||
chrome.storage.sync.set(
|
||||
{
|
||||
pomoData: {
|
||||
seconds: seconds,
|
||||
minutes: minutes,
|
||||
countdownTimer: currentTimer,
|
||||
status,
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
seconds: seconds,
|
||||
minutes: minutes,
|
||||
countdownTimer: currentTimer,
|
||||
status,
|
||||
},
|
||||
},
|
||||
},
|
||||
function () {
|
||||
if (!chrome.runtime.error) {
|
||||
console.log("started");
|
||||
function() {
|
||||
if (!chrome.runtime.error) {
|
||||
console.log("started");
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
//设置badge文本用来显示剩余分钟数
|
||||
@ -193,58 +133,28 @@ function countdown({ minutes, seconds, status }) {
|
||||
// count down every second, when a minute is up, countdown one minute
|
||||
// when time reaches 0:00, reset
|
||||
if (seconds > 0) {
|
||||
timer = setTimeout(() => {
|
||||
countdown({ minutes, seconds, status });
|
||||
}, 1000);
|
||||
timer = setTimeout(() => {
|
||||
countdown({ minutes, seconds, status });
|
||||
}, 1000);
|
||||
} else if (minutes > 0) {
|
||||
seconds = 60;
|
||||
minutes--;
|
||||
chrome.storage.sync.set(
|
||||
{
|
||||
pomoData: {
|
||||
seconds: seconds,
|
||||
minutes: minutes,
|
||||
countdownTimer: currentTimer,
|
||||
status,
|
||||
},
|
||||
function() {
|
||||
if (!chrome.runtime.error) {
|
||||
console.log("started");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
//设置badge文本用来显示剩余分钟数
|
||||
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
|
||||
chrome.browserAction.setBadgeText({ text: pomoData.minutes.toString() + ":" + pomoData.seconds.toString() });
|
||||
});
|
||||
|
||||
console.log(currentTimer);
|
||||
// count down every second, when a minute is up, countdown one minute
|
||||
// when time reaches 0:00, reset
|
||||
if (seconds > 0) {
|
||||
timer = setTimeout(() => {
|
||||
countdown({ minutes, seconds, status });
|
||||
}, 1000);
|
||||
} else if (minutes > 0) {
|
||||
seconds = 60;
|
||||
minutes--;
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
seconds: seconds,
|
||||
minutes: minutes,
|
||||
countdownTimer: currentTimer,
|
||||
status,
|
||||
},
|
||||
},
|
||||
function() {
|
||||
if (!chrome.runtime.error) {
|
||||
console.log("started");
|
||||
}
|
||||
}
|
||||
);
|
||||
countdown({ minutes, seconds, status });
|
||||
}
|
||||
seconds = 60;
|
||||
minutes--;
|
||||
chrome.storage.sync.set({
|
||||
pomoData: {
|
||||
seconds: seconds,
|
||||
minutes: minutes,
|
||||
countdownTimer: currentTimer,
|
||||
status,
|
||||
},
|
||||
},
|
||||
function() {
|
||||
if (!chrome.runtime.error) {
|
||||
console.log("started");
|
||||
}
|
||||
}
|
||||
);
|
||||
countdown({ minutes, seconds, status });
|
||||
}
|
||||
}
|
||||
|
||||
//设置badge文本背景颜色
|
||||
@ -252,7 +162,6 @@ chrome.browserAction.setBadgeBackgroundColor({ color: "#DD4A48" });
|
||||
|
||||
//桌面通知
|
||||
function showPomoNotification(){
|
||||
|
||||
new Notification("番茄钟🍅",{
|
||||
//图标暂时未设置
|
||||
icon:'48.png',
|
||||
|
Loading…
Reference in New Issue
Block a user