wabot
Version:
Whatsapp Bot Module for automate response and interact whit users
135 lines (115 loc) • 4.79 kB
JavaScript
/* Polyfill service v3.25.1
* For detailed credits and licence information see https://github.com/financial-times/polyfill-service.
*
* UA detected: opera/67.0.0
* Features requested: default
*
* - _mutation, License: CC0 (required by "DocumentFragment.prototype.append", "default", "DocumentFragment.prototype.prepend", "Element.prototype.after", "Element.prototype.append", "Element.prototype.before", "Element.prototype.prepend", "Element.prototype.replaceWith")
* - DocumentFragment.prototype.append, License: CC0 (required by "default")
* - DocumentFragment.prototype.prepend, License: CC0 (required by "default")
* - Element.prototype.after, License: CC0 (required by "default")
* - Element.prototype.append, License: CC0 (required by "default")
* - Element.prototype.before, License: CC0 (required by "default")
* - Element.prototype.prepend, License: CC0 (required by "default")
* - Element.prototype.replaceWith, License: CC0 (required by "default") */
(function(undefined) {
// _mutation
var _mutation = (function () { // eslint-disable-line no-unused-vars
function isNode(object) {
// DOM, Level2
if (typeof Node === 'function') {
return object instanceof Node;
}
// Older browsers, check if it looks like a Node instance)
return object &&
typeof object === "object" &&
object.nodeName &&
object.nodeType >= 1 &&
object.nodeType <= 12;
}
// http://dom.spec.whatwg.org/#mutation-method-macro
return function mutation(nodes) {
if (nodes.length === 1) {
return isNode(nodes[0]) ? nodes[0] : document.createTextNode(nodes[0] + '');
}
var fragment = document.createDocumentFragment();
for (var i = 0; i < nodes.length; i++) {
fragment.appendChild(isNode(nodes[i]) ? nodes[i] : document.createTextNode(nodes[i] + ''));
}
return fragment;
};
}());
// DocumentFragment.prototype.append
DocumentFragment.prototype.append = function append() {
this.appendChild(_mutation(arguments));
};
// DocumentFragment.prototype.prepend
DocumentFragment.prototype.prepend = function prepend() {
this.insertBefore(_mutation(arguments), this.firstChild);
};
// Element.prototype.after
Document.prototype.after = Element.prototype.after = function after() {
if (this.parentNode) {
var args = Array.prototype.slice.call(arguments),
viableNextSibling = this.nextSibling,
idx = viableNextSibling ? args.indexOf(viableNextSibling) : -1;
while (idx !== -1) {
viableNextSibling = viableNextSibling.nextSibling;
if (!viableNextSibling) {
break;
}
idx = args.indexOf(viableNextSibling);
}
this.parentNode.insertBefore(_mutation(arguments), viableNextSibling);
}
};
// Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
// TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
if ("Text" in this) {
Text.prototype.after = Element.prototype.after;
}
// Element.prototype.append
Document.prototype.append = Element.prototype.append = function append() {
this.appendChild(_mutation(arguments));
};
// Element.prototype.before
Document.prototype.before = Element.prototype.before = function before() {
if (this.parentNode) {
var args = Array.prototype.slice.call(arguments),
viablePreviousSibling = this.previousSibling,
idx = viablePreviousSibling ? args.indexOf(viablePreviousSibling) : -1;
while (idx !== -1) {
viablePreviousSibling = viablePreviousSibling.previousSibling;
if (!viablePreviousSibling) {
break;
}
idx = args.indexOf(viablePreviousSibling);
}
this.parentNode.insertBefore(
_mutation(arguments),
viablePreviousSibling ? viablePreviousSibling.nextSibling : this.parentNode.firstChild
);
}
};
// Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
// TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
if ("Text" in this) {
Text.prototype.before = Element.prototype.before;
}
// Element.prototype.prepend
Document.prototype.prepend = Element.prototype.prepend = function prepend() {
this.insertBefore(_mutation(arguments), this.firstChild);
};
// Element.prototype.replaceWith
Document.prototype.replaceWith = Element.prototype.replaceWith = function replaceWith() {
if (this.parentNode) {
this.parentNode.replaceChild(_mutation(arguments), this);
}
};
// Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
// TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
if ('Text' in this) {
Text.prototype.replaceWith = Element.prototype.replaceWith;
}
})
.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});