// ==UserScript== // @name DMHY download helper // @name:zh-CN 动漫花园下载助手 // @description A dmhy.org download userscript. // @description:zh-CN 一个用于 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?* // @require https://cdn.jsdelivr.net/npm/vue@2.6.8/dist/vue.min.js // @grant GM_setClipboard // @source https://github.com/kuoruan/dmhy-download-helper.git // @license MIT - https://opensource.org/licenses/MIT // @run-at document-end // @version 1.1.1 // @icon https://www.google.cn/s2/favicons?domain=share.dmhy.org // @downloadURL none // ==/UserScript== !function(Vue) { "use strict"; Vue = Vue && Vue.hasOwnProperty("default") ? Vue.default : Vue; function styleInject(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)); } } styleInject("body{position:relative}#topic_list .even:hover,#topic_list .even:hover td,#topic_list .odd:hover,#topic_list .odd:hover td{background-color:#0eb9e7}"); function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || "[object Arguments]" === Object.prototype.toString.call(iter)) { return Array.from(iter); } } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } 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; } var script = { name: "ToolBar", props: { position: { type: String, default: "top" } }, data: function data() { return { visible: !1, opts: { clean: !0, separator: getDefaultLinebreak() } }; } }; 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 hook(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() { style.call(this, createInjectorShadow(this.$root.$options.shadowRoot)); } : function(context) { style.call(this, createInjector(context)); }); } if (hook) { if (options.functional) { var originalRender = options.render; options.render = function renderWithStyleInjection(h, context) { hook.call(context); return originalRender(h, context); }; } else { var existing = options.beforeCreate; options.beforeCreate = existing ? [].concat(existing, hook) : [ hook ]; } } return script; } var normalizeComponent_1 = normalizeComponent, isOldIE = "undefined" != typeof navigator && /msie [6-9]\\b/.test(navigator.userAgent.toLowerCase()); function createInjector(context) { return function(id, style) { return addStyle(id, style); }; } var HEAD = document.head || document.getElementsByTagName("head")[0], styles = {}; function addStyle(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); 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); } } } var browser = createInjector; var ToolBar = normalizeComponent_1({ 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 $$v = null, $$i = _vm._i($$a, $$v); $$el.checked ? $$i < 0 && _vm.$set(_vm.opts, "clean", $$a.concat([ $$v ])) : $$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-9d334570_0", { source: ".tool-bar[data-v-9d334570]{background-color:#247;color:#fff;display:none}.tool-bar.top[data-v-9d334570]{border-bottom:1px solid #fff}.tool-bar.bottom[data-v-9d334570]{border-top:1px solid #fff}.tool-bar.visible[data-v-9d334570]{display:block}.wrapper[data-v-9d334570]{display:flex;height:auto;flex-direction:row;align-items:center}.wrapper label[data-v-9d334570]{margin-left:10px}.wrapper .title[data-v-9d334570]{padding:8px 15px;border-right:2px solid #fff}.wrapper .checkbox[data-v-9d334570]{width:14px;height:14px;vertical-align:middle}.wrapper .btn-wrapper[data-v-9d334570]{margin-left:10px}.wrapper .btn-wrapper .btn[data-v-9d334570]{padding:2px 5px;color:#247;background-color:#fff;border:1px solid #247;margin:0 5px;outline:0}", map: void 0, media: void 0 }); }, script, "data-v-9d334570", !1, void 0, browser, void 0); var CheckboxHeader = normalizeComponent_1({ 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 $$v = null, $$i = _vm._i($$a, $$v); $$el.checked ? $$i < 0 && (_vm.checked = $$a.concat([ $$v ])) : $$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-7bc073df_0", { source: ".header[data-v-7bc073df]{cursor:default}.header .select-all[data-v-7bc073df]{width:14px;height:14px}.header .title[data-v-7bc073df]{margin-left:5px}", map: void 0, media: void 0 }); }, { name: "CheckboxHeader", data: function data() { return { checked: !1 }; } }, "data-v-7bc073df", !1, void 0, browser, void 0); var CheckboxItem = normalizeComponent_1({ 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 $$v = null, $$i = _vm._i($$a, $$v); $$el.checked ? $$i < 0 && (_vm.checked = $$a.concat([ $$v ])) : $$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-614ed75f_0", { source: ".select[data-v-614ed75f]{width:14px;height:14px}", map: void 0, media: void 0 }); }, { name: "CheckboxItem", props: { index: { type: Number, default: 0 }, magnet: { type: String, default: "" } }, data: function data() { return { checked: !1 }; } }, "data-v-614ed75f", !1, void 0, browser, void 0); var Toast = normalizeComponent_1({ render: function() { var _vm = this, _h = _vm.$createElement, _c = _vm._self._c || _h; return _c("div", { staticClass: "toast", class: { show: _vm.show } }, [ _c("span", { staticClass: "text" }, [ _vm._v(_vm._s(_vm.text)) ]) ]); }, staticRenderFns: [] }, function(inject) { inject && inject("data-v-161e41de_0", { source: ".toast[data-v-161e41de]{display:none;padding:10px 20px;position:fixed;left:50%;bottom:30px;z-index:99;border-radius:2px;background-color:#333;transform:translateX(-50%)}.toast.show[data-v-161e41de]{display:block;animation:fadein-data-v-161e41de .5s,fadeout-data-v-161e41de .5s 2.5s}.toast .text[data-v-161e41de]{color:#fff;font-size:14px;line-height:1.5}@-moz-keyframes fadein-data-v-161e41de{from{bottom:0;opacity:0}to{bottom:30px;opacity:1}}@-webkit-keyframes fadein-data-v-161e41de{from{bottom:0;opacity:0}to{bottom:30px;opacity:1}}@-o-keyframes fadein-data-v-161e41de{from{bottom:0;opacity:0}to{bottom:30px;opacity:1}}@keyframes fadein-data-v-161e41de{from{bottom:0;opacity:0}to{bottom:30px;opacity:1}}@-moz-keyframes fadeout-data-v-161e41de{from{bottom:30px;opacity:1}to{bottom:0;opacity:0}}@-webkit-keyframes fadeout-data-v-161e41de{from{bottom:30px;opacity:1}to{bottom:0;opacity:0}}@-o-keyframes fadeout-data-v-161e41de{from{bottom:30px;opacity:1}to{bottom:0;opacity:0}}@keyframes fadeout-data-v-161e41de{from{bottom:30px;opacity:1}to{bottom:0;opacity:0}}", map: void 0, media: void 0 }); }, { name: "Toast", data: function data() { return { text: "", show: !1, timer: 0 }; }, methods: { display: function display(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); } } }, "data-v-161e41de", !1, void 0, browser, void 0); var Popup = normalizeComponent_1({ 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-1ba53d01_0", { source: '.overlay[data-v-1ba53d01]{position:fixed;top:0;bottom:0;left:0;right:0;text-align:center;background-color:rgba(0,0,0,.3)}.overlay[data-v-1ba53d01]:after{content:"";display:inline-block;height:100%;width:0;vertical-align:middle}.overlay .popup[data-v-1ba53d01]{display:inline-block;background-color:#fff;box-shadow:0 2px 12px 0 rgba(0,0,0,.1);text-align:left;overflow:hidden;backface-visibility:hidden;border:1px solid #247;padding:2px}.overlay .popup.middle[data-v-1ba53d01]{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 onScroll(evt) { var el = evt.target, _window$getComputedSt = window.getComputedStyle(el), overflow = _window$getComputedSt.overflow, overflowY = _window$getComputedSt.overflowY, overflowX = _window$getComputedSt.overflowX; (!/(auto|scroll)/.test(overflow + overflowX + overflowY) || 0 === el.scrollTop && evt.deltaY < 0 || Math.abs(el.scrollTop - (el.scrollHeight - el.clientHeight)) <= 1 && evt.deltaY > 0) && evt.preventDefault(); } } }, "data-v-1ba53d01", !1, void 0, browser, void 0); var LinksPopup = normalizeComponent_1({ 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-ece87676_0", { source: ".btn[data-v-ece87676]{padding:2px 5px;color:#247;background-color:#fff;border:1px solid #247;outline:0}.popup-header[data-v-ece87676]{background-color:#247;padding:5px;display:flex;flex-direction:row;align-items:center}.popup-header h4[data-v-ece87676]{font-size:14px;text-align:left;font-weight:400;line-height:1.5;color:#fff;flex:1 1 0}.popup-body[data-v-ece87676]{padding:5px;background-color:#fff}.popup-body .links-box[data-v-ece87676]{background-color:#eef;background-image:none;border:1px solid #247;color:#333;padding:4px 8px;font-size:12px;line-height:1.5;overflow:auto;resize:none;cursor:text}.popup-footer[data-v-ece87676]{padding:5px;background-color:#cdf;display:flex;flex-direction:row;align-items:center}.popup-footer .btn[data-v-ece87676]:not(:first-child){margin-left:10px}.popup-footer p[data-v-ece87676]{text-align:right;flex:1 1 0;margin:0}", map: void 0, media: void 0 }); }, { name: "LinksPopup", components: { Popup: Popup }, props: { zIndex: { type: Number, default: 10 }, links: { type: Array, default: function _default() { return []; } }, options: { type: Object, default: function _default() { return { separator: getDefaultLinebreak() }; } } }, data: function data() { return { content: "" }; }, created: function created() { this.resetContent(); }, watch: { links: function links() { this.resetContent(); } }, computed: { textStyle: function textStyle() { return [ "\n", "\r\n" ].indexOf(this.options.separator) > -1 && this.links.length > 1 ? { "white-space": "nowrap", "word-wrap": "normal" } : { "white-space": "pre-wrap", "word-wrap": "break-all" }; } }, methods: { resetContent: function resetContent() { this.content = this.links.join(this.options.separator); }, copySelected: function copySelected() { 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 copyAll() { 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 selectAll() { var target = this.$refs.textarea; target ? target.select() : this.$toast.display("获取文本框失败"); } } }, "data-v-ece87676", !1, void 0, browser, void 0); function createList(selector) { var HeaderVM = Vue.extend(CheckboxHeader), ItemVM = Vue.extend(CheckboxItem); return new Vue({ el: selector, data: function data() { return { header: null, all: [], selected: [] }; }, mounted: function mounted() { this.$nextTick(function() { var table = this.$el; 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.insertCheckBoxToRow(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.insertCheckBoxToRow(row, _i - 1); } } }); }, beforeDestroy: function beforeDestroy() { if (this.header) { this.header.$off("change"); this.header = null; } this.all.forEach(function(item) { item.$off("change"); }); this.all.splice(0, this.all.length); this.selected.splice(0, this.selected.length); }, computed: { links: function links() { return this.selected.map(function(item) { return item.magnet; }).filter(function(m) { return !!m; }); } }, watch: { links: function links(val) { this.$emit("change", val); } }, methods: { insertHeaderToRow: function insertHeaderToRow(row) { var th = new HeaderVM(); th.$on("change", this.onSelectAllChange); th.$mount(); row.insertBefore(th.$el, row.cells[0]); this.header = th; }, insertCheckBoxToRow: function insertCheckBoxToRow(row, index) { var linkDOM = row.querySelector(".arrow-magnet"), tdDOM = row.insertCell(0), td = new ItemVM({ propsData: { index: index, magnet: linkDOM ? linkDOM.href : "" } }), _self = this; td.$on("change", function(checked) { _self.onItemSelectChange(td, checked); }); td.$mount(tdDOM); this.all.push(td); }, onSelectAllChange: function onSelectAllChange(checked) { this.all.forEach(function(item) { item.checked = checked; }); checked ? this.selected = _toConsumableArray(this.all) : this.selected.splice(0, this.selected.length); }, onItemSelectChange: function onItemSelectChange(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); } } }); } function createToolbar(propsData) { return new (Vue.extend(ToolBar))({ propsData: propsData }).$mount(); } function createToast() { var toast = new (Vue.extend(Toast))().$mount(); document.body.appendChild(toast.$el); Object.defineProperty(Vue.prototype, "$toast", { value: toast }); return toast; } function createLinksPopup(propsData) { return new (Vue.extend(LinksPopup))({ propsData: propsData }).$mount(); } var list = createList("#topic_list"); if (list.$el && list.$el.parentNode) { var toast = createToast(), popupIndex = 10, onCopyClick = function onCopyClick(opts) { var links = magnetLinksWithOptions(list.links, opts); if (links.length > 0) { try { var content = links.join(opts.separator); GM_setClipboard(content, "{ type: 'text', mimetype: 'text/plain'}"); toast.display("复制成功!"); } catch (e) { toast.display("复制失败,请重试。"); } } }, onShowClick = function onShowClick(opts) { var links = magnetLinksWithOptions(list.links, opts); if (links.length > 0) { var popup = createLinksPopup({ zIndex: popupIndex++, links: links, options: opts }); popup.$on("close", function() { popup.$off("close"); try { popup.$el.remove(); } catch (e) { document.body.removeChild(popup.$el); } }); document.body.appendChild(popup.$el); } }, tableContainer = list.$el.parentNode.parentNode; if (tableContainer.className.indexOf("table") > -1) { var headerToolbar = createToolbar({ position: "top" }); headerToolbar.$on("copy", onCopyClick); headerToolbar.$on("show", onShowClick); var bottomToobar = createToolbar({ position: "bottom" }); bottomToobar.$on("copy", onCopyClick); bottomToobar.$on("show", onShowClick); tableContainer.insertBefore(headerToolbar.$el, tableContainer.firstChild); tableContainer.appendChild(bottomToobar.$el); list.$on("change", function(values) { var isEmpty = values.length <= 0; headerToolbar.visible = !isEmpty; bottomToobar.visible = !isEmpty; }); } } }(Vue);