// ==UserScript== // @name 【秋风于渭水】博客网站留言评论信息自动填充 // @namespace https://www.tjsky.net // @version 1.0.0 // @description 博客网站留言评论自动填写个人信息方法 // @author 去年夏天 // @include http://*/* // @include https://*/* // @exclude *://*/wp-admin/* // @exclude *://*/admin/* // @exclude *://*.aliyun.com/* // @exclude *://myssl.com* // @exclude *://*.alipay.com/* // @exclude *://*.taobao.com/* // @exclude *://*.alimama.com/* // @exclude *://*.tmall.com/* // @exclude *://*.qq.com/* // @exclude *://*.tencent.com/* // @exclude *://*.qcloud.com/* // @exclude *://*.tenpay.com/* // @exclude *://*.baidu.com/* // @exclude *://*.bing.com/* // @exclude *://*.iqiyi.com/* // @exclude *://*.jd.com/* // @exclude *://*.meituan.com/* // @exclude *://*.cloudflare.com/* // @exclude *://*.yundun.com/* // @exclude *://github.com/* // @exclude *://weibo.com/* // @exclude *://*.sina.com.cn/* // @exclude *://*.youku.com/* // @exclude *://*.bilibili.com/* // @exclude *://*.acfun.cn/* // @exclude *://douban.com/* // @exclude *://*.jd.com/* // @exclude *://*.huya.com/* // @exclude *://*.douyin.com/* // @exclude *://*.douyu.com/* // @exclude *://*.sohu.com/* // @exclude *://*.letv.com/* // @exclude *://*.toutiao.com/* // @exclude *://*.ixigua.com/* // @exclude *://*.kafan.cn/* // @exclude *://*.163.com/* // @exclude *://*.126.com/* // @exclude *://*.hupu.com/* // @exclude *://*.qidian.com/* // @exclude *://*.mi.com/* // @exclude *://*.360.cn/* // @exclude *://*.icbc.com.cn/* // @exclude *://*.ccb.com/* // @exclude *://*.abchina.com/* // @exclude *://*.cmbchina.com/* // @exclude *://*.boc.cn/* // @exclude *://*.bankcomm.com/* // @exclude *://*.psbc.com/* // @exclude *://*.pingan.com/* // @exclude *://*.citicbank.com/* // @exclude *://*.cib.com.cn/* // @exclude *://*.spdb.com.cn/* // @exclude *://*.cebbank.com/* // @exclude *://*.cmbc.com.cn/* // @exclude *://*.cgbchina.com.cn/* // @exclude *://*.unionpay.com/* // @exclude *://*.chinalife.com.cn/* // @exclude *://*.citi.com/* // @exclude *://*.hsbc.com/* // @exclude *://*.sc.com/* // @exclude *://*.google.com/* // @exclude *://*.google.hk/* // @exclude *://*.google.cn/* // @exclude *://*.apple.com/* // @exclude *://*.youtube.com/* // @exclude *://*.facebook.com/* // @exclude *://twitter.com/* // @exclude *://*.qianxin.com/* // @exclude *://*.mail-tester.com/* // @exclude *://*.openai.com/* // @exclude *://*.godaddy.com/* // @exclude *://*.lowendtalk.com/* // @exclude *://*.racknerd.com/* // @exclude *://*.colocrossing.com/* // @exclude *://*.namecheap.com/* // @exclude *://*.namesilo.com/* // @exclude *://*.expireddomains.net/* // @exclude *://*.mailu.io/* // @exclude *://*.amazon.cn/* // @exclude *://*.amazon.com/* // @exclude *://*.qiniu.com/* // @run-at document-end // @grant unsafeWindow // @grant GM_getValue // @grant GM_setValue // @grant GM_registerMenuCommand // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 默认配置值 const DEFAULT_CONFIG = { authorName: '请输入你的昵称', authorEmail: '请输入你的邮箱', authorUrl: '请输入你的网站(可留空)', autoFillEnabled: true, hotkey: 'Ctrl+Shift+F' }; // 初始化配置 function initConfig() { if (typeof GM_getValue === 'undefined') return; if (GM_getValue('authorName') === undefined) { GM_setValue('authorName', DEFAULT_CONFIG.authorName); } if (GM_getValue('authorEmail') === undefined) { GM_setValue('authorEmail', DEFAULT_CONFIG.authorEmail); } if (GM_getValue('authorUrl') === undefined) { GM_setValue('authorUrl', DEFAULT_CONFIG.authorUrl); } if (GM_getValue('autoFillEnabled') === undefined) { GM_setValue('autoFillEnabled', DEFAULT_CONFIG.autoFillEnabled); } if (GM_getValue('hotkey') === undefined) { GM_setValue('hotkey', DEFAULT_CONFIG.hotkey); } } // 注册菜单 function registerMenuCommands() { if (typeof GM_registerMenuCommand === 'undefined') return; GM_registerMenuCommand('设置昵称', () => { const currentName = GM_getValue('authorName', DEFAULT_CONFIG.authorName); const newName = prompt('请输入您的昵称:', currentName); if (newName !== null) { GM_setValue('authorName', newName); alert('昵称已更新!'); } }); GM_registerMenuCommand('设置邮箱', () => { const currentEmail = GM_getValue('authorEmail', DEFAULT_CONFIG.authorEmail); const newEmail = prompt('请输入您的邮箱:', currentEmail); if (newEmail !== null) { GM_setValue('authorEmail', newEmail); alert('邮箱已更新!'); } }); GM_registerMenuCommand('设置网址', () => { const currentUrl = GM_getValue('authorUrl', DEFAULT_CONFIG.authorUrl); const newUrl = prompt('请输入您的网址(可留空):', currentUrl); if (newUrl !== null) { GM_setValue('authorUrl', newUrl); alert('网址已更新!'); } }); GM_registerMenuCommand('切换自动填充状态', () => { const currentStatus = GM_getValue('autoFillEnabled', DEFAULT_CONFIG.autoFillEnabled); const newStatus = !currentStatus; GM_setValue('autoFillEnabled', newStatus); alert(`自动填充功能已${newStatus ? '开启' : '关闭'}!`); }); GM_registerMenuCommand('设置填充快捷键', () => { const currentHotkey = GM_getValue('hotkey', DEFAULT_CONFIG.hotkey); const newHotkey = prompt('请输入新的快捷键组合(例如:Ctrl+Shift+F):', currentHotkey); if (newHotkey !== null && newHotkey.trim() !== '') { GM_setValue('hotkey', newHotkey); setupHotkeyListener(); alert(`快捷键已更新为:${newHotkey}`); } }); } // 快捷键监听 function setupHotkeyListener() { if (window.dr_gm_hotkeyHandler) { document.removeEventListener('keydown', window.dr_gm_hotkeyHandler); } const hotkey = GM_getValue('hotkey', DEFAULT_CONFIG.hotkey); const keys = hotkey.split('+').map(k => k.trim().toLowerCase()); window.dr_gm_hotkeyHandler = function(event) { const pressed = []; if (event.ctrlKey) pressed.push('ctrl'); if (event.shiftKey) pressed.push('shift'); if (event.altKey) pressed.push('alt'); if (event.metaKey) pressed.push('meta'); if (event.key.length === 1) { pressed.push(event.key.toLowerCase()); } else if (event.key.startsWith('F') && event.key.length > 1) { pressed.push(event.key.toLowerCase()); } // 检查是否匹配快捷键 const match = keys.length === pressed.length && keys.every(k => pressed.includes(k)); if (match) { event.preventDefault(); manualFill(); } }; document.addEventListener('keydown', window.dr_gm_hotkeyHandler); } // 手动触发填充 function manualFill() { const result = dr_js_autofill_commentinfos(); if (!result) { alert('未找到可填充的评论表单!'); } } // 填充三要素 function dr_js_autofill_commentinfos() { const authorName = GM_getValue('authorName', DEFAULT_CONFIG.authorName); const authorEmail = GM_getValue('authorEmail', DEFAULT_CONFIG.authorEmail); const authorUrl = GM_getValue('authorUrl', DEFAULT_CONFIG.authorUrl); var lauthor = ["input#author","input[name='comname']","input#inpName","input[name='author']","input#ds-dialog-name","input#name","input[name='name']","input[name='nick']","input#comment_author", ".comment-form input[placeholder='昵称(必填)']","input.atk-name"], lmail =["input#mail","input#email","input[name='commail']","input#inpEmail","input[name='email']","input#ds-dialog-email","input[name='mail']","input#comment_email", ".comment-form input[type='email']","input.atk-email"], lurl =["input#url","input[name='comurl']","input#inpHomePage","input#ds-dialog-url","input[name='url']","input[name='website']","input#website","input[name='link']","input#comment_url", ".comment-form input[type='url']","input.atk-link"]; let filled = false; for (var i = 0; i < lauthor.length; i++) { var author = document.querySelector(lauthor[i]); if (author != null) { author.value = authorName; author.dispatchEvent(new Event('input')); author.dispatchEvent(new Event('change')); filled = true; break; } } for (var j = 0; j < lmail.length; j++) { var mail = document.querySelector(lmail[j]); if (mail != null) { mail.value = authorEmail; mail.dispatchEvent(new Event('input')); mail.dispatchEvent(new Event('change')); filled = true; break; } } for (var k = 0; k < lurl.length; k++) { var url = document.querySelector(lurl[k]); if (url != null) { url.value = authorUrl; url.dispatchEvent(new Event('input')); url.dispatchEvent(new Event('change')); filled = true; break; } } return filled; } // init function dr_init(){ var filled = false; var obj = dr_get_type(); const dr_gm_debug = false; if ( dr_gm_debug ) { console.log( '【秋风于渭水】GM脚本填充评论信息:', obj ); } if( obj && obj.fill ){ filled = dr_js_autofill_commentinfos(); } console.log( '【秋风于渭水】GM脚本填充评论信息'+( filled?'成功':'失败' )+':', obj ? obj.type : '未知类型' ); } // 判断评论程序类型函数 function dr_get_type(){ if( dr_is_wordpress() ){ return { type: 'WordPress', fill: true }; }else if( dr_is_typecho() ){ return { type: 'Typecho', fill: true }; }else if( dr_is_zblog() ){ return { type: 'ZBlog', fill: true }; }else if( dr_is_emlog() ){ return { type: 'Emlog', fill: true }; }else if( dr_is_twikoojs() ){ return { type: 'TwikooJS', fill: true }; }else if( dr_is_artalkjs() ){ return { type: 'ArtalkJS', fill: true }; }else if( dr_is_valinejs() ){ return { type: 'ValineJS', fill: true }; }else if( dr_is_walinejs() ){ return { type: 'WalineJS', fill: true }; }else{ return { type: '未知', fill: false }; } } // 检测评论程序函数 function dr_is_wordpress(){ return document.querySelector('#commentform') !== null || document.querySelector('#wp-comment-list') !== null || document.querySelector('input#comment_post_ID') !== null; } function dr_is_typecho(){ return document.querySelector('form#comment-form') !== null || document.querySelector('input[name=_]') !== null; } function dr_is_zblog() { return document.querySelector('form#frmSumbit') !== null || document.querySelector('div.commentpost') !== null; } function dr_is_emlog() { return document.querySelector('form#commentform') !== null || document.querySelector('input#comment') !== null; } function dr_is_twikoojs() { return document.querySelector('div.twikoo') !== null || document.querySelector('div#twikoo') !== null; } function dr_is_artalkjs() { return document.querySelector('div#Artalk') !== null || document.querySelector('div.artalk') !== null; } function dr_is_valinejs() { return document.querySelector('div#valine') !== null || document.querySelector('div.v[data-class=v]') !== null; } function dr_is_walinejs() { return document.querySelector('div#waline') !== null || document.querySelector('div.wl-comment') !== null; } // 初始化 function init() { initConfig(); registerMenuCommands(); setupHotkeyListener(); // 仅在自动填充开启时执行自动填充 const autoFillEnabled = GM_getValue('autoFillEnabled', DEFAULT_CONFIG.autoFillEnabled); if (autoFillEnabled) { // 缺失必填项不执行脚本 const authorName = GM_getValue('authorName', DEFAULT_CONFIG.authorName); const authorEmail = GM_getValue('authorEmail', DEFAULT_CONFIG.authorEmail); if (authorName === '' || authorEmail === '') { console.log('【秋风于渭水】评论信息不完整,自动填充未执行'); return; } if (window.top !== window.self) { return; } setTimeout(dr_init, 1500); } } init(); })();