vue-if-bot
Version:
Hide stuff from bots (especially cookie consents)
36 lines (28 loc) • 950 B
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.ifBot = factory());
}(this, (function () { 'use strict';
var index = {
functional: true,
render: function render(h, _ref) {
var children = _ref.children,
slots = _ref.slots,
_ref$props = _ref.props,
regex = _ref$props.regex,
invert = _ref$props.invert;
var dummyEl = h('div', {}, []);
if (process.server) {
return dummyEl;
}
var botRegex = regex || /bot|googlebot|crawler|spider|robot|crawling/i;
var isBot = navigator.userAgent && botRegex.test(navigator.userAgent);
var shouldShow = invert ? isBot : !isBot;
if (!shouldShow) {
return dummyEl;
}
return h('div', {}, slots().default);
}
};
return index;
})));