// ==UserScript== // @name 滴答清单 解锁日历视图 v10 // @namespace https://dida365.com/ // @version 10.0 // @match https://dida365.com/* // @match https://*.dida365.com/* // @match https://ticktick.com/* // @match https://*.ticktick.com/* // @run-at document-start // @grant none // @description 解锁滴答清单网页版 Pro 日历视图 // @license MIT // ==/UserScript== (function () { 'use strict'; console.log('%c[解锁日历] v10 已就位', 'color:#e91e63;font-weight:bold'); // 进入本文件时是否就落在日历路由(=直接刷新进入),用于判断要不要复刻跳转 const INITIAL_CAL = /#c\/all\/calendar/.test(location.hash); // ---- 1. 数据层解锁:只碰 user 接口,不再全量重建 Response ---- function unlockText(t) { if (typeof t !== 'string') return t; return t .replace(/"pro"\s*:\s*false/g, '"pro":true') .replace(/"teamPro"\s*:\s*false/g, '"teamPro":true') .replace(/"isPro"\s*:\s*false/g, '"isPro":true') .replace(/"proType"\s*:\s*\d+/g, '"proType":1') .replace(/"userType"\s*:\s*\d+/g, '"userType":1') .replace(/"proEndDate"\s*:\s*"[^"]*"/g, '"proEndDate":"2099-12-31T23:59:59.000+0000"') .replace(/"needSubscribe"\s*:\s*true/g, '"needSubscribe":false'); } // 只拦用户相关接口,日历取任务的请求不碰,避免拖慢首帧 const HIT = /\/api\/v\d\/user\/(status|profile)/i; const P = XMLHttpRequest.prototype, oOpen = P.open; P.open = function (m, u) { this.__u = u; return oOpen.apply(this, arguments); }; const rt = Object.getOwnPropertyDescriptor(P, 'responseText'); if (rt && rt.get) Object.defineProperty(P, 'responseText', { configurable: true, get: function () { const v = rt.get.call(this); try { return (this.__u && HIT.test(this.__u)) ? unlockText(v) : v; } catch (e) { return v; } }}); const rp = Object.getOwnPropertyDescriptor(P, 'response'); if (rp && rp.get) Object.defineProperty(P, 'response', { configurable: true, get: function () { const v = rp.get.call(this); try { if (this.__u && HIT.test(this.__u)) { if (typeof v === 'string') return unlockText(v); if (v && typeof v === 'object') { const s = JSON.stringify(v), ns = unlockText(s); if (ns !== s) return JSON.parse(ns); } } } catch (e) {} return v; }}); const of = window.fetch; if (of) window.fetch = async function (...a) { const r = await of.apply(this, a); try { const u = typeof a[0] === 'string' ? a[0] : (a[0] && a[0].url) || ''; if (HIT.test(u) && r && r.ok) { const t = await r.clone().text(); const nv = unlockText(t); if (nv !== t) { const h = new Headers(r.headers); h.delete('content-length'); h.delete('content-encoding'); return new Response(nv, { status: r.status, statusText: r.statusText, headers: h }); } } } catch (e) {} return r; }; // 注意:不再改写 localStorage 缓存(刷新时吃坏缓存正是错日期的来源之一) // ---- 2. 升级弹窗 + 幕布,整块 display:none ---- const UP_TEXT = /(立即升级|升级了解|解锁全部|会员专享|开通\s*Pro|试用结束)/i; function killUpgrade() { let n = 0; document.querySelectorAll('.upgrade-pop, .calendar-upgrade').forEach(el => { if (getComputedStyle(el).display !== 'none') { el.style.setProperty('display', 'none', 'important'); n++; } const cover = el.closest('.popup-cover'); if (cover && getComputedStyle(cover).display !== 'none') { cover.style.setProperty('display', 'none', 'important'); n++; } }); document.querySelectorAll('.popup-cover').forEach(c => { if (UP_TEXT.test(c.textContent || '') && getComputedStyle(c).display !== 'none') { c.style.setProperty('display', 'none', 'important'); n++; } }); if (n) console.log('%c[解锁日历] 已移除升级弹层 ' + n + ' 处', 'color:#4caf50'); } // ---- 3. 安全兜底:只收拾"空的纯遮挡",含可点元素/文字一律放过 ---- function clearStrayMask() { document.querySelectorAll('div').forEach(el => { try { const cs = el.classList; if (cs && (cs.contains('popup-cover') || cs.contains('popup') || cs.contains('upgrade-pop') || cs.contains('calendar-upgrade'))) return; if (el.querySelector('button,a,input,textarea,select,[role="button"],[contenteditable="true"]')) return; if ((el.textContent || '').trim().length > 0) return; const s = getComputedStyle(el), r = el.getBoundingClientRect(); if (s.position === 'fixed' && r.width > innerWidth * 0.9 && r.height > innerHeight * 0.9 && parseFloat(s.opacity) < 0.9 && s.pointerEvents !== 'none') { el.style.setProperty('pointer-events', 'none', 'important'); } } catch (e) {} }); } // ---- 4. 首帧补救:触发重排 + 点"今天" ---- function findTodayBtn() { const cand = document.querySelectorAll('button,a,[role="button"],[class*="today" i],[title*="今天"]'); for (const el of cand) { const txt = (el.textContent || '').trim(); const title = el.getAttribute('title') || el.getAttribute('aria-label') || ''; if (txt === '今天' || /今天/.test(title) || /today/i.test(el.className || '')) return el; } const deep = [...document.querySelectorAll('div,span')].filter(e => (e.textContent || '').trim() === '今天'); return deep.length ? deep[deep.length - 1] : null; } function nudgeRender() { try { window.dispatchEvent(new Event('resize')); } catch (e) {} document.querySelectorAll('[class*="scroll" i],[class*="calendar" i],[class*="view" i]').forEach(sc => { try { const o = sc.scrollTop; sc.scrollTop = o + 1; sc.scrollTop = o; sc.dispatchEvent(new WheelEvent('wheel', { deltaY: 1, bubbles: true })); } catch (e) {} }); } function clickToday() { const b = findTodayBtn(); if (b) { try { b.click(); return true; } catch (e) {} } return false; } // ---- 5. 直接刷新进入日历 → 复刻"从别的页点进来"的站内跳转 ---- let remounted = false; function remountIfDirectLoad() { if (!INITIAL_CAL || remounted) return; if (!/#c\/all\/calendar/.test(location.hash)) return; // 用户已自己离开就别动 remounted = true; const back = location.hash; let hop = ''; const links = [...document.querySelectorAll('a[href*="#c/"]')] .map(a => a.getAttribute('href')) .filter(h => h && !/calendar/.test(h)); hop = links[0] || '#c/all/tasks'; console.log('%c[解锁日历] 检测到直接刷新进入日历,复刻跳转: ' + hop + ' → ' + back, 'color:#2196f3'); location.hash = hop; setTimeout(() => { location.hash = back; setTimeout(() => { nudgeRender(); clickToday(); }, 600); }, 400); } function sweep() { killUpgrade(); clearStrayMask(); } window.fixCalendarClick = sweep; window.healCalendar = () => { nudgeRender(); clickToday(); }; function boot() { sweep(); try { fetch('/api/v2/user/status', { credentials: 'include' }); } catch (e) {} new MutationObserver(sweep).observe(document.documentElement, { childList: true, subtree: true }); let c = 0; const iv = setInterval(() => { sweep(); if (++c > 60) clearInterval(iv); }, 700); // 直接刷新兜底:先复刻跳转,再补几拍重排 if (INITIAL_CAL) { setTimeout(remountIfDirectLoad, 900); [1400, 2600, 4000].forEach(ms => setTimeout(() => { if (/#c\/all\/calendar/.test(location.hash)) { nudgeRender(); clickToday(); } }, ms)); window.addEventListener('wheel', () => nudgeRender(), { once: true, passive: true }); } } if (document.readyState === 'loading') window.addEventListener('DOMContentLoaded', boot); else boot(); })();