// ==UserScript==
// @name 目标追踪
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 非常好用的目标追踪器nya
// @author BetterGlow and Doubao AI
// @match *://*/*
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
let l = localStorage.getItem('goal_tracker_lang') || 'en';
let d = localStorage.getItem('goal_tracker_dark') === 'true' || false;
let a = localStorage.getItem('goal_tracker_anim') === 'true' || true;
let t = JSON.parse(localStorage.getItem('goal_tracker_theme')) || {
primary: '#667eea',
secondary: '#764ba2',
completed: '#22c55e'
};
const c = {
en: {
collapseTip: 'All great actions and all great thoughts have a humble beginning.',
emptyTip: 'Click Settings to add a goal.',
settings: 'Settings',
goalContent: 'Goal Content',
currentProgress: 'Current Progress',
targetGoal: 'Final Goal',
progressBarColor: 'Color',
saveGoal: 'Save',
cancel: 'Cancel',
plusOne: '+1',
delete: 'Delete',
confirmDelete: 'Confirm',
deleteTip: 'Click again to delete',
enterContent: 'Please enter goal content',
targetValid: 'Final goal must be a number greater than 0',
language: 'Language',
english: 'English',
chinese: 'Chinese',
completed: 'Completed',
smiley: '😊',
edit: 'Edit',
saveEdit: 'Save',
appearance: 'Appearance',
darkMode: 'Dark Mode',
enableAnimation: 'Animation',
customTheme: 'Custom Theme',
primaryColor: 'Primary Color',
secondaryColor: 'Secondary Color',
completedColor: 'Completed Color',
saveTheme: 'Save',
moveUp: '↑',
moveDown: '↓',
editGoal: 'Edit'
},
cn: {
collapseTip: '任何一个伟大的思想,都有一个微不足道的开始。',
emptyTip: '点击设置以添加目标',
settings: '设置',
goalContent: '目标内容',
currentProgress: '当前进度',
targetGoal: '最终目标',
progressBarColor: '颜色',
saveGoal: '保存',
cancel: '取消',
plusOne: '+1',
delete: '删除',
confirmDelete: '确认',
deleteTip: '再次点击删除',
enterContent: '请输入目标内容',
targetValid: '最终目标应是大于0的数字',
language: '语言',
english: '英文',
chinese: '中文',
completed: '已完成',
smiley: '😊',
edit: '编辑',
saveEdit: '保存',
appearance: '外观',
darkMode: '深色模式',
enableAnimation: '动画',
customTheme: '自定义主题',
primaryColor: '主色',
secondaryColor: '辅色',
completedColor: '完成色',
saveTheme: '保存',
moveUp: '↑',
moveDown: '↓',
editGoal: '编辑'
}
};
const g = (k) => c[l][k];
const u = () => {
const o = document.getElementById('goal-tracker-style');
if (o) o.remove();
const s = document.createElement('style');
s.id = 'goal-tracker-style';
const b = d ? 'rgba(30, 30, 40, 0.3)' : 'rgba(255, 255, 255, 0.3)';
const h = `linear-gradient(135deg, ${t.primary} 0%, ${t.secondary} 100%)`;
const i = d ? 'rgba(40, 40, 50, 0.8)' : 'rgba(255, 255, 255, 0.8)';
const j = d ? 'rgba(45, 45, 60, 0.9)' : 'rgba(255, 255, 255, 0.9)';
const m = d ? '#e2e8f0' : '#2d3748';
const n = d ? '#a0aec0' : '#4a5568';
s.textContent = `
#goal-tracker-container {
position: fixed;
left: 20px;
bottom: 20px;
width: 280px;
background: ${b};
border-radius: 16px;
padding: 15px;
z-index: 999999;
backdrop-filter: blur(8px);
transition: ${a ? 'transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s cubic-bezier(0.4, 0, 0.2, 1)' : 'none'};
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
cursor: move;
height: auto;
max-height: 120px;
overflow: hidden;
transform: translateZ(0);
will-change: transform, max-height, opacity;
pointer-events: auto !important;
user-select: none;
-webkit-user-select: none;
color: ${m};
}
#goal-tracker-container:hover {
background: ${h};
opacity: 1 !important;
transform: ${a ? 'translateZ(0) translateY(-4px)' : 'none'};
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
max-height: 600px;
}
.goal-item {
background: ${i};
border-radius: 12px;
padding: 12px;
margin-bottom: 10px;
transition: ${a ? 'background 0.2s ease' : 'none'};
transform: translateZ(0);
pointer-events: auto;
color: ${m};
}
#goal-tracker-container:hover .goal-item {
background: ${j};
}
.goal-content {
font-size: 15px;
font-weight: 600;
color: ${m};
margin-bottom: 6px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.goal-metrics {
display: flex;
justify-content: space-between;
font-size: 13px;
color: ${n};
margin-bottom: 6px;
}
.goal-progress-bar {
height: 6px;
border-radius: 3px;
overflow: hidden;
background: ${d ? 'rgba(80, 80, 100, 0.5)' : 'rgba(200, 200, 200, 0.5)'};
margin-bottom: 6px;
}
.goal-progress-fill {
height: 100%;
border-radius: 3px;
transition: ${a ? 'width 0.3s cubic-bezier(0.4, 0, 0.2, 1)' : 'none'};
transform: translateZ(0);
}
.goal-btn {
border: none;
border-radius: 8px;
padding: 5px 10px;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: ${a ? 'transform 0.2s ease, background 0.2s ease' : 'none'};
transform: translateZ(0);
}
.plus-one-btn {
background: ${t.primary};
color: white;
margin-right: 6px;
}
.plus-one-btn:hover {
background: ${d ? f(t.primary, -10) : f(t.primary, -10)};
transform: ${a ? 'translateZ(0) scale(1.05)' : 'none'};
}
.delete-btn {
background: #e53e3e;
color: white;
margin-right: 6px;
}
.delete-btn:hover {
background: #c53030;
transform: ${a ? 'translateZ(0) scale(1.05)' : 'none'};
}
.delete-btn.confirm {
background: #dc2626;
animation: ${a ? 'pulse 0.5s ease' : 'none'};
}
.edit-btn {
background: #f59e0b;
color: white;
margin-right: 6px;
}
.edit-btn:hover {
background: #d97706;
transform: ${a ? 'translateZ(0) scale(1.05)' : 'none'};
}
.move-btn {
background: ${d ? '#4b5563' : '#94a3b8'};
color: white;
margin-right: 6px;
padding: 5px 8px;
}
.move-btn:hover {
background: ${d ? '#64748b' : '#718096'};
transform: ${a ? 'translateZ(0) scale(1.05)' : 'none'};
}
.move-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
background: ${d ? '#374151' : '#cbd5e1'};
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.1); }
100% { transform: scale(1); }
}
@keyframes celebrate {
0% { transform: scale(1); }
50% { transform: scale(1.2); }
100% { transform: scale(1); }
}
#settings-btn {
width: 100%;
background: ${t.secondary};
color: white;
margin-top: 8px;
padding: 7px 0;
font-size: 14px;
}
#settings-btn:hover {
background: ${d ? f(t.secondary, -10) : f(t.secondary, -10)};
}
#goal-modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) translateZ(0);
width: 340px;
background: ${h};
border-radius: 16px;
padding: 20px;
z-index: 1000000;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
display: none;
will-change: opacity;
transition: ${a ? 'opacity 0.2s ease' : 'none'};
color: white;
}
.modal-tabs {
display: flex;
gap: 8px;
margin-bottom: 15px;
border-bottom: 1px solid rgba(255,255,255,0.3);
padding-bottom: 8px;
}
.tab-btn {
padding: 6px 12px;
border-radius: 8px;
border: none;
background: rgba(255,255,255,0.2);
color: white;
cursor: pointer;
transition: ${a ? 'all 0.2s ease' : 'none'};
}
.tab-btn.active {
background: white;
color: ${t.secondary};
font-weight: 600;
}
.lang-switch-group, .appearance-group, .theme-group {
margin-bottom: 15px;
}
.lang-switch, .toggle-group {
display: flex;
gap: 8px;
margin-top: 5px;
}
.lang-btn, .toggle-btn {
flex: 1;
padding: 6px 0;
border-radius: 6px;
border: 1px solid rgba(255,255,255,0.5);
background: rgba(255,255,255,0.2);
color: white;
cursor: pointer;
transition: ${a ? 'all 0.2s ease' : 'none'};
}
.lang-btn.active, .toggle-btn.active {
background: white;
color: ${t.secondary};
font-weight: 600;
}
.color-group {
display: flex;
gap: 8px;
margin-top: 5px;
}
.color-input {
flex: 1;
height: 36px;
border-radius: 6px;
border: none;
cursor: pointer;
background: transparent;
}
#modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: ${d ? 'rgba(0, 0, 0, 0.7)' : 'rgba(0, 0, 0, 0.5)'};
z-index: 999999;
display: none;
backdrop-filter: blur(4px);
opacity: 0;
transition: ${a ? 'opacity 0.2s ease' : 'none'};
}
#modal-overlay.show {
opacity: 1;
}
.modal-input-group {
margin-bottom: 12px;
}
.modal-label {
display: block;
color: white;
font-size: 13px;
margin-bottom: 5px;
font-weight: 500;
}
.modal-input {
width: 100%;
padding: 8px;
border-radius: 8px;
border: none;
font-size: 13px;
background: ${d ? 'rgba(40, 40, 50, 0.9)' : 'rgba(255, 255, 255, 0.9)'};
color: ${d ? '#e2e8f0' : '#2d3748'};
}
.modal-input:focus {
outline: none;
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
}
.modal-btn-group {
display: flex;
gap: 8px;
margin-top: 18px;
}
#save-goal-btn, #cancel-btn, #save-theme-btn {
flex: 1;
padding: 8px 0;
font-size: 13px;
}
#save-goal-btn, #save-theme-btn {
background: ${t.completed};
color: white;
}
#save-goal-btn:hover, #save-theme-btn:hover {
background: ${d ? f(t.completed, -10) : f(t.completed, -10)};
}
#cancel-btn {
background: #e53e3e;
color: white;
}
#cancel-btn:hover {
background: #c53030;
}
.collapse-tip {
color: ${d ? '#e2e8f0' : '#2d3748'};
text-align: center;
padding: 10px 0;
font-size: 14px;
display: block;
}
#goal-tracker-container:hover .collapse-tip {
display: none;
}
.goal-completed {
display: flex;
align-items: center;
gap: 6px;
font-size: 14px;
font-weight: 600;
color: ${t.completed};
margin-bottom: 6px;
animation: ${a ? 'celebrate 0.8s ease' : 'none'};
}
.edit-mode {
padding: 10px 0;
}
.edit-input {
width: 100%;
padding: 8px;
border-radius: 6px;
border: 1px solid ${t.primary};
margin-bottom: 8px;
background: ${d ? 'rgba(40, 40, 50, 0.9)' : 'rgba(255, 255, 255, 0.9)'};
color: ${d ? '#e2e8f0' : '#2d3748'};
font-size: 14px;
}
`;
document.head.appendChild(s);
};
const f = (h, p) => {
const n = parseInt(h.replace('#',''), 16);
const a = Math.round(2.55 * p);
const R = (n >> 16) + a;
const G = (n >> 8 & 0x00FF) + a;
const B = (n & 0x0000FF) + a;
return `#${(0x1000000 + (R<255?R<1?0:R:255)*0x10000 + (G<255?G<1?0:G:255)*0x100 + (B<255?B<1?0:B:255)).toString(16).slice(1)}`;
};
let x = [];
let y = {
left: '20px',
bottom: '20px',
top: 'auto',
right: 'auto'
};
let z = null;
try {
const s = localStorage.getItem('tampermonkey_goals');
if (s) {
x = JSON.parse(s) || [];
x = x.filter(i =>
i && typeof i === 'object' &&
typeof i.content === 'string' &&
!isNaN(i.current) &&
!isNaN(i.target) &&
i.target > 0
);
}
const p = localStorage.getItem('tampermonkey_goal_window_pos');
if (p) {
y = JSON.parse(p) || y;
if (typeof y.left !== 'string' || typeof y.top !== 'string') {
y = { left: '20px', bottom: '20px', top: 'auto', right: 'auto' };
}
}
} catch (e) {
console.error('读取本地数据失败:', e);
x = [];
y = { left: '20px', bottom: '20px', top: 'auto', right: 'auto' };
}
const s = () => {
try {
localStorage.setItem('tampermonkey_goals', JSON.stringify(x));
} catch (e) {
console.error('保存目标失败:', e);
}
};
const p = (pos) => {
try {
localStorage.setItem('tampermonkey_goal_window_pos', JSON.stringify(pos));
} catch (e) {
console.error('保存位置失败:', e);
}
};
const e = () => {
try {
localStorage.setItem('goal_tracker_lang', l);
localStorage.setItem('goal_tracker_dark', d);
localStorage.setItem('goal_tracker_anim', a);
localStorage.setItem('goal_tracker_theme', JSON.stringify(t));
} catch (e) {
console.error('保存设置失败:', e);
}
};
const m = (i, dir) => {
if (dir === 'up' && i > 0) {
[x[i], x[i-1]] = [x[i-1], x[i]];
} else if (dir === 'down' && i < x.length - 1) {
[x[i], x[i+1]] = [x[i+1], x[i]];
}
s();
if (z) {
r();
}
};
const ed = (i) => {
const g = x[i];
const gi = z.querySelector(`.goal-item:nth-child(${i+2})`);
gi.innerHTML = `
<div class="edit-mode">
<input type="text" class="edit-input" id="edit-content-${i}" value="${g.content}" placeholder="${g('goalContent')}">
<div style="display: flex; gap: 8px; margin-bottom: 8px;">
<input type="number" class="edit-input" id="edit-current-${i}" value="${g.current}" min="0" placeholder="${g('currentProgress')}" style="flex: 1;">
<input type="number" class="edit-input" id="edit-target-${i}" value="${g.target}" min="1" placeholder="${g('targetGoal')}" style="flex: 1;">
</div>
<input type="color" class="edit-input" id="edit-color-${i}" value="${g.color || '#4299e1'}">
<div style="display: flex; gap: 6px; margin-top: 8px;">
<button class="goal-btn edit-btn" id="save-edit-${i}">${g('saveEdit')}</button>
<button class="goal-btn delete-btn" id="cancel-edit-${i}">${g('cancel')}</button>
</div>
</div>
`;
document.getElementById(`save-edit-${i}`).onclick = () => {
const c = document.getElementById(`edit-content-${i}`).value.trim();
const cu = parseInt(document.getElementById(`edit-current-${i}`).value) || 0;
const ta = parseInt(document.getElementById(`edit-target-${i}`).value) || 1;
const co = document.getElementById(`edit-color-${i}`).value;
if (!c) {
alert(g('enterContent'));
return;
}
if (ta < 1) {
alert(g('targetValid'));
return;
}
x[i] = {
content: c,
current: Math.max(0, cu),
target: ta,
color: co
};
s();
r();
};
document.getElementById(`cancel-edit-${i}`).onclick = () => {
r();
};
};
const r = () => {
if (!z) return;
z.innerHTML = '';
const ct = document.createElement('div');
ct.className = 'collapse-tip';
ct.textContent = g('collapseTip');
z.appendChild(ct);
if (x.length === 0) {
const et = document.createElement('div');
et.style.color = d ? '#e2e8f0' : '#2d3748';
et.style.textAlign = 'center';
et.style.padding = '10px 0';
et.style.fontSize = '14px';
et.style.display = 'none';
et.textContent = g('emptyTip');
z.appendChild(et);
z.addEventListener('mouseenter', () => {
ct.style.display = 'none';
et.style.display = 'block';
});
z.addEventListener('mouseleave', () => {
ct.style.display = 'block';
et.style.display = 'none';
});
} else {
x.forEach((gl, i) => {
if (!gl || typeof gl !== 'object') return;
const cu = Math.max(0, parseInt(gl.current) || 0);
const ta = Math.max(1, parseInt(gl.target) || 1);
const cm = cu >= ta;
const pr = Math.min((cu / ta) * 100, 100);
const gi = document.createElement('div');
gi.className = 'goal-item';
const cn = document.createElement('div');
cn.className = 'goal-content';
cn.textContent = gl.content || 'Unnamed Goal';
gi.appendChild(cn);
const mt = document.createElement('div');
mt.className = 'goal-metrics';
mt.innerHTML = `<span>${g('currentProgress')}: ${cu}</span><span>${g('targetGoal')}: ${ta}</span>`;
gi.appendChild(mt);
if (cm) {
const cd = document.createElement('div');
cd.className = 'goal-completed';
cd.innerHTML = `<span>${g('completed')}</span><span>${g('smiley')}</span>`;
gi.appendChild(cd);
} else {
const pb = document.createElement('div');
pb.className = 'goal-progress-bar';
const pf = document.createElement('div');
pf.className = 'goal-progress-fill';
pf.style.backgroundColor = gl.color || t.primary;
pf.style.width = `${pr}%`;
pb.appendChild(pf);
gi.appendChild(pb);
const po = document.createElement('button');
po.className = 'goal-btn plus-one-btn';
po.textContent = g('plusOne');
po.onclick = () => {
x[i].current = cu + 1;
s();
r();
};
gi.appendChild(po);
}
const mu = document.createElement('button');
mu.className = 'goal-btn move-btn';
mu.textContent = g('moveUp');
mu.disabled = i === 0;
mu.onclick = () => m(i, 'up');
gi.appendChild(mu);
const md = document.createElement('button');
md.className = 'goal-btn move-btn';
md.textContent = g('moveDown');
md.disabled = i === x.length - 1;
md.onclick = () => m(i, 'down');
gi.appendChild(md);
const eb = document.createElement('button');
eb.className = 'goal-btn edit-btn';
eb.textContent = g('edit');
eb.onclick = () => ed(i);
gi.appendChild(eb);
const db = document.createElement('button');
db.className = 'goal-btn delete-btn';
db.textContent = g('delete');
let cf = false;
db.onclick = () => {
if (!cf) {
cf = true;
db.textContent = g('confirmDelete');
db.classList.add('confirm');
db.title = g('deleteTip');
setTimeout(() => {
if (cf && db) {
cf = false;
db.textContent = g('delete');
db.classList.remove('confirm');
db.title = '';
}
}, 3000);
} else {
x.splice(i, 1);
s();
r();
}
};
gi.appendChild(db);
z.appendChild(gi);
});
}
const sb = document.createElement('button');
sb.id = 'settings-btn';
sb.className = 'goal-btn';
sb.textContent = g('settings');
sb.onclick = () => {
o();
};
z.appendChild(sb);
};
const cr = () => {
if (document.getElementById('goal-tracker-container')) {
z = document.getElementById('goal-tracker-container');
return;
}
const co = document.createElement('div');
co.id = 'goal-tracker-container';
co.style.left = y.left;
co.style.bottom = y.bottom;
co.style.top = y.top;
co.style.right = y.right;
document.body.appendChild(co);
z = co;
dr(co);
u();
r();
};
let mo, ov;
const o = () => {
if (!mo) {
ov = document.createElement('div');
ov.id = 'modal-overlay';
ov.onclick = () => {
mo.style.display = 'none';
ov.classList.remove('show');
};
document.body.appendChild(ov);
mo = document.createElement('div');
mo.id = 'goal-modal';
document.body.appendChild(mo);
}
rs();
mo.style.display = 'block';
ov.classList.add('show');
};
const rs = () => {
if (!mo) return;
mo.innerHTML = `
<div class="modal-tabs">
<button class="tab-btn active" id="tab-goal">${g('settings')}</button>
<button class="tab-btn" id="tab-appearance">${g('appearance')}</button>
</div>
<div id="content-goal" style="display: block;">
<div class="lang-switch-group">
<label class="modal-label">${g('language')}</label>
<div class="lang-switch">
<button class="lang-btn ${l === 'en' ? 'active' : ''}" id="lang-en-btn">${g('english')}</button>
<button class="lang-btn ${l === 'cn' ? 'active' : ''}" id="lang-cn-btn">${g('chinese')}</button>
</div>
</div>
<div class="modal-input-group">
<label class="modal-label">${g('goalContent')}</label>
<input type="text" id="goal-content-input" class="modal-input" placeholder="${g('goalContent')}">
</div>
<div class="modal-input-group">
<label class="modal-label">${g('currentProgress')}</label>
<input type="number" id="goal-current-input" class="modal-input" placeholder="0" min="0" value="0">
</div>
<div class="modal-input-group">
<label class="modal-label">${g('targetGoal')}</label>
<input type="number" id="goal-target-input" class="modal-input" placeholder="100" min="1" required>
</div>
<div class="modal-input-group">
<label class="modal-label">${g('progressBarColor')}</label>
<input type="color" id="goal-color-input" class="modal-input" value="${t.primary}">
</div>
<div class="modal-btn-group">
<button id="save-goal-btn" class="goal-btn">${g('saveGoal')}</button>
<button id="cancel-btn" class="goal-btn">${g('cancel')}</button>
</div>
</div>
<div id="content-appearance" style="display: none;">
<div class="appearance-group">
<label class="modal-label">${g('darkMode')}</label>
<div class="toggle-group">
<button class="toggle-btn ${d ? 'active' : ''}" id="dark-mode-on">${g('english') === 'English' ? 'On' : '开启'}</button>
<button class="toggle-btn ${!d ? 'active' : ''}" id="dark-mode-off">${g('english') === 'English' ? 'Off' : '关闭'}</button>
</div>
</div>
<div class="appearance-group">
<label class="modal-label">${g('enableAnimation')}</label>
<div class="toggle-group">
<button class="toggle-btn ${a ? 'active' : ''}" id="anim-on">${g('english') === 'English' ? 'On' : '开启'}</button>
<button class="toggle-btn ${!a ? 'active' : ''}" id="anim-off">${g('english') === 'English' ? 'Off' : '关闭'}</button>
</div>
</div>
<div class="theme-group">
<label class="modal-label">${g('customTheme')}</label>
<div class="color-group">
<div style="flex: 1;">
<label class="modal-label" style="font-size: 12px;">${g('primaryColor')}</label>
<input type="color" class="color-input" id="primary-color" value="${t.primary}">
</div>
<div style="flex: 1;">
<label class="modal-label" style="font-size: 12px;">${g('secondaryColor')}</label>
<input type="color" class="color-input" id="secondary-color" value="${t.secondary}">
</div>
<div style="flex: 1;">
<label class="modal-label" style="font-size: 12px;">${g('completedColor')}</label>
<input type="color" class="color-input" id="completed-color" value="${t.completed}">
</div>
</div>
</div>
<div class="modal-btn-group">
<button id="save-theme-btn" class="goal-btn">${g('saveTheme')}</button>
<button id="cancel-theme-btn" class="goal-btn">${g('cancel')}</button>
</div>
</div>
`;
document.getElementById('tab-goal').onclick = () => {
document.getElementById('tab-goal').classList.add('active');
document.getElementById('tab-appearance').classList.remove('active');
document.getElementById('content-goal').style.display = 'block';
document.getElementById('content-appearance').style.display = 'none';
};
document.getElementById('tab-appearance').onclick = () => {
document.getElementById('tab-appearance').classList.add('active');
document.getElementById('tab-goal').classList.remove('active');
document.getElementById('content-goal').style.display = 'none';
document.getElementById('content-appearance').style.display = 'block';
};
document.getElementById('lang-en-btn').onclick = () => {
l = 'en';
e();
rs();
u();
r();
};
document.getElementById('lang-cn-btn').onclick = () => {
l = 'cn';
e();
rs();
u();
r();
};
document.getElementById('dark-mode-on').onclick = () => {
d = true;
e();
u();
rs();
r();
};
document.getElementById('dark-mode-off').onclick = () => {
d = false;
e();
u();
rs();
r();
};
document.getElementById('anim-on').onclick = () => {
a = true;
e();
u();
rs();
r();
};
document.getElementById('anim-off').onclick = () => {
a = false;
e();
u();
rs();
r();
};
document.getElementById('save-theme-btn').onclick = () => {
t = {
primary: document.getElementById('primary-color').value,
secondary: document.getElementById('secondary-color').value,
completed: document.getElementById('completed-color').value
};
e();
u();
r();
mo.style.display = 'none';
ov.classList.remove('show');
};
document.getElementById('cancel-theme-btn').onclick = () => {
mo.style.display = 'none';
ov.classList.remove('show');
};
document.getElementById('save-goal-btn').onclick = () => {
const c = document.getElementById('goal-content-input').value.trim();
const cu = parseInt(document.getElementById('goal-current-input').value) || 0;
const ta = parseInt(document.getElementById('goal-target-input').value);
const co = document.getElementById('goal-color-input').value;
if (!c) {
alert(g('enterContent'));
return;
}
if (!ta || ta < 1) {
alert(g('targetValid'));
return;
}
x.push({
content: c,
current: Math.max(0, cu),
target: ta,
color: co
});
s();
r();
mo.style.display = 'none';
ov.classList.remove('show');
document.getElementById('goal-content-input').value = '';
document.getElementById('goal-current-input').value = '0';
document.getElementById('goal-target-input').value = '';
document.getElementById('goal-color-input').value = t.primary;
};
document.getElementById('cancel-btn').onclick = () => {
mo.style.display = 'none';
ov.classList.remove('show');
};
};
const dr = (el) => {
let dg = false;
let sx, sy;
let il, it;
const gp = () => {
const rc = el.getBoundingClientRect();
return { left: rc.left, top: rc.top };
};
el.addEventListener('mousedown', (e) => {
if (e.target.classList.contains('goal-btn') || e.target.tagName === 'INPUT') return;
dg = true;
sx = e.clientX;
sy = e.clientY;
const p = gp();
il = p.left;
it = p.top;
el.style.opacity = '1';
el.style.zIndex = '1000000';
el.style.cursor = 'grabbing';
e.preventDefault();
});
document.addEventListener('mousemove', (e) => {
if (!dg) return;
const dx = e.clientX - sx;
const dy = e.clientY - sy;
const nl = il + dx;
const nt = it + dy;
const vw = window.innerWidth;
const vh = window.innerHeight;
const ew = el.offsetWidth;
const eh = el.offsetHeight;
const cl = Math.max(0, Math.min(nl, vw - ew));
const ct = Math.max(0, Math.min(nt, vh - eh));
el.style.left = `${cl}px`;
el.style.top = `${ct}px`;
el.style.bottom = 'auto';
el.style.right = 'auto';
el.style.transform = 'none';
}, { passive: true });
document.addEventListener('mouseup', () => {
if (!dg) return;
dg = false;
el.style.zIndex = '999999';
el.style.cursor = 'move';
const rc = el.getBoundingClientRect();
const fp = {
left: `${rc.left}px`,
top: `${rc.top}px`,
bottom: 'auto',
right: 'auto'
};
y = fp;
p(fp);
});
document.addEventListener('mouseleave', () => {
if (dg) {
dg = false;
el.style.zIndex = '999999';
el.style.cursor = 'move';
}
});
};
const inp = () => {
if (document.readyState === 'complete' && !document.getElementById('goal-tracker-container')) {
cr();
}
};
if (document.readyState === 'complete') {
inp();
} else {
let lb = false;
if (!lb) {
window.addEventListener('load', inp, { once: true });
lb = true;
}
}
})();剪贴板
剪贴板 clw16iou
剪贴板信息
剪贴板信息
- 收录
- 更新