// ==UserScript== // @name X 用户备注 // @namespace https://github.com/SIXiaolong1117/Rules // @version 0.1 // @description 为 X 用户添加自定义备注 // @license MIT // @icon https://x.com/favicon.ico // @author SI Xiaolong // @match https://twitter.com/* // @match https://x.com/* // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @downloadURL https://update.greasyfork.icu/scripts/554605/X%20%E7%94%A8%E6%88%B7%E5%A4%87%E6%B3%A8.user.js // @updateURL https://update.greasyfork.icu/scripts/554605/X%20%E7%94%A8%E6%88%B7%E5%A4%87%E6%B3%A8.meta.js // ==/UserScript== (function() { 'use strict'; // 存储用户备注 const notes = {}; // 加载所有备注 function loadNotes() { const saved = GM_getValue('userNotes', '{}'); Object.assign(notes, JSON.parse(saved)); } // 保存备注 function saveNote(username, note) { if (note.trim()) { notes[username] = note; } else { delete notes[username]; } GM_setValue('userNotes', JSON.stringify(notes)); } // 创建备注元素 function createNoteElement(username, note) { const noteSpan = document.createElement('span'); noteSpan.className = 'user-note-custom'; noteSpan.style.cssText = ` margin-left: 6px; padding: 2px 8px; background: #1d9bf0; color: white; border-radius: 12px; font-size: 13px; font-weight: 500; cursor: pointer; `; noteSpan.textContent = note; noteSpan.title = '点击编辑备注'; noteSpan.addEventListener('click', (e) => { e.stopPropagation(); e.preventDefault(); showEditDialog(username, note); }); return noteSpan; } // 创建添加备注按钮 function createAddButton(username) { const btn = document.createElement('button'); btn.className = 'add-note-btn'; btn.style.cssText = ` margin-left: 6px; padding: 2px 8px; background: #eff3f4; color: #536471; border: none; border-radius: 12px; font-size: 13px; cursor: pointer; font-weight: 500; `; btn.textContent = '+ 备注'; btn.title = '添加备注'; btn.addEventListener('click', (e) => { e.stopPropagation(); e.preventDefault(); showEditDialog(username, ''); }); btn.addEventListener('mouseenter', () => { btn.style.background = '#e7e9ea'; }); btn.addEventListener('mouseleave', () => { btn.style.background = '#eff3f4'; }); return btn; } // 显示编辑对话框 function showEditDialog(username, currentNote) { const dialog = document.createElement('div'); dialog.style.cssText = ` position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 10000; `; const box = document.createElement('div'); box.style.cssText = ` background: white; padding: 24px; border-radius: 16px; width: 400px; max-width: 90%; `; box.innerHTML = `