Greasy Fork is available in English.
连续按两次 'd' 触发生成 Is.gd 直连短链,自动跳过输入框
// ==UserScript==
// @name 一键生成直连短链 (快捷键 dd 版)
// @namespace https://github.com/
// @version 4.0
// @description 连续按两次 'd' 触发生成 Is.gd 直连短链,自动跳过输入框
// @author Gemini
// @match *://*/*
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
// @connect is.gd
// ==/UserScript==
(function() {
'use strict';
let isProcessing = false;
let lastKeyTime = 0;
const DOUBLE_PRESS_DELAY = 400; // 两次按键的最大间隔(毫秒)
async function convertAndCopy() {
if (isProcessing) return;
isProcessing = true;
showStatus('⌛ 正在生成...');
const apiUrl = `https://is.gd/create.php?format=simple&url=${encodeURIComponent(window.location.href)}`;
GM_xmlhttpRequest({
method: 'GET',
url: apiUrl,
onload: function(response) {
if (response.status === 200) {
const shortUrl = response.responseText.trim();
GM_setClipboard(shortUrl);
showStatus('✅ 短链已复制: ' + shortUrl);
} else {
showStatus('❌ 失败: ' + response.status);
}
isProcessing = false;
},
onerror: () => {
showStatus('🌐 网络异常 (大陆部分地区受限)');
isProcessing = false;
}
});
}
// 状态提示逻辑
function showStatus(msg) {
let tip = document.getElementById('isgd-status-tip');
if (!tip) {
tip = document.createElement('div');
tip.id = 'isgd-status-tip';
tip.style.cssText = 'position:fixed;top:20px;left:50%;transform:translateX(-50%);background:#333;color:white;padding:10px 20px;border-radius:20px;z-index:2147483647;font-size:13px;box-shadow:0 4px 12px rgba(0,0,0,0.3);transition: opacity 0.3s;';
document.body.appendChild(tip);
}
tip.innerText = msg;
tip.style.opacity = '1';
// 自动隐藏逻辑
clearTimeout(window.isgdTimer);
window.isgdTimer = setTimeout(() => {
tip.style.opacity = '0';
setTimeout(() => tip.remove(), 300);
}, 2500);
}
// 键盘监听逻辑
window.addEventListener('keydown', function(e) {
// 1. 冲突回避:如果焦点在输入框或可编辑区域,则不触发
const activeElem = document.activeElement;
const isInput = activeElem.tagName === 'INPUT' ||
activeElem.tagName === 'TEXTAREA' ||
activeElem.isContentEditable;
if (isInput) return;
// 2. 序列匹配:识别 "dd"
if (e.key.toLowerCase() === 'd') {
const currentTime = new Date().getTime();
if (currentTime - lastKeyTime < DOUBLE_PRESS_DELAY) {
// 成功触发
convertAndCopy();
lastKeyTime = 0; // 重置计数
} else {
lastKeyTime = currentTime;
}
} else {
lastKeyTime = 0; // 按了其他键,重置序列
}
});
})();