// ==UserScript== // @name dmhy-torrent-auto-rename // @name:zh-CN 动漫花园种子自动重命名 // @description auto rename torrent for dmhy // @description:zh-CN 自动将动漫花园的会员专用链接所指向的文件文件名改为标题名 // @match *://dmhy.org/topics/view/* // @match *://www.dmhy.org/topics/view/* // @match *://share.dmhy.org/topics/view/* // @author 菜姬 // @version 0.3 // @namespace https://greasyfork.org/users/171607 // @grant GM_xmlhttpRequest // @connect dmhy.org // @license GPL version 3 // @encoding utf-8 // @downloadURL none // ==/UserScript== (function () { let urlblock = document.querySelector('#tabs-1 > p:nth-child(1) > a'); let url = urlblock.getAttribute('href'); let filename = urlblock.innerHTML + ".torrent"; urlblock.onclick = (e) => { e.preventDefault(); GM_xmlhttpRequest({ method: "get", url: url, responseType: "blob", onload: function (r) { let blob = new Blob([r.response]); const anchor = document.createElement("a"); anchor.href = URL.createObjectURL(blob); anchor.download = filename; anchor.style["display"] = "none"; document.body.append(anchor); anchor.click(); setTimeout(() => { document.body.removeChild(anchor); URL.revokeObjectURL(anchor.href); }, 0); } }); }; })();