← 返回 Skills 市场
534422530

剪贴板历史

作者 534422530 · GitHub ↗ · v1.1.0 · MIT-0
cross-platform ✓ 安全检测通过
27
总下载
0
收藏
0
当前安装
2
版本数
在 OpenClaw 中安装
/install laosi-clipboard-history
功能描述
剪贴板历史 - 自动保存复制内容,最多50条历史,可搜索可恢复。再也不丢复制过的东西
使用说明 (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 (可选,用于自动监控模式)
安全使用建议
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.
能力评估
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.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install laosi-clipboard-history
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /laosi-clipboard-history 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
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),无需联网 - 提高内容复制效率,防止内容丢失
元数据
Slug laosi-clipboard-history
版本 1.1.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 2
常见问题

剪贴板历史 是什么?

剪贴板历史 - 自动保存复制内容,最多50条历史,可搜索可恢复。再也不丢复制过的东西. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 27 次。

如何安装 剪贴板历史?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install laosi-clipboard-history」即可一键安装,无需额外配置。

剪贴板历史 是免费的吗?

是的,剪贴板历史 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

剪贴板历史 支持哪些平台?

剪贴板历史 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 剪贴板历史?

由 534422530(@534422530)开发并维护,当前版本 v1.1.0。

💬 留言讨论