From 7b1972b4db5b1b7dee2ee7f12b1f0c276411c9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=BD=E5=9F=B9=E8=80=85?= Date: Fri, 16 Aug 2019 09:58:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=8D=E5=AD=90=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=A1=B5=E2=80=9C=E6=8B=96=E6=94=BE=E4=B8=8B=E8=BD=BD=E5=88=B0?= =?UTF-8?q?=E2=80=9D=E5=8A=9F=E8=83=BD=E5=A2=9E=E5=8A=A0=E5=AF=B9=E9=9D=9E?= =?UTF-8?q?NexusPHP=E7=AB=99=E7=82=B9=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/schemas/NexusPHP/common.js | 105 +++++++++----------------- resource/schemas/NexusPHP/torrents.js | 38 ++++++++++ src/content/index.ts | 12 ++- 3 files changed, 86 insertions(+), 69 deletions(-) diff --git a/resource/schemas/NexusPHP/common.js b/resource/schemas/NexusPHP/common.js index b3b05115e..4b3d7f874 100644 --- a/resource/schemas/NexusPHP/common.js +++ b/resource/schemas/NexusPHP/common.js @@ -120,23 +120,21 @@ String.prototype.getQueryString = function(name, split) { } this.showAllContentMenus(event.originalEvent, success, error); }, - onDrop: this.isNexusPHP() - ? (data, event, success, error) => { - console.log(data); - let url = this.getDroperURL(data.url); - console.log(url); - this.showContentMenusForUrl( - { - url, - title: data.title, - link: data.url - }, - event.originalEvent, - success, - error - ); - } - : undefined + onDrop: (data, event, success, error) => { + console.log(data); + let url = this.getDroperURL(data.url); + console.log(url); + this.showContentMenusForUrl( + { + url, + title: data.title, + link: data.url + }, + event.originalEvent, + success, + error + ); + } }); // 复制下载链接 @@ -165,24 +163,22 @@ String.prototype.getQueryString = function(name, split) { error(); }); }, - onDrop: this.isNexusPHP() - ? (data, event, success, error) => { - if (checkPasskey && !PTService.site.passkey) { - error(this.t("needPasskey")); - return; - } - let url = this.getDroperURL(data.url); - url && - PTService.call(PTService.action.copyTextToClipboard, url) - .then(result => { - console.log("命令执行完成", result); - success(); - }) - .catch(() => { - error(); - }); - } - : undefined + onDrop: (data, event, success, error) => { + if (checkPasskey && !PTService.site.passkey) { + error(this.t("needPasskey")); + return; + } + let url = this.getDroperURL(data.url); + url && + PTService.call(PTService.action.copyTextToClipboard, url) + .then(result => { + console.log("命令执行完成", result); + success(); + }) + .catch(() => { + error(); + }); + } }); // 检查是否有下载管理权限 @@ -432,40 +428,13 @@ String.prototype.getQueryString = function(name, split) { siteURL += "/"; } - if (PTService.site.schema == "NexusPHP") { - if (!url.getQueryString) { - PTService.showNotice({ - msg: - "系统依赖函数(getQueryString)未正确加载,请尝试刷新页面或重新启用插件。" - }); - return null; - } - - if (url.indexOf("download.php") == -1) { - let id = url.getQueryString("id"); - if (id) { - // 如果站点没有配置禁用https,则默认添加https链接 - url = - siteURL + - "download.php?id=" + - id + - (PTService.site.passkey - ? "&passkey=" + PTService.site.passkey - : "") + - (PTService.site.disableHttps ? "" : "&https=1"); - } else { - url = ""; - } - } - } else { - if (url && url.substr(0, 2) === "//") { - url = `${location.protocol}://${url}`; - } else if (url && url.substr(0, 4) !== "http") { - if (url.substr(0, 1) == "/") { - url = url.substr(1); - } - url = `${siteURL}${url}`; + if (url && url.substr(0, 2) === "//") { + url = `${location.protocol}${url}`; + } else if (url && url.substr(0, 4) !== "http") { + if (url.substr(0, 1) == "/") { + url = url.substr(1); } + url = `${siteURL}${url}`; } return url; diff --git a/resource/schemas/NexusPHP/torrents.js b/resource/schemas/NexusPHP/torrents.js index d7738a44d..b721d77e0 100644 --- a/resource/schemas/NexusPHP/torrents.js +++ b/resource/schemas/NexusPHP/torrents.js @@ -72,6 +72,44 @@ ) ); } + + /** + * 获取有效的拖放地址 + * @param {*} url + */ + getDroperURL(url) { + let siteURL = PTService.site.url; + if (siteURL.substr(-1) != "/") { + siteURL += "/"; + } + + if (!url.getQueryString) { + PTService.showNotice({ + msg: + "系统依赖函数(getQueryString)未正确加载,请尝试刷新页面或重新启用插件。" + }); + return null; + } + + if (url.indexOf("download.php") === -1) { + let id = url.getQueryString("id"); + if (id) { + // 如果站点没有配置禁用https,则默认添加https链接 + url = + siteURL + + "download.php?id=" + + id + + (PTService.site.passkey + ? "&passkey=" + PTService.site.passkey + : "") + + (PTService.site.disableHttps ? "" : "&https=1"); + } else { + url = ""; + } + } + + return url; + } } new App().init(); })(jQuery); diff --git a/src/content/index.ts b/src/content/index.ts index 92e99537c..34633e7c5 100644 --- a/src/content/index.ts +++ b/src/content/index.ts @@ -771,7 +771,17 @@ class PTPContent { if (data && data.url) { onDrop.call(this, data, e, onSuccess, onError); } - } catch (error) {} + } catch (error) { + // 错误时,尝试直接使用文本内容 + let data = e.originalEvent.dataTransfer.getData("text/plain"); + if (data) { + data = { + url: data + }; + + onDrop.call(this, data, e, onSuccess, onError); + } + } }); // 离开拖放时