Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. e.exports = function() {
  2.             if ("undefined" == typeof document || !document.addEventListener) return null;
  3.             var r, o, i, a = {};
  4.             return a.copy = function() {
  5.                 var e = !1,
  6.                     t = null,
  7.                     n = !1;
  8.  
  9.                 function r() {
  10.                     e = !1, t = null, n && window.getSelection().removeAllRanges(), n = !1
  11.                 }
  12.                 return document.addEventListener("copy", function(n) {
  13.                         if (e) {
  14.                             for (var r in t) n.clipboardData.setData(r, t[r]);
  15.                             n.preventDefault()
  16.                         }
  17.                     }),
  18.                     function(o) {
  19.                         return new Promise(function(i, a) {
  20.                             e = !0, "string" == typeof o ? t = {
  21.                                     "text/plain": o
  22.                                 } : o instanceof Node ? t = {
  23.                                     "text/html": (new XMLSerializer).serializeToString(o)
  24.                                 } : o instanceof Object ? t = o : a("Invalid data type. Must be string, DOM node, or an object mapping MIME types to strings."),
  25.                                 function e(t) {
  26.                                     try {
  27.                                         if (document.execCommand("copy")) r(), i();
  28.                                         else {
  29.                                             if (t) throw r(), new Error("Unable to copy. Perhaps it's not available in your browser?");
  30.                                             ! function() {
  31.                                                 var e = document.getSelection();
  32.                                                 if (!document.queryCommandEnabled("copy") && e.isCollapsed) {
  33.                                                     var t = document.createRange();
  34.                                                     t.selectNodeContents(document.body), e.removeAllRanges(), e.addRange(t), n = !0
  35.                                                 }
  36.                                             }(), e(!0)
  37.                                         }
  38.                                     } catch (e) {
  39.                                         r(), a(e)
  40.                                     }
  41.                                 }(!1)
  42.                         })
  43.                     }
  44.             }(), a.paste = (i = !1, document.addEventListener("paste", function(e) {
  45.                 if (i) {
  46.                     i = !1, e.preventDefault();
  47.                     var t = r;
  48.                     r = null, t(e.clipboardData.getData(o))
  49.                 }
  50.             }), function(e) {
  51.                 return new Promise(function(t, n) {
  52.                     i = !0, r = t, o = e || "text/plain";
  53.                     try {
  54.                         document.execCommand("paste") || (i = !1, n(new Error("Unable to paste. Pasting only works in Internet Explorer at the moment.")))
  55.                     } catch (e) {
  56.                         i = !1, n(new Error(e))
  57.                     }
  58.                 })
  59.             }), "undefined" == typeof ClipboardEvent && void 0 !== window.clipboardData && void 0 !== window.clipboardData.setData && (
  60.                 /*! promise-polyfill 2.0.1 */
  61.                 function(r) {
  62.                     function o(e, t) {
  63.                         return function() {
  64.                             e.apply(t, arguments)
  65.                         }
  66.                     }
  67.  
  68.                     function i(e) {
  69.                         if ("object" != n(this)) throw new TypeError("Promises must be constructed via new");
  70.                         if ("function" != typeof e) throw new TypeError("not a function");
  71.                         this._state = null, this._value = null, this._deferreds = [], f(e, o(l, this), o(u, this))
  72.                     }
  73.  
  74.                     function a(e) {
  75.                         var t = this;
  76.                         return null === this._state ? void this._deferreds.push(e) : void p(function() {
  77.                             var n = t._state ? e.onFulfilled : e.onRejected;
  78.                             if (null !== n) {
  79.                                 var r;
  80.                                 try {
  81.                                     r = n(t._value)
  82.                                 } catch (t) {
  83.                                     return void e.reject(t)
  84.                                 }
  85.                                 e.resolve(r)
  86.                             } else(t._state ? e.resolve : e.reject)(t._value)
  87.                         })
  88.                     }
  89.  
  90.                     function l(e) {
  91.                         try {
  92.                             if (e === this) throw new TypeError("A promise cannot be resolved with itself.");
  93.                             if (e && ("object" == n(e) || "function" == typeof e)) {
  94.                                 var t = e.then;
  95.                                 if ("function" == typeof t) return void f(o(t, e), o(l, this), o(u, this))
  96.                             }
  97.                             this._state = !0, this._value = e, c.call(this)
  98.                         } catch (e) {
  99.                             u.call(this, e)
  100.                         }
  101.                     }
  102.  
  103.                     function u(e) {
  104.                         this._state = !1, this._value = e, c.call(this)
  105.                     }
  106.  
  107.                     function c() {
  108.                         for (var e = 0, t = this._deferreds.length; t > e; e++) a.call(this, this._deferreds[e]);
  109.                         this._deferreds = null
  110.                     }
  111.  
  112.                     function s(e, t, n, r) {
  113.                         this.onFulfilled = "function" == typeof e ? e : null, this.onRejected = "function" == typeof t ? t : null, this.resolve = n, this.reject = r
  114.                     }
  115.  
  116.                     function f(e, t, n) {
  117.                         var r = !1;
  118.                         try {
  119.                             e(function(e) {
  120.                                 r || (r = !0, t(e))
  121.                             }, function(e) {
  122.                                 r || (r = !0, n(e))
  123.                             })
  124.                         } catch (e) {
  125.                             if (r) return;
  126.                             r = !0, n(e)
  127.                         }
  128.                     }
  129.                     var p = i.immediateFn || "function" == typeof t && t || function(e) {
  130.                             setTimeout(e, 1)
  131.                         },
  132.                         d = Array.isArray || function(e) {
  133.                             return "[object Array]" === Object.prototype.toString.call(e)
  134.                         };
  135.                     i.prototype.catch = function(e) {
  136.                         return this.then(null, e)
  137.                     }, i.prototype.then = function(e, t) {
  138.                         var n = this;
  139.                         return new i(function(r, o) {
  140.                             a.call(n, new s(e, t, r, o))
  141.                         })
  142.                     }, i.all = function() {
  143.                         var e = Array.prototype.slice.call(1 === arguments.length && d(arguments[0]) ? arguments[0] : arguments);
  144.                         return new i(function(t, r) {
  145.                             function o(a, l) {
  146.                                 try {
  147.                                     if (l && ("object" == n(l) || "function" == typeof l)) {
  148.                                         var u = l.then;
  149.                                         if ("function" == typeof u) return void u.call(l, function(e) {
  150.                                             o(a, e)
  151.                                         }, r)
  152.                                     }
  153.                                     e[a] = l, 0 == --i && t(e)
  154.                                 } catch (e) {
  155.                                     r(e)
  156.                                 }
  157.                             }
  158.                             if (0 === e.length) return t([]);
  159.                             for (var i = e.length, a = 0; a < e.length; a++) o(a, e[a])
  160.                         })
  161.                     }, i.resolve = function(e) {
  162.                         return e && "object" == n(e) && e.constructor === i ? e : new i(function(t) {
  163.                             t(e)
  164.                         })
  165.                     }, i.reject = function(e) {
  166.                         return new i(function(t, n) {
  167.                             n(e)
  168.                         })
  169.                     }, i.race = function(e) {
  170.                         return new i(function(t, n) {
  171.                             for (var r = 0, o = e.length; o > r; r++) e[r].then(t, n)
  172.                         })
  173.                     }, e.exports ? e.exports = i : r.Promise || (r.Promise = i)
  174.                 }(this), a.copy = function(e) {
  175.                     return new Promise(function(t, n) {
  176.                         if ("string" != typeof e && !("text/plain" in e)) throw new Error("You must provide a text/plain type.");
  177.                         var r = "string" == typeof e ? e : e["text/plain"];
  178.                         window.clipboardData.setData("Text", r) ? t() : n(new Error("Copying was rejected."))
  179.                     })
  180.                 }, a.paste = function() {
  181.                     return new Promise(function(e, t) {
  182.                         var n = window.clipboardData.getData("Text");
  183.                         n ? e(n) : t(new Error("Pasting was rejected."))
  184.                     })
  185.                 }), a
  186.         }()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement