@@ -178,40 +178,56 @@ const CodeDots = styled.div`
178178` ;
179179
180180const codeExample = `// ==UserScript==
181- // @name My Typescript UserScript
181+ // @name Typescript Userscript Template
182+ // @namespace https://github.com/JSREI/typescript-userscript-template
182183// @version 1.0.0
183- // @description A UserScript built with TypeScript
184+ // @description A modern userscript template using TypeScript
184185// @author Your Name
185- // @match https://example.com/*
186+ // @match *://*/*
187+ // @run-at document-start
188+ // @grant GM_getValue
189+ // @grant GM_setValue
190+ // @grant GM_xmlhttpRequest
186191// ==/UserScript==
187192
193+ import { storeData, retrieveData } from "./gm_api_utils";
194+
188195class MyUserScript {
189196 private config = {
190197 enableLogging: true,
191- theme: ' dark',
198+ theme: " dark"
192199 };
193200
194201 constructor() {
195202 this.initialize();
196203 }
197204
198- private initialize(): void {
199- console.log('UserScript initialized!');
205+ private async initialize(): Promise<void> {
206+ console.log("UserScript initialized!");
207+
208+ // 存储并获取上次运行时间
209+ await storeData("lastRun", new Date().toISOString());
210+ const lastRun = await retrieveData<string>("lastRun", "从未运行");
211+
212+ if (this.config.enableLogging) {
213+ console.log(\`上次运行时间: \${lastRun}\`);
214+ }
215+
200216 this.setupEventListeners();
201217 }
202218
203219 private setupEventListeners(): void {
204- document.addEventListener(' click' , this.handleClick);
220+ document.addEventListener(" click" , this.handleClick);
205221 }
206222
207223 private handleClick = (e: MouseEvent): void => {
208224 if (this.config.enableLogging) {
209- console.log(' Clicked:' , e.target);
225+ console.log(" Clicked:" , e.target);
210226 }
211227 };
212228}
213229
214- // Start the script
230+ // 启动脚本
215231new MyUserScript();` ;
216232
217233const Hero : React . FC = ( ) => {
0 commit comments