// ==UserScript== // @name DMHY download helper // @name:zh-CN 动漫花园下载助手 // @description A userscript for share.dmhy.org. // @description:zh-CN 一个为动漫花园(share.dmhy.org)提供增强功能的用户脚本 // @author Xingwang Liao // @namespace https://github.com/kuoruan // @homepage https://github.com/kuoruan/dmhy-download-helper#readme // @supportURL https://github.com/kuoruan/dmhy-download-helper/issues // @match *://share.dmhy.org/ // @match *://share.dmhy.org/topics/list/* // @match *://share.dmhy.org/topics/list?* // @match *://share.dmhy.org/topics/view/* // @require https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js // @require https://cdn.jsdelivr.net/npm/xbytes@1.6.2/dist/index.min.js // @connect dmhy.org // @grant GM_setClipboard // @grant GM_xmlhttpRequest // @source https://github.com/kuoruan/dmhy-download-helper.git // @license MIT // @run-at document-end // @version 1.3.3 // @icon https://www.google.cn/s2/favicons?domain=share.dmhy.org // @downloadURL none // ==/UserScript== !function(Vue, XBytes) { "use strict"; Vue = Vue && Object.prototype.hasOwnProperty.call(Vue, "default") ? Vue.default : Vue; XBytes = XBytes && Object.prototype.hasOwnProperty.call(XBytes, "default") ? XBytes.default : XBytes; !function(css, ref) { void 0 === ref && (ref = {}); var insertAt = ref.insertAt; if (css && "undefined" != typeof document) { var head = document.head || document.getElementsByTagName("head")[0], style = document.createElement("style"); style.type = "text/css"; "top" === insertAt && head.firstChild ? head.insertBefore(style, head.firstChild) : head.appendChild(style); style.styleSheet ? style.styleSheet.cssText = css : style.appendChild(document.createTextNode(css)); } }("body{position:relative}#topic_list .even:hover,#topic_list .even:hover td,#topic_list .odd:hover,#topic_list .odd:hover td{background-color:#0eb9e7}"); var script = { name: "Toast", data: function() { return { text: "", show: !1, timer: 0 }; }, methods: { display: function(text) { if (this.timer) { window.clearTimeout(this.timer); this.timer = 0; } this.text = text; this.show = !0; var _self = this; this.timer = window.setTimeout((function() { _self.show = !1; _self.text = ""; _self.timer = 0; }), 3e3); } } }; function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) { if ("boolean" != typeof shadowMode) { createInjectorSSR = createInjector; createInjector = shadowMode; shadowMode = !1; } var hook, options = "function" == typeof script ? script.options : script; if (template && template.render) { options.render = template.render; options.staticRenderFns = template.staticRenderFns; options._compiled = !0; isFunctionalTemplate && (options.functional = !0); } scopeId && (options._scopeId = scopeId); if (moduleIdentifier) { hook = function(context) { (context = context || this.$vnode && this.$vnode.ssrContext || this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) || "undefined" == typeof __VUE_SSR_CONTEXT__ || (context = __VUE_SSR_CONTEXT__); style && style.call(this, createInjectorSSR(context)); context && context._registeredComponents && context._registeredComponents.add(moduleIdentifier); }; options._ssrRegister = hook; } else { style && (hook = shadowMode ? function(context) { style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot)); } : function(context) { style.call(this, createInjector(context)); }); } if (hook) { if (options.functional) { var originalRender = options.render; options.render = function(h, context) { hook.call(context); return originalRender(h, context); }; } else { var existing = options.beforeCreate; options.beforeCreate = existing ? [].concat(existing, hook) : [ hook ]; } } return script; } var HEAD, isOldIE = "undefined" != typeof navigator && /msie [6-9]\\b/.test(navigator.userAgent.toLowerCase()); function createInjector(context) { return function(id, style) { return function(id, css) { var group = isOldIE ? css.media || "default" : id, style = styles[group] || (styles[group] = { ids: new Set, styles: [] }); if (!style.ids.has(id)) { style.ids.add(id); var code = css.source; if (css.map) { code += "\n/*# sourceURL=" + css.map.sources[0] + " */"; code += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(unescape(encodeURIComponent(JSON.stringify(css.map)))) + " */"; } if (!style.element) { style.element = document.createElement("style"); style.element.type = "text/css"; css.media && style.element.setAttribute("media", css.media); void 0 === HEAD && (HEAD = document.head || document.getElementsByTagName("head")[0]); HEAD.appendChild(style.element); } if ("styleSheet" in style.element) { style.styles.push(code); style.element.styleSheet.cssText = style.styles.filter(Boolean).join("\n"); } else { var index = style.ids.size - 1, textNode = document.createTextNode(code), nodes = style.element.childNodes; nodes[index] && style.element.removeChild(nodes[index]); nodes.length ? style.element.insertBefore(textNode, nodes[index]) : style.element.appendChild(textNode); } } }(id, style); }; } var styles = {}; var __vue_component__ = normalizeComponent({ render: function() { var _h = this.$createElement, _c = this._self._c || _h; return _c("div", { staticClass: "toast", class: { show: this.show } }, [ _c("span", { staticClass: "text" }, [ this._v(this._s(this.text)) ]) ]); }, staticRenderFns: [] }, (function(inject) { inject && inject("data-v-53b58458_0", { source: ".toast[data-v-53b58458]{position:fixed;bottom:30px;left:50%;z-index:99;display:none;padding:10px 20px;border-radius:2px;background-color:#333;transform:translateX(-50%)}.toast.show[data-v-53b58458]{display:block;-webkit-animation:fadein-data-v-53b58458 .5s,fadeout-data-v-53b58458 .5s 2.5s;animation:fadein-data-v-53b58458 .5s,fadeout-data-v-53b58458 .5s 2.5s}.toast .text[data-v-53b58458]{color:#fff;font-size:14px;line-height:1.5}@-webkit-keyframes fadein-data-v-53b58458{0%{bottom:0;opacity:0}to{bottom:30px;opacity:1}}@keyframes fadein-data-v-53b58458{0%{bottom:0;opacity:0}to{bottom:30px;opacity:1}}@-webkit-keyframes fadeout-data-v-53b58458{0%{bottom:30px;opacity:1}to{bottom:0;opacity:0}}@keyframes fadeout-data-v-53b58458{0%{bottom:30px;opacity:1}to{bottom:0;opacity:0}}", map: void 0, media: void 0 }); }), script, "data-v-53b58458", !1, void 0, !1, createInjector, void 0, void 0); function _toConsumableArray(arr) { return function(arr) { if (Array.isArray(arr)) { return _arrayLikeToArray(arr); } }(arr) || function(iter) { if ("undefined" != typeof Symbol && Symbol.iterator in Object(iter)) { return Array.from(iter); } }(arr) || function(o, minLen) { if (!o) { return; } if ("string" == typeof o) { return _arrayLikeToArray(o, minLen); } var n = Object.prototype.toString.call(o).slice(8, -1); "Object" === n && o.constructor && (n = o.constructor.name); if ("Map" === n || "Set" === n) { return Array.from(o); } if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) { return _arrayLikeToArray(o, minLen); } }(arr) || function() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }(); } function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } var Videos = [ "mp4", "rmvb", "avi", "mkv", "wmv", "flv", "ts" ], Audios = [ "mp3", "ogg", "wma", "wav", "aac", "flac", "mka", "cue" ], Subtitles = [ "sub", "idx", "sup", "sst", "srt", "ssa", "ass", "tts" ], Images = [ "jpg", "jpeg", "png", "gif", "bmp", "pdf", "webp" ], Archives = [ "rar", "rar5", "zip", "7z", "tar", "gz", "xz" ], Documents = [ "txt", "log", "md", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "md5" ], __vue_component__$2 = normalizeComponent({ render: function() { var _vm = this, _h = _vm.$createElement, _c = _vm._self._c || _h; return _c("ul", { staticStyle: { padding: "0", margin: "0", "list-style": "none" } }, _vm._l(_vm.folders, (function(folder, index) { return _c("tree-item", _vm._b({ key: folder.key, attrs: { "is-last": index === _vm.folders.length - 1, expand: !0 } }, "tree-item", folder, !1)); })), 1); }, staticRenderFns: [] }, void 0, { name: "Tree", components: { TreeItem: normalizeComponent({ render: function() { var _vm = this, _h = _vm.$createElement, _c = _vm._self._c || _h; return _c("li", { staticClass: "tree-item", class: { collection: this.isFolder, last: this.isLast } }, [ _vm.isFolder ? _c("div", { staticClass: "hitarea", class: { "collapsable-hitarea": _vm.isOpen, "last-hitarea": _vm.isLast }, on: { click: _vm.toggle } }) : _vm._e(), _c("div", { class: [ "title", _vm.icon ], on: { click: function($event) { _vm.isFolder && _vm.toggle(); } } }, [ _c("h5", [ _vm._v(_vm._s(_vm.name)) ]), _c("span", { staticClass: "size" }, [ _vm._v(_vm._s(_vm.totalSize)) ]) ]), _vm.isFolder ? _c("ul", { directives: [ { name: "show", rawName: "v-show", value: _vm.isOpen, expression: "isOpen" } ] }, _vm._l(_vm.children, (function(child, index) { return _c("tree-item", _vm._b({ key: child.key, staticClass: "item", attrs: { "is-last": index === _vm.children.length - 1 } }, "tree-item", child, !1)); })), 1) : _vm._e() ]); }, staticRenderFns: [] }, (function(inject) { inject && inject("data-v-f25f0048_0", { source: 'li.tree-item[data-v-f25f0048]{margin:0;padding:2px 0 2px 16px;background:url(data:image/gif;base64,R0lGODlhEADwBvABAICAgAAAACH5BAUAAAEALAAAAAAQAPAGQAL/jI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC8fyTNf2jef6zvf+DwwKh8Si8YhMKpfMpvMJjUqn1Kr1is1qt9yu9wsOi8fksvmMTqvX7Lb7DY/L5/S6/Y7P6/f8vv8PGCg4SFhoeIiYqLjI2Oj4CBkpOUlZaXmJmam5ydnp+QkaKjpKWmp6ipqqusp6ATDxKhEbMQvxehuAq1D7wOvg2wDMILxAvAuLLJtMu2zb3Pv8Gx08PVxdfH2svM3M7ewNDS4tTk1ubY6Nrt3N/t0e/j4eXz5/Xp9+v+6+D88v708PoD2B+Ajq64fwX8KACwc2LPjwoMKJDL0YS3ARQcYD/xsNdMyVDWNIjSM5lvR4EqQ6kStJtjT5EmVMlflY1nR5E2ZOmTtpGrT5E2dQnUN5FvUZEWhSoUuJNjX6FClFh1MhVpVYMStVrVa5Yt0KtmvYr2LLkj2r9Gpar2vHtjX7Fi1TtXPZ1nV7F25euU7p9rX7F29gvYP5QvV7GHBiwYsJNzYsVXFkxpMdV4b8MXNKzTM59/R8FHRU0Ygvxz29F3Vh1Y9Zm04Ne3Xs1rNfy75NG7ft3Lx3+yYtGThl4ZaJY96MvHPyz8tDNx/9vLRx19NrV9d9vXf239GDdx/+vXj448rLMzfvHD109dLHU3dvHT52+drpc2fvHT94/eL5k/8/D2B6Aa43YHv+vXdgfAnOt2B9Dd5XYH4R7jdhfxX+J2CGBGpo4IUIeqggiAyK6CCJEHIoIYoUqmghixhuCGOHLn44Y4g1jnhjiTmeGGOKPa74Y4tBvijjkDQaaSOSOCqpI5M8Fgmlj1ECOaWQVRIpZZZUamkll1huCWaXYX4pZplknnnklWl6ueaYbZr5JppJqjknm3W6eSececq5JJ192vknnoHqOSifTfp5KKCJCroooY0a+qSikTI6qaOVQrpdpvZp+iCnJnq6I6hOioropXGeuieqhar6KKumpgrrqrG2Ouurst5KK6625srrrr6SKimwlAprKbGYbopsp8knfrpsqM2O+mypxro6ba3V6nptr9n+Gm2w3Q77bbHhHqtsuczicksBADs=) 0 0 no-repeat}li.tree-item.collection[data-v-f25f0048]{background-position:0 -176px}li.tree-item.last[data-v-f25f0048]{background-position:0 -1766px}li.tree-item .hitarea[data-v-f25f0048]{float:left;margin-left:-16px;width:16px;height:16px;background:url(data:image/gif;base64,R0lGODlhYACFAPACAAAAAICAgCH5BAUAAAIALAAAAABgAIUAAAL/lI+py+0PBZjA0Yiz3qjyD4aaJ5amSZ7qyrbuGsSy/NZmsOD2/unS4eMJIz5ScIhk4CgTAe6ZjCKKQKl1ejBet0dDdzucicHkstl5Tqul37X7fWrDUfNkqlqPXCzNPOjOIeeXNVhoeAgmNoNY8iXICOEIGSI52SPBhAZliVHJqeH52ZkjCqoYU5pq9aja+sLqGqsCqwoo+2BLW7fXwOtqCyoKfEtcbFx3inqMl6BbSuW1zKwljcZUAeU8CY1Wza39GXqcDF5tfo6ero4xXN3OmdnbF/u+nGtef3y/zu+UbC7O2DeAhKJ5w3Qh27iC3aQNPKignCVy/SpavCgtnzGNWsU4IvK1AGStih5vlcSIMhZFiM0IRnTZ8uA1TQ2JBSx20yYpb/9S+vwJdNBJeiSJiewwL6griUohMW06aKXDnVNfssQiM5NCgVSX5bz1VZZUqGTLmj2LNu2tAgA7) -48px -47px no-repeat;cursor:pointer}li.tree-item .hitarea.last-hitarea[data-v-f25f0048]{background-color:#fff;background-position:-32px -69px}li.tree-item .hitarea.collapsable-hitarea[data-v-f25f0048]{background-position:-16px -91px}li.tree-item .hitarea.collapsable-hitarea.last-hitarea[data-v-f25f0048]{background-position:0 -113px}li.tree-item .title[data-v-f25f0048]{position:relative;display:flex;flex-direction:row;box-sizing:border-box;padding-left:18px;width:100%;height:16px;line-height:16px}li.tree-item .title h5[data-v-f25f0048]{flex:1 1 0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:400;font-size:12px}li.tree-item .title[data-v-f25f0048]:before{position:absolute;top:0;left:0;display:block;width:16px;height:16px;background-color:#fff;background-repeat:no-repeat;content:""}li.tree-item .title.folder-close[data-v-f25f0048]:before{background-image:url(data:image/gif;base64,R0lGODdhEAAOAPIHAK1zLeC6eP/insOHNP/////Sg59oJJdaHywAAAAAEAAOAEADM0i63AoiygnYkCWEwXkzYCg6RDeQyzWtB3MUcCy3aL1Ud33qDLRSDINsWDC4AMQYzUZKAAA7)}li.tree-item .title.folder-open[data-v-f25f0048]:before{background-image:url(data:image/gif;base64,R0lGODlhEAAOAIIAAZdaH+C6eP/inq1zLf/////Sg59oJMOHNCwAAAAAEAAOAAIDN0i63P7vyAPXYBcewUsIk8RQFalsXKoCmDq8cEwMKa2mxWUUOe//GUDvB1wABsQiw8BsOitQQgIAOw==)}li.tree-item .title.document[data-v-f25f0048]:before{background-image:url(data:image/gif;base64,R0lGODdhDwAOAPIHANS9fIy3oamMQX98XzmJdP////9tcGpsYiwAAAAADwAOAEADOlgl3KxQjWJMGefIKGi1UAdNUUQqYgQAKVoE8KQtZgHAAUFsYWm3rtKKxfH1jsbWybdclpqDqHSqSAAAOw==)}li.tree-item .title.video[data-v-f25f0048]:before{background-image:url(https://share.dmhy.org/images/icon/mkv.gif)}li.tree-item .title.audio[data-v-f25f0048]:before{background-image:url(https://share.dmhy.org/images/icon/mp3.gif)}li.tree-item .title.image[data-v-f25f0048]:before{background-image:url(https://share.dmhy.org/images/icon/jpg.gif)}li.tree-item .title.archive[data-v-f25f0048]:before{background-image:url(https://share.dmhy.org/images/icon/rar.gif)}li.tree-item .title.subtitle[data-v-f25f0048]:before{background-image:url(https://share.dmhy.org/images/icon/txt.gif)}li.tree-item .title.unknown[data-v-f25f0048]:before{background-image:url(https://share.dmhy.org/images/icon/unknown.gif)}li.tree-item .title .size[data-v-f25f0048]{display:block;flex:0;color:grey;white-space:nowrap}li.tree-item:nth-child(2n)>.title[data-v-f25f0048]{background-color:#cdf}li.tree-item::nth-child(odd)>.title[data-v-f25f0048]{background-color:#fff}li.tree-item ul[data-v-f25f0048]{margin:4px 0 0;padding:0;list-style:none}', map: void 0, media: void 0 }); }), { name: "TreeItem", props: { key: { type: Number, default: -1 }, parentKey: { type: Number, default: -1 }, name: { type: String, default: "" }, level: { type: Number, default: 1 }, size: { type: Number, default: 0 }, children: { type: Array, default: function() { return []; } }, isLast: { type: Boolean, default: !1 }, expand: { type: Boolean, default: !1 } }, data: function() { return { isOpen: this.expand }; }, computed: { isFolder: function() { return this.children && this.children.length > 0; }, totalSize: function() { var sum; if (this.size > 0) { sum = this.size; } else { sum = this.sizeListWithItem({ size: this.size, children: this.children }).reduce((function(a, b) { return a + b; }), 0); } return XBytes(sum, { iec: !0, fixed: 1 }); }, icon: function() { if (this.isFolder) { return this.isOpen ? "folder-open" : "folder-close"; } var ext = this.name.split(".").pop().toLowerCase(); switch (!0) { case Videos.indexOf(ext) > -1: return "video"; case Images.indexOf(ext) > -1: return "image"; case Archives.indexOf(ext) > -1: return "archive"; case Audios.indexOf(ext) > -1: return "audio"; case Documents.indexOf(ext) > -1: return "document"; case Subtitles.indexOf(ext) > -1: return "subtitle"; default: return "unknown"; } } }, methods: { toggle: function() { this.isOpen = !this.isOpen; }, sizeListWithItem: function(item) { var children = item.children; if (!children || children.length <= 0) { return item.size ? [ item.size ] : []; } for (var list = [], i = 0, len = children.length; i < len; i++) { var cList = this.sizeListWithItem(children[i]); list.push.apply(list, _toConsumableArray(cList)); } return list; } } }, "data-v-f25f0048", !1, void 0, !1, createInjector, void 0, void 0) }, props: { folders: { type: Array, default: function() { return []; } } } }, void 0, !1, void 0, !1, void 0, void 0, void 0); function magnetLinksWithOptions(magnetLinks, opts) { return !magnetLinks || magnetLinks.length <= 0 ? [] : opts.clean ? magnetLinks.map((function(l) { return l.substring(0, l.indexOf("&")); })) : _toConsumableArray(magnetLinks); } function getDefaultLinebreak() { var linebreak = "\n"; navigator.userAgent.indexOf("Windows") > -1 && (linebreak = "\r\n"); return linebreak; } function hashCode(str) { var hash = 0; if (!str || str.length <= 0) { return hash; } for (var i = 0, len = str.length; i < len; i++) { hash = (hash << 5) - hash + str.charCodeAt(i); hash |= 0; } return hash; } var TreeVM = Vue.extend(__vue_component__$2); var __vue_component__$3 = normalizeComponent({ render: function() { var _h = this.$createElement; this._self._c; return this._m(0); }, staticRenderFns: [ function() { var _h = this.$createElement, _c = this._self._c || _h; return _c("th", { staticClass: "{sorter: false}", attrs: { width: "5%", nowrap: "nowrap" } }, [ _c("span", { staticClass: "title" }, [ this._v("Torrent") ]) ]); } ] }, void 0, { name: "TorrentDownloadHeader" }, void 0, !1, void 0, !1, void 0, void 0, void 0), __vue_component__$4 = normalizeComponent({ render: function() { var _h = this.$createElement, _c = this._self._c || _h; return _c("td", { attrs: { nowrap: "nowrap", align: "center" } }, [ _c("a", { staticClass: "download-arrow arrow-torrent", attrs: { title: "Torrent 下载", href: "javascript:void(0);", "data-index": this.index }, on: { click: this.getAndDownloadTorrent } }) ]); }, staticRenderFns: [] }, void 0, { name: "TorrentDownloadItem", props: { index: { type: Number, default: 0 }, detailLink: { type: String, default: "" }, title: { type: String, default: "" } }, methods: { getAndDownloadTorrent: function() { if (this.detailLink) { var _self = this; GM_xmlhttpRequest({ method: "GET", url: this.detailLink, timeout: 5e3, context: { title: this.title }, ontimeout: function() { _self.$toast.display("下载超时,请重试!"); }, onerror: function() { _self.$toast.display("下载失败,请重试!"); }, onload: function(_ref) { var matches, _ref$context = _ref.context, _ref$context$title = (_ref$context = void 0 === _ref$context ? {} : _ref$context).title, title = void 0 === _ref$context$title ? "" : _ref$context$title, _ref$responseText = _ref.responseText, responseText = void 0 === _ref$responseText ? "" : _ref$responseText; responseText && (matches = responseText.match(/(.+)?<\/a>/)) && matches.length >= 3 ? _self.downloadTorrent(matches[1], "".concat(matches[2] || title, ".torrent")) : _self.$toast.display("获取下载链接失败!"); } }); } else { this.$toast.display("无法获取下载链接。"); } }, downloadTorrent: function(url, name) { var _self = this; GM_xmlhttpRequest({ method: "GET", url: url, responseType: "blob", timeout: 5e3, onerror: function() { _self.$toast.display("下载失败,请重试!"); }, ontimeout: function() { _self.$toast.display("下载超时,请重试!"); }, onload: function(_ref2) { var response = _ref2.response, b = new Blob([ response ], { type: "application/octet-stream" }), herf = URL.createObjectURL(b), anchor = document.createElement("a"); anchor.href = herf; anchor.style.display = "none"; anchor.download = name; _self.$el.appendChild(anchor); anchor.click(); setTimeout((function() { _self.$el.removeChild(anchor); URL.revokeObjectURL(herf); }), 0); } }); } } }, void 0, !1, void 0, !1, void 0, void 0, void 0), __vue_component__$5 = normalizeComponent({ render: function() { var _vm = this, _h = _vm.$createElement, _c = _vm._self._c || _h; return _c("th", { staticClass: "header", attrs: { width: "40" } }, [ _c("input", { directives: [ { name: "model", rawName: "v-model", value: _vm.checked, expression: "checked" } ], staticClass: "select-all", attrs: { type: "checkbox" }, domProps: { checked: Array.isArray(_vm.checked) ? _vm._i(_vm.checked, null) > -1 : _vm.checked }, on: { change: [ function($event) { var $$a = _vm.checked, $$el = $event.target, $$c = !!$$el.checked; if (Array.isArray($$a)) { var $$i = _vm._i($$a, null); $$el.checked ? $$i < 0 && (_vm.checked = $$a.concat([ null ])) : $$i > -1 && (_vm.checked = $$a.slice(0, $$i).concat($$a.slice($$i + 1))); } else { _vm.checked = $$c; } }, function($event) { return _vm.$emit("change", $event.target.checked); } ] } }) ]); }, staticRenderFns: [] }, (function(inject) { inject && inject("data-v-4272d513_0", { source: ".header[data-v-4272d513]{cursor:default}.header .select-all[data-v-4272d513]{width:14px;height:14px}.header .title[data-v-4272d513]{margin-left:5px}", map: void 0, media: void 0 }); }), { name: "CheckboxHeader", data: function() { return { checked: !1 }; } }, "data-v-4272d513", !1, void 0, !1, createInjector, void 0, void 0), __vue_component__$6 = normalizeComponent({ render: function() { var _vm = this, _h = _vm.$createElement, _c = _vm._self._c || _h; return _c("td", { attrs: { width: "40" } }, [ _c("input", { directives: [ { name: "model", rawName: "v-model", value: _vm.checked, expression: "checked" } ], staticClass: "select", attrs: { type: "checkbox", "data-index": _vm.index }, domProps: { checked: Array.isArray(_vm.checked) ? _vm._i(_vm.checked, null) > -1 : _vm.checked }, on: { change: [ function($event) { var $$a = _vm.checked, $$el = $event.target, $$c = !!$$el.checked; if (Array.isArray($$a)) { var $$i = _vm._i($$a, null); $$el.checked ? $$i < 0 && (_vm.checked = $$a.concat([ null ])) : $$i > -1 && (_vm.checked = $$a.slice(0, $$i).concat($$a.slice($$i + 1))); } else { _vm.checked = $$c; } }, function($event) { return _vm.$emit("change", $event.target.checked); } ] } }) ]); }, staticRenderFns: [] }, (function(inject) { inject && inject("data-v-383d9aff_0", { source: ".select[data-v-383d9aff]{width:14px;height:14px}", map: void 0, media: void 0 }); }), { name: "CheckboxItem", props: { index: { type: Number, default: 0 }, magnet: { type: String, default: "" } }, data: function() { return { checked: !1 }; } }, "data-v-383d9aff", !1, void 0, !1, createInjector, void 0, void 0), __vue_component__$8 = normalizeComponent({ render: function() { var _vm = this, _h = _vm.$createElement, _c = _vm._self._c || _h; return _c("popup", { attrs: { "z-index": _vm.zIndex, middle: !1, "margin-top": 100 }, on: { "overlay-click": function($event) { return _vm.$emit("close"); } } }, [ _c("div", { staticClass: "popup-header" }, [ _c("h4", [ _vm._v("查看链接") ]), _c("button", { staticClass: "btn", on: { click: function($event) { return _vm.$emit("close"); } } }, [ _vm._v("关闭") ]) ]), _c("div", { staticClass: "popup-body" }, [ _c("textarea", { directives: [ { name: "model", rawName: "v-model", value: _vm.content, expression: "content" } ], ref: "textarea", staticClass: "links-box", style: _vm.textStyle, attrs: { rows: "10", cols: "80" }, domProps: { value: _vm.content }, on: { input: function($event) { $event.target.composing || (_vm.content = $event.target.value); } } }) ]), _c("div", { staticClass: "popup-footer" }, [ _c("button", { staticClass: "btn", on: { click: _vm.resetContent } }, [ _vm._v("重置") ]), _c("button", { staticClass: "btn", on: { click: _vm.selectAll } }, [ _vm._v("全选") ]), _c("button", { staticClass: "btn", on: { click: _vm.copySelected } }, [ _vm._v("复制选中") ]), _c("button", { staticClass: "btn", on: { click: _vm.copyAll } }, [ _vm._v("复制全部") ]), _c("p", [ _vm._v("共 " + _vm._s(_vm.links.length) + " 条链接") ]) ]) ]); }, staticRenderFns: [] }, (function(inject) { inject && inject("data-v-f0078772_0", { source: ".btn[data-v-f0078772]{padding:2px 5px;outline:0;border:1px solid #247;background-color:#fff;color:#247}.popup-header[data-v-f0078772]{display:flex;flex-direction:row;align-items:center;padding:5px;background-color:#247}.popup-header h4[data-v-f0078772]{flex:1 1 0;color:#fff;text-align:left;font-weight:400;font-size:14px;line-height:1.5}.popup-body[data-v-f0078772]{padding:5px;background-color:#fff}.popup-body .links-box[data-v-f0078772]{overflow:auto;padding:4px 8px;border:1px solid #247;background-color:#eef;background-image:none;color:#333;font-size:12px;line-height:1.5;resize:none;cursor:text}.popup-footer[data-v-f0078772]{display:flex;flex-direction:row;align-items:center;padding:5px;background-color:#cdf}.popup-footer .btn[data-v-f0078772]:not(:first-child){margin-left:10px}.popup-footer p[data-v-f0078772]{flex:1 1 0;margin:0;text-align:right}", map: void 0, media: void 0 }); }), { name: "LinksPopup", components: { Popup: normalizeComponent({ render: function() { var _vm = this, _h = _vm.$createElement, _c = _vm._self._c || _h; return _c("div", { staticClass: "overlay", style: { "z-index": _vm.zIndex }, on: { click: function($event) { return $event.target !== $event.currentTarget ? null : _vm.$emit("overlay-click"); }, touchmove: _vm.onScroll, mousewheel: _vm.onScroll } }, [ _c("div", { staticClass: "popup", class: { middle: _vm.middle }, style: { "margin-top": _vm.marginTop + "px" } }, [ _vm._t("default") ], 2) ]); }, staticRenderFns: [] }, (function(inject) { inject && inject("data-v-5e817f6c_0", { source: '.overlay[data-v-5e817f6c]{position:fixed;top:0;right:0;bottom:0;left:0;background-color:rgba(0,0,0,.3);text-align:center}.overlay[data-v-5e817f6c]:after{display:inline-block;width:0;height:100%;content:"";vertical-align:middle}.overlay .popup[data-v-5e817f6c]{display:inline-block;overflow:hidden;padding:2px;border:1px solid #247;background-color:#fff;box-shadow:0 2px 12px 0 rgba(0,0,0,.1);text-align:left;-webkit-backface-visibility:hidden;backface-visibility:hidden}.overlay .popup.middle[data-v-5e817f6c]{vertical-align:middle}', map: void 0, media: void 0 }); }), { name: "Popup", props: { zIndex: { type: Number, default: 10 }, middle: { type: Boolean, default: !1 }, marginTop: { type: Number, default: 0 } }, methods: { onScroll: function(evt) { var el = evt.target, _window$getComputedSt = window.getComputedStyle(el), overflow = _window$getComputedSt.overflow, overflowY = _window$getComputedSt.overflowY, overflowX = _window$getComputedSt.overflowX, scrollTop = el.scrollTop, scrollHeight = el.scrollHeight, clientHeight = el.clientHeight, isAutoOrScroll = /(auto|scroll)/.test(overflow + overflowX + overflowY), scroll = 0 === scrollTop && evt.deltaY < 0 || Math.abs(scrollTop - (scrollHeight - clientHeight)) <= 1 && evt.deltaY > 0; isAutoOrScroll && !scroll || evt.preventDefault(); } } }, "data-v-5e817f6c", !1, void 0, !1, createInjector, void 0, void 0) }, props: { zIndex: { type: Number, default: 10 }, links: { type: Array, default: function() { return []; } }, options: { type: Object, default: function() { return { separator: getDefaultLinebreak() }; } } }, data: function() { return { content: "" }; }, computed: { textStyle: function() { return [ "\n", "\r\n" ].indexOf(this.options.separator) > -1 && this.links.length > 1 ? { "white-space": "nowrap", "word-break": "normal" } : { "white-space": "pre-line", "word-break": "break-all" }; } }, watch: { links: function() { this.resetContent(); } }, created: function() { this.resetContent(); }, methods: { resetContent: function() { this.content = this.links.join(this.options.separator); }, copySelected: function() { var target = this.$refs.textarea; if (target) { var start = target.selectionStart, finish = target.selectionEnd; if (start < 0 || finish <= start) { this.$toast.display("所选内容为空!"); return; } try { var text = this.content.substring(start, finish); GM_setClipboard(text, "{ type: 'text', mimetype: 'text/plain'}"); this.$toast.display("复制成功!"); } catch (e) { this.$toast.display("复制失败。"); } } else { this.$toast.display("获取文本框失败!"); } }, copyAll: function() { if (this.content) { try { GM_setClipboard(this.content, "{ type: 'text', mimetype: 'text/plain'}"); this.$toast.display("复制成功!"); } catch (e) { this.$toast.display("复制失败。"); } } else { this.$toast.display("文本框内容为空!"); } }, selectAll: function() { var target = this.$refs.textarea; target ? target.select() : this.$toast.display("获取文本框失败!"); } } }, "data-v-f0078772", !1, void 0, !1, createInjector, void 0, void 0), __vue_component__$9 = normalizeComponent({ render: function() { var _vm = this, _h = _vm.$createElement, _c = _vm._self._c || _h; return _c("div", { staticClass: "tool-bar", class: [ _vm.position, { visible: _vm.visible } ] }, [ _c("div", { staticClass: "wrapper" }, [ _c("span", { staticClass: "title" }, [ _vm._v("下载助手") ]), _c("label", { attrs: { for: "clean-" + _vm.position } }, [ _vm._v("清理链接:") ]), _c("input", { directives: [ { name: "model", rawName: "v-model", value: _vm.opts.clean, expression: "opts.clean" } ], staticClass: "checkbox", attrs: { id: "clean-" + _vm.position, type: "checkbox" }, domProps: { checked: Array.isArray(_vm.opts.clean) ? _vm._i(_vm.opts.clean, null) > -1 : _vm.opts.clean }, on: { change: function($event) { var $$a = _vm.opts.clean, $$el = $event.target, $$c = !!$$el.checked; if (Array.isArray($$a)) { var $$i = _vm._i($$a, null); $$el.checked ? $$i < 0 && _vm.$set(_vm.opts, "clean", $$a.concat([ null ])) : $$i > -1 && _vm.$set(_vm.opts, "clean", $$a.slice(0, $$i).concat($$a.slice($$i + 1))); } else { _vm.$set(_vm.opts, "clean", $$c); } } } }), _c("label", { attrs: { for: "separator-" + _vm.position } }, [ _vm._v("分隔符:") ]), _c("select", { directives: [ { name: "model", rawName: "v-model", value: _vm.opts.separator, expression: "opts.separator" } ], attrs: { id: "separator-" + _vm.position }, on: { change: function($event) { var $$selectedVal = Array.prototype.filter.call($event.target.options, (function(o) { return o.selected; })).map((function(o) { return "_value" in o ? o._value : o.value; })); _vm.$set(_vm.opts, "separator", $event.target.multiple ? $$selectedVal : $$selectedVal[0]); } } }, [ _c("option", { attrs: { value: "\n" } }, [ _vm._v("\\n") ]), _c("option", { attrs: { value: "\r\n" } }, [ _vm._v("\\r\\n") ]), _c("option", { attrs: { value: "\t" } }, [ _vm._v("\\t") ]), _c("option", { attrs: { value: " " } }, [ _vm._v("空格") ]), _c("option", { attrs: { value: "," } }, [ _vm._v(",") ]) ]), _c("div", { staticClass: "btn-wrapper" }, [ _c("button", { staticClass: "btn", on: { click: function($event) { return _vm.$emit("copy", _vm.opts); } } }, [ _vm._v("复制") ]), _c("button", { staticClass: "btn", on: { click: function($event) { return _vm.$emit("show", _vm.opts); } } }, [ _vm._v("查看") ]) ]) ]) ]); }, staticRenderFns: [] }, (function(inject) { inject && inject("data-v-0b5a2752_0", { source: ".tool-bar[data-v-0b5a2752]{display:none;background-color:#247;color:#fff}.tool-bar.top[data-v-0b5a2752]{border-bottom:1px solid #fff}.tool-bar.bottom[data-v-0b5a2752]{border-top:1px solid #fff}.tool-bar.visible[data-v-0b5a2752]{display:block}.wrapper[data-v-0b5a2752]{display:flex;flex-direction:row;align-items:center;height:auto}.wrapper label[data-v-0b5a2752]{margin-left:10px}.wrapper .title[data-v-0b5a2752]{padding:8px 15px;border-right:2px solid #fff}.wrapper .checkbox[data-v-0b5a2752]{width:14px;height:14px;vertical-align:middle}.wrapper .btn-wrapper[data-v-0b5a2752]{margin-left:10px}.wrapper .btn-wrapper .btn[data-v-0b5a2752]{margin:0 5px;padding:2px 5px;outline:0;border:1px solid #247;background-color:#fff;color:#247}", map: void 0, media: void 0 }); }), { name: "ToolBar", props: { position: { type: String, default: "top" } }, data: function() { return { visible: !1, opts: { clean: !0, separator: getDefaultLinebreak() } }; } }, "data-v-0b5a2752", !1, void 0, !1, createInjector, void 0, void 0), CheckboxHeaderVM = Vue.extend(__vue_component__$5), CheckboxItemVM = Vue.extend(__vue_component__$6), TorrentDownloadHeaderVM = Vue.extend(__vue_component__$3), TorrentDownloadItemVM = Vue.extend(__vue_component__$4), ToolBarVM = Vue.extend(__vue_component__$9), LinksPopupVM = Vue.extend(__vue_component__$8); var topicListEl, fileListEl, el, toast = (new (Vue.extend(__vue_component__))).$mount(); document.body.appendChild(toast.$el); Object.defineProperty(Vue.prototype, "$toast", { value: toast }); (topicListEl = document.querySelector("#topic_list")) && (el = topicListEl, new Vue({ data: function() { return { header: null, all: [], selected: [], popupIndex: 10, toolbars: [] }; }, computed: { links: function() { return this.selected.map((function(item) { return item.magnet; })).filter((function(m) { return !!m; })); } }, watch: { links: function(val) { var isEmpty = !val || val.length <= 0; this.toolbars.forEach((function(t) { t.visible = !isEmpty; })); } }, mounted: function() { this.$nextTick((function() { var tableContainer, table = this.$el; if (table.parentNode && (tableContainer = table.parentNode.parentNode) && !(tableContainer.className.indexOf("table") < 0)) { if (table.tHead && table.tBodies) { table.tHead.rows && table.tHead.rows.length > 0 && this.insertHeaderToRow(table.tHead.rows[0]); for (var index = 0, i = 0, len = table.tBodies.length; i < len; i++) { for (var body = table.tBodies[i], j = 0, rowLen = body.rows.length; j < rowLen; j++) { this.insertItemToRow(body.rows[j], index++); } } } else if (table.rows) { for (var _i = 0, _len = table.rows.length; _i < _len; _i++) { var row = table.rows[_i]; 0 === _i ? this.insertHeaderToRow(row) : this.insertItemToRow(row, _i - 1); } } this.initToolBars(tableContainer); } })); }, beforeDestroy: function() { if (this.header) { this.header.$off("change"); this.header = null; } this.all.forEach((function(item) { item.$off("change"); })); this.toolbars.forEach((function(t) { t.$off("copy"); t.$off("show"); })); this.all.splice(0, this.all.length); this.selected.splice(0, this.selected.length); this.toolbars.splice(0, this.toolbars.length); }, methods: { initToolBars: function(tableContainer) { var headerToolbar = new ToolBarVM({ propsData: { position: "top" } }).$mount(); headerToolbar.$on("copy", this.onCopyLinks); headerToolbar.$on("show", this.onShowLinks); var bottomToobar = new ToolBarVM({ propsData: { position: "bottom" } }).$mount(); bottomToobar.$on("copy", this.onCopyLinks); bottomToobar.$on("show", this.onShowLinks); tableContainer.insertBefore(headerToolbar.$el, tableContainer.firstChild); tableContainer.appendChild(bottomToobar.$el); this.toolbars.push(headerToolbar, bottomToobar); }, insertHeaderToRow: function(row) { if (!(row.cells.length <= 0)) { var sizeCell, firstCell = row.cells[0]; row.cells.length >= 5 && (sizeCell = row.cells[4]); var checkboxTH = (new CheckboxHeaderVM).$mount(); checkboxTH.$on("change", this.onSelectAllChange); row.insertBefore(checkboxTH.$el, firstCell); this.header = checkboxTH; if (sizeCell) { var bittorrentDownloadTH = (new TorrentDownloadHeaderVM).$mount(); row.insertBefore(bittorrentDownloadTH.$el, sizeCell); } } }, insertItemToRow: function(row, index) { if (!(row.cells.length <= 0)) { var sizeCell, firstCell = row.cells[0]; row.cells.length >= 5 && (sizeCell = row.cells[4]); var magnetLinkDOM = row.querySelector("td > .arrow-magnet"), checkboxTD = new CheckboxItemVM({ propsData: { index: index, magnet: magnetLinkDOM ? magnetLinkDOM.href : "" } }).$mount(), _self = this; checkboxTD.$on("change", (function(checked) { _self.onItemSelectChange(checkboxTD, checked); })); row.insertBefore(checkboxTD.$el, firstCell); this.all.push(checkboxTD); if (sizeCell) { var detailLinkDom = row.querySelector("td.title > a"), bittorrentDownloadTD = new TorrentDownloadItemVM({ propsData: { index: index, detailLink: detailLinkDom ? detailLinkDom.href : "", title: detailLinkDom ? detailLinkDom.innerText : "" } }).$mount(); row.insertBefore(bittorrentDownloadTD.$el, sizeCell); } } }, onSelectAllChange: function(checked) { this.all.forEach((function(item) { item.checked = checked; })); checked ? this.selected = _toConsumableArray(this.all) : this.selected.splice(0, this.selected.length); }, onItemSelectChange: function(item, checked) { var selectedIndex = this.selected.indexOf(item); checked && selectedIndex < 0 ? this.selected.push(item) : !checked && selectedIndex > -1 && this.selected.splice(selectedIndex, 1); this.header && (this.header.checked = this.all.length === this.selected.length); }, onCopyLinks: function(opts) { var links = magnetLinksWithOptions(this.links, opts); if (links.length > 0) { try { var content = links.join(opts.separator); GM_setClipboard(content, "{ type: 'text', mimetype: 'text/plain'}"); this.$toast.display("复制成功!"); } catch (e) { this.$toast.display("复制失败,请重试。"); } } }, onShowLinks: function(opts) { var links = magnetLinksWithOptions(this.links, opts); if (links.length > 0) { var popup = new LinksPopupVM({ propsData: { zIndex: this.popupIndex++, links: links, options: opts } }).$mount(); popup.$on("close", (function() { popup.$off("close"); try { popup.$el.remove(); } catch (e) { document.body.removeChild(popup.$el); } })); document.body.appendChild(popup.$el); } } } }).$mount(el)); if (fileListEl = document.querySelector("#resource-tabs .file_list")) { var titleEl, title = ""; (titleEl = document.querySelector(".topic-title h3")) && (title = titleEl.innerText.trim()); !function(el, title) { var fileListNode = el.querySelector("ul"), fileItemNodeList = el.querySelectorAll("ul > li"); if (fileListNode && !(fileItemNodeList.length <= 0)) { var folders = function(fileNodeList) { for (var map = {}, list = [], i = 0, len = fileNodeList.length; i < len; i++) { var fileNode = fileNodeList[i], fileSizeNode = fileNode.querySelector(".bt_file_size"), nodeText = fileNode.innerText, fileSizeStr = void 0; fileSizeNode && (fileSizeStr = fileSizeNode.innerText.trim()); var filePath = void 0, fileBytes = 0; if (fileSizeStr) { var bytes = fileSizeStr.replace(/(\d+)bytes?/i, "$1"); fileBytes = isNaN(+bytes) ? XBytes.parseSize(fileSizeStr, { iec: !1 }) : +bytes; filePath = nodeText.substring(0, nodeText.indexOf(fileSizeStr)).trim(); } else { filePath = nodeText.trim(); } filePath || (filePath = "No. ".concat(i + 1, " - Unknown filename")); for (var slice = filePath.split("/"), parentKey = 0, j = 0, sLen = slice.length; j < sLen; j++) { var fileName = slice[j], level = j + 1, key = hashCode(filePath.substring(0, filePath.indexOf(fileName) + fileName.length)); if (!map[key]) { var file = { key: key, parentKey: parentKey, name: fileName, level: level, size: level === sLen ? fileBytes : 0, children: level === sLen ? null : [] }; map[key] = file; list.push(file); } parentKey = key; } } for (var root = [], _i = 0, _len = list.length; _i < _len; _i++) { var _file = list[_i]; _file.parentKey ? map[_file.parentKey].children.push(_file) : root.push(_file); } return root; }(fileItemNodeList); if (!(folders.length <= 0)) { new TreeVM({ propsData: { folders: (folders.length > 1 || folders[0].size) && title ? [ { key: 0, parentKey: -1, name: title, children: folders } ] : folders } }).$mount(fileListNode); } } }(fileListEl, title); } }(Vue, xbytes);