Greasy Fork is available in English.
通过选中的文字快速打开百度网盘链接和提取码
当前为
// ==UserScript==
// @name 快速打开百度网盘分享链接
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 通过选中的文字快速打开百度网盘链接和提取码
// @author 蜻蜓
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var altKeyDown = false;
document.addEventListener('keydown', function(event) {
if (event.keyCode === 18) {
// Alt 键按下
altKeyDown = true;
} else if (event.keyCode === 86 && altKeyDown) {
// v 键按下且 Alt 键已按下
// 用户按下了 Alt+v 键
altKeyDown = false;
// 执行操作
let text = window.getSelection().toString();
if (text) {
let linkMatch = text.match(/\s*(https:\/\/pan\.baidu\.com\/s\/[a-zA-Z0-9-_]+)/);
let codeMatch = text.match(/\s*提取码:?\s*([a-zA-Z0-9]{4})/); // 确保“提取码”和代码匹配更加准确
if (linkMatch && codeMatch) {
let newUrl = `${linkMatch[1]}?pwd=${codeMatch[1]}`;
//window.open(newUrl, '_blank');
function openLinkInNewTab(url) {
var a = document.createElement('a');
a.href = url;
a.target = '_blank';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
openLinkInNewTab(newUrl)
} else {
console.log("无法解析链接或提取码,请确认选中的文本格式正确。");
}
}
}
});
document.addEventListener('keyup', function(event) {
if (event.keyCode === 18) {
// Alt 键松开
altKeyDown = false;
}
});
})();