// ==UserScript==
// @name 博客网站留言评论信息自动填充
// @namespace https://www.tjsky.net
// @version 1.0.4
// @description 博客网站留言评论自动填写个人信息方法
// @author 去年夏天
// @namespace https://gf.qytechs.cn/zh-CN/users/39819
// @homepage https://gf.qytechs.cn/zh-CN/scripts/552004
// @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
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAXfSURBVFhHrVZtbFNVGG6YDMaHg8HWe2/DhzOaKBrAH0REohEjiSR+gQZj4k9/8A8NMYq6nxo3urW9Xdex0QkhsIWI+IOAG/symYKbbGy297Zbv7aVlX203UfXr9vHnNu1Xc/WDQZP8qa59573PM95znnfU4ViBZiejb4jSZJRkqQ+SZLuS5LUK0lS5VQ0foge+8TwZr37jVZ30OALx8wxSZrBIojFYjO+YPS/lsEgf+Ci63V6jpXh297D33f42lyzNN3SsM8AX7ePNytO9azQlY9bNuSesdXqzVF67kdCRW8YOWU2g+JYfR5NkRX5P94rzlXbe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yG2wTYRy65JTnSZMngixYqRWPJG4jY+dqRmfp52qGUy4kReSVWbDTYAPfNSFb+TAIhGKo+Gcc2yoTpZ1JLoKr8YDVWsyKhoac1I3I6cTjql/GM1QmRRRoRHkVu88NyBVCuuXwVASzUQmxeFz+JaXb5JzGN21evFQ7II8nrZ1eOSn5hNu291PkSbA683VZhC7twvzYXCHIE29UC7Irr5js2H/Bgb0mO3YYbHIrJ9/JZUPnphZU4wGjES7S3DKUpd1FTKV9kNzV2USQYHSJciWCyMVCfskzeU+PzQh9P7hqd5Qr695Lc6dQqO3dzRjdE8uJeOSY6zOc0QXO4LIoy+/upLlT4Mr79nBGtyN9JlYqZK6sazzgqgfBGRyk/YL8+2KrHANFlWIxzZ1C4c+3Ga7K+ZuqbgyJ6ngUIWliud552wVy6Fi+f5I7O5wWwQv9NO8CsIaBz1ijs5fULQm5Y867OzJCb5O/J8Z6wRhd3ZzB/klqLq1wgDO6A/KCtBZwRjcy2bKhpOQpxug8yhpdDayh36nUW4PkIiG3WSp0Ykx+r+93MJXOy6zR8YGipGQVPRWnsbzGVLkGOYMjruSt4/8DXeOz38W5+7UAAAAASUVORK5CYII=
// ==/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","input#nick","input[placeholder='昵称']","input[placeholder='名称']","input[placeholder='你的昵称']"],
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","input[placeholder='邮箱']","input[placeholder='你的邮箱']"],
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","input[placeholder='网址']","input[placeholder='你的网址']"];
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();
})();