获取所有磁力链地址
// ==UserScript==
// @name 获取所有磁力链地址
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.2.2
// @description try to take over the world!
// @author sjbwylbs
// #@require-css https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.1/css/bootstrap.min.css
// #@require-css https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css
// @match *://*.ai66.cc/*
// @match *://*.66s6.net/*
// @match *://*.xb6v.com/*
// #@match https://*
// @run-at document-end
// ==/UserScript==
(function () {
'use strict';
let container;
var domHead = document.getElementsByTagName('head')[0];
var domStyle = document.createElement('style');
// domStyle.type = 'text/css';
domStyle.rel = 'stylesheet';
function initStyle() {
let css = `
.fixed-btn {
position: fixed;
text-align: right;
right: 0;
bottom: 44%;
width: 44px;
z-index: 1040;
cursor: pointer;
}
.modal {
--bs-modal-width: '';
}
`
var domBootstrapStyle = document.createElement('link');
domBootstrapStyle.rel = 'stylesheet';
domBootstrapStyle.href = 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css';
domBootstrapStyle.integrity = 'sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN';
domBootstrapStyle.crossOrigin = 'anonymous';
var domBootstrapIconStyle = document.createElement('link');
domBootstrapIconStyle.rel = 'stylesheet';
domBootstrapIconStyle.href = 'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css';
var domBootstrapScript = document.createElement('script');
domBootstrapScript.src = 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js';
domBootstrapScript.integrity = 'sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL';
domBootstrapScript.crossOrigin = 'anonymous';
domHead.appendChild(domBootstrapStyle);
domHead.appendChild(domBootstrapIconStyle);
domStyle.appendChild(document.createTextNode(css));
domHead.appendChild(domStyle);
domHead.appendChild(domBootstrapScript);
}
function invert() {
const unchecks = container.querySelectorAll("[type=checkbox]:not(:checked)");
const checks = container.querySelectorAll("[type=checkbox]:checked");
unchecks.forEach(t => t.checked = true);
checks.forEach(t => t.checked = false);
}
function all() {
const alls = container.querySelectorAll("[type=checkbox]");
alls.forEach(t => t.checked = true);
}
function copyToClipboard(textToCopy) {
console.log(textToCopy);
// navigator clipboard 需要https等安全上下文
if (navigator.clipboard && window.isSecureContext) {
// navigator clipboard 向剪贴板写文本
return navigator.clipboard.writeText(textToCopy);
} else {
// 创建text area
let textArea = document.createElement("textarea");
textArea.value = textToCopy;
// 使text area不在viewport,同时设置不可见
textArea.style.position = "absolute";
textArea.style.opacity = 0;
textArea.style.left = "-999999px";
textArea.style.top = "-999999px";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
return new Promise((res, rej) => {
// 执行复制命令并移除文本框
document.execCommand('copy') ? res() : rej();
textArea.remove();
});
}
}
function copy() {
const checks = container.querySelectorAll("[type=checkbox]:checked");
if (checks.length) {
let s = "";
checks.forEach(t => {
s += t.dataset.url + '\n\r';
});
copyToClipboard(s).then(()=> alert("复制成功"), () => alert("复制失败"));
} else {
alert("没有选择!");
}
}
const fixedButton = () => `
嗅探
`
const model = (content) => `
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">嗅探结果如下:请选择复制</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
${content}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" id="selectAll">全选</button>
<button type="button" class="btn btn-secondary" id="invertSelect">反选</button>
<button type="button" class="btn btn-danger" id="copySelect">复制</button>
</div>
</div>
</div>`;
let template = (index, content, url) =>
`<input id="mg${index}" class="form-check-input" type="checkbox" value="${content}" data-url="${url}"/><label for="mg${index}" class="form-check-label">${content}</label>`
function initLinks() {
const links = document.querySelectorAll('a[href^=magnet],a[href^=ed2k]')
let s = '';
if (links.length) {
links.forEach((t, i) => {
s += template(i, t.textContent, t.href);
});
container = document.createElement('div');
container.className = "modal fade";
container.id = "SNIFFERS_ROOT";
container.innerHTML = model(s);
container.dataset.bsBackdrop = 'static';
container.dataset.bsKeyboard = true;
document.body.appendChild(container);
document.querySelector('#selectAll').addEventListener('click', all);
document.querySelector('#invertSelect').addEventListener('click', invert);
document.querySelector('#copySelect').addEventListener('click', copy);
}
}
function init() {
const snifferBtn = document.createElement('div');
snifferBtn.className = 'btn btn-primary fixed-btn';
snifferBtn.dataset.bsToggle="modal";
snifferBtn.dataset.bsTarget="#SNIFFERS_ROOT"
snifferBtn.innerHTML = fixedButton();
document.body.appendChild(snifferBtn);
}
initStyle();
init();
initLinks();
})();