qBittorrent Web UI clipboard support

Adds ctrl+v support to qBittorrent's Web UI, if a magnet link is in your clipboard it automatically adds the torrent.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         qBittorrent Web UI clipboard support
// @name:zh-TW   qBittorrent Web UI 剪貼簿支援
// @namespace    https://github.com/axzxc1236/
// @version      0.1
// @description  Adds ctrl+v support to qBittorrent's Web UI, if a magnet link is in your clipboard it automatically adds the torrent.
// @description:zh-tw  對qBittorrent的Web UI新增了貼上(ctrl+v)的支援,如果腳本在你的剪貼簿偵測到磁力連結,會自動新增種子
// @author       axzxc1236
// @match        https://127.0.0.1:8080/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    navigator.permissions.query({
        name: 'clipboard-read'
    }).then(permissionStatus => {
        // Will be 'granted', 'denied' or 'prompt':
        if (permissionStatus.state == "denied") {
            alert("Clipboard permission is denied, this script will not work until you change that");
        }
    });
    document.addEventListener('paste', function(data) {
        var text = data.clipboardData.getData("text");
        if (text.startsWith("magnet:?xt=")) {
            document.getElementById('downloadButton').click();
            document.getElementById("downloadPage_iframe").contentDocument.body.onload = function() {
                this.document.body.getElementById("urls").innerText = text;
                this.document.body.getElementById("submitButton").click();
            };
        }
    });
})();