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