← Back to Skills Marketplace
534422530

剪贴板历史

by 534422530 · GitHub ↗ · v1.1.0 · MIT-0
cross-platform ✓ Security Clean
27
Downloads
0
Stars
0
Active Installs
2
Versions
Install in OpenClaw
/install laosi-clipboard-history
Description
剪贴板历史 - 自动保存复制内容,最多50条历史,可搜索可恢复。再也不丢复制过的东西
README (SKILL.md)

Clipboard History - 剪贴板历史

激活词: 剪贴板 / 复制历史 / clipboard

有什么用

复制-粘贴是最高频的操作之一。但 Windows 的剪贴板只能存一个。这个技能自动保存每次复制的内容,可以随时找回。

Python 实现

import os
import json
import time
from datetime import datetime

CLIPBOARD_FILE = os.path.join(os.path.dirname(__file__), "clipboard_history.json")

class ClipboardHistory:
    MAX_ITEMS = 50
    
    def __init__(self):
        os.makedirs(os.path.dirname(CLIPBOARD_FILE), exist_ok=True)
        self.history = self._load()
    
    def _load(self):
        if os.path.exists(CLIPBOARD_FILE):
            try:
                with open(CLIPBOARD_FILE, encoding="utf-8") as f:
                    return json.load(f)
            except (json.JSONDecodeError, ValueError):
                return []
        return []
    
    def _save(self):
        with open(CLIPBOARD_FILE, "w", encoding="utf-8") as f:
            json.dump(self.history, f, ensure_ascii=False, indent=2)
    
    def save(self, text: str) -> dict:
        """保存一条剪贴板记录(去重)"""
        if not text or not text.strip():
            return {"saved": False, "reason": "empty"}
        
        # 去重:不保存和上一条相同的
        if self.history and self.history[0]["text"] == text.strip()[:200]:
            return {"saved": False, "reason": "duplicate"}
        
        entry = {
            "text": text.strip()[:200],
            "length": len(text.strip()),
            "time": datetime.now().isoformat(),
            "timestamp": time.time()
        }
        self.history.insert(0, entry)
        if len(self.history) > self.MAX_ITEMS:
            self.history = self.history[:self.MAX_ITEMS]
        self._save()
        return {"saved": True, "index": 0, "count": len(self.history)}
    
    def get(self, index: int = 0) -> str:
        """取指定位置的剪贴板历史"""
        if 0 \x3C= index \x3C len(self.history):
            return self.history[index]["text"]
        return ""
    
    def search(self, keyword: str) -> list:
        """搜索历史中的内容"""
        results = []
        for i, entry in enumerate(self.history):
            if keyword.lower() in entry["text"].lower():
                results.append({"index": i, "text": entry["text"], "time": entry["time"]})
        return results
    
    def clear(self):
        """清空历史"""
        self.history = []
        self._save()
    
    def stats(self) -> dict:
        """统计信息"""
        if not self.history:
            return {"total": 0}
        return {
            "total": len(self.history),
            "oldest": self.history[-1]["time"],
            "newest": self.history[0]["time"],
            "total_chars": sum(e["length"] for e in self.history)
        }

# 使用示例
ch = ClipboardHistory()

# 模拟复制操作
ch.save("Python 3.12 新增了类型参数语法")
ch.save("FlashAttention 实现了2-4x加速")
ch.save("https://github.com/anomalyco/opencode")

# 搜索
results = ch.search("python")
for r in results:
    print(f"[{r['index']}] {r['text']}")

# 取最新一条
latest = ch.get(0)
print(f"最新: {latest}")

# 统计
print(f"共 {ch.stats()['total']} 条历史")

监控模式(自动保存)

import pyperclip
import time

def auto_watch(interval: float = 1.0):
    """轮询剪贴板,自动保存新内容"""
    ch = ClipboardHistory()
    last = ""
    print("剪贴板监控已启动(按 Ctrl+C 停止)")
    try:
        while True:
            try:
                current = pyperclip.paste()
                if current and current != last:
                    result = ch.save(current)
                    if result["saved"]:
                        print(f"  保存: {current[:40]}...")
                    last = current
            except Exception:
                pass
            time.sleep(interval)
    except KeyboardInterrupt:
        print("\
监控已停止")

# 启动监控
# auto_watch()

数据格式

[
  {
    "text": "FlashAttention 实现了2-4x加速",
    "length": 20,
    "time": "2026-05-28T10:30:00",
    "timestamp": 1748392200.0
  }
]

使用场景

  1. 编程: 复制了一段代码忘了存,回来还能找回
  2. 写作: 不同段落之间切换,之前复制的引用还在
  3. 研究: 搜集资料时多次切换复制源,不丢失
  4. 办公: 不同文档间复制粘贴,随时回溯

依赖

  • Python 3.8+
  • pyperclip (可选,用于自动监控模式)
Usage Guidance
Install only if you are comfortable with clipboard snippets being saved locally. Do not enable the monitoring sample unless you explicitly want continuous clipboard polling, and clear or avoid using it around passwords, tokens, personal data, or confidential work.
Capability Assessment
Purpose & Capability
The skill's stated purpose is to save, search, and restore clipboard history, and the included code does exactly that with a 50-item limit and 200-character stored text snippets.
Instruction Scope
The activation phrases are broad and the sample includes an optional polling monitor, so agents and users should treat clipboard reading or monitoring as an explicit user-directed action.
Install Mechanism
The artifact contains only SKILL.md; metadata shows no executable scripts, no declared dependency packages, and clean static/dependency scans.
Credentials
The behavior is local file I/O plus optional clipboard polling, with no network access, credential use, obfuscation, destructive action, or unrelated system access.
Persistence & Privilege
Clipboard entries are persisted to a local clipboard_history.json file in the skill directory, which is expected for the purpose but may contain sensitive copied text.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install laosi-clipboard-history
  3. After installation, invoke the skill by name or use /laosi-clipboard-history
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.1.0
- Added detailed usage instructions, implementation code, and usage scenarios to documentation. - Included Python sample code for saving, searching, and restoring clipboard history. - Described data format and explained auto-monitoring with pyperclip. - Expanded explanation of benefits and practical use cases. - Added dependency requirements section.
v1.0.0
Clipboard History v1.0.0 - 自动保存每次复制内容,最多记录50条历史 - 支持查看、搜索、恢复剪贴板历史 - 剪贴板数据本地保存(D:\coze-local\data\clipboard_history.json),无需联网 - 提高内容复制效率,防止内容丢失
Metadata
Slug laosi-clipboard-history
Version 1.1.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 2
Frequently Asked Questions

What is 剪贴板历史?

剪贴板历史 - 自动保存复制内容,最多50条历史,可搜索可恢复。再也不丢复制过的东西. It is an AI Agent Skill for Claude Code / OpenClaw, with 27 downloads so far.

How do I install 剪贴板历史?

Run "/install laosi-clipboard-history" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is 剪贴板历史 free?

Yes, 剪贴板历史 is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does 剪贴板历史 support?

剪贴板历史 is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created 剪贴板历史?

It is built and maintained by 534422530 (@534422530); the current version is v1.1.0.

💬 Comments