您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
15/02/2023, 20:13:58
当前为
// ==UserScript== // @name yomichan lookup history // @namespace Violentmonkey Scripts // @match *://*/* // @grant none // @grant GM_getValue // @grant GM_setValue // @version 3.0 // @license MIT // @author grumpythomas // @description 15/02/2023, 20:13:58 // ==/UserScript== const dbKey = 'yomichan-lookup-history'; const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; (function () { let data = getData() || initData(); const host = window.location.host; if (host.indexOf('localhost') > -1 || host.indexOf('therealgrumpythomas') > -1) { let hydrateInterval = window.setInterval(() => { if (unsafeWindow.hydrate) { unsafeWindow.hydrate(data); unsafeWindow.clearInterval(hydrateInterval); } }, 100); } document.addEventListener('selectionchange', debounce(() => { if (!window.getSelection) { return; } const selectedText = window.getSelection()?.toString()?.trim(); if (!selectedText?.length) { return; } data = insertRow(data, selectedText, document.title); }, 1500)); })(); function initData() { return { created: Date.now(), lookups: [], sources: [] }; } function getData() { const rawData = GM_getValue(dbKey); if (!rawData) { return; } rawData.sources = rawData.sources || []; return JSON.parse(rawData); } function insertRow(data, lookup, source) { const dbLookup = { text: lookup, created: Date.now(), timezone }; let dbSourceId = data.sources.findIndex(s => s.label === source); if (dbSourceId === -1) { dbSourceId = data.sources.push({ label: source }) } dbLookup.sourceId = dbSourceId; data.lookups.push(dbLookup); GM_setValue(dbKey, JSON.stringify(data)); return data; } function debounce(func, timeout) { let timer; return (...args) => { clearTimeout(timer); timer = setTimeout(() => { func.apply(this, args); }, timeout); }; }