Guest User

Untitled

a guest
Dec 31st, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. var incognito = function(require, module, exports) {
  2. "use strict";
  3. function isWebkitRequestFileSystem() {
  4. return !!window.webkitRequestFileSystem
  5. }
  6. function isFirefoxIndexedDB() {
  7. return !!window.indexedDB && /Firefox/.test(window.navigator.userAgent)
  8. }
  9. function isIE10PlusOrEdge() {
  10. if (document.documentMode) {
  11. var e = window.navigator.userAgent.match(/(?:MSIE|Trident.*rv:)\s*([\d\.]+)/i);
  12. return "object" === (void 0 === e ? "undefined" : _typeof(e)) && parseInt(e[1]) >= 10
  13. }
  14. return !!window.StyleMedia && /Edge\//i.test(window.navigator.userAgent)
  15. }
  16. function isSafariLocalStorage() {
  17. return !!window.localStorage && /Safari/.test(window.navigator.userAgent)
  18. }
  19. function detectWebkitRequestFileSystem(e, t) {
  20. return new Promise(function(e) {
  21. if (!window.webkitRequestFileSystem)
  22. return e(null);
  23. window.webkitRequestFileSystem(window.TEMPORARY, 1, e.bind(null, !1), e.bind(null, !0))
  24. }
  25. )
  26. }
  27. function detectFirefoxIndexedDB() {
  28. return new Promise(function(e) {
  29. if (!window.indexedDB)
  30. return e(null);
  31. var t = void 0;
  32. try {
  33. t = window.indexedDB.open("test")
  34. } catch (t) {
  35. return e(!0)
  36. }
  37. var n = 0
  38. , i = window.setInterval(function() {
  39. if ("done" === t.readyState) {
  40. var o = !t.result;
  41. return window.clearInterval(i),
  42. e(o)
  43. }
  44. if (++n >= 50)
  45. return window.clearInterval(i),
  46. e(null)
  47. }, 10)
  48. }
  49. )
  50. }
  51. function detectIE10PlusOrEdge() {
  52. return new Promise(function(e) {
  53. try {
  54. return e(window.indexedDB ? !1 : !0)
  55. } catch (t) {
  56. return e(!0)
  57. }
  58. }
  59. )
  60. }
  61. function detectSafariLocalStorage() {
  62. return new Promise(function(e) {
  63. if (!window.localStorage)
  64. return e(null);
  65. try {
  66. window.localStorage.setItem("test", 1),
  67. window.localStorage.removeItem("test")
  68. } catch (t) {
  69. return e(!0)
  70. }
  71. return e(!1)
  72. }
  73. )
  74. }
  75. function detectIncognito() {
  76. return new Promise(function(e) {
  77. if (incognitoCheckIsDisabled())
  78. return e("disabled");
  79. for (var t in detects) {
  80. var n = _slicedToArray(detects[t], 3)
  81. , i = n[1]
  82. , o = n[2];
  83. if (i())
  84. return e(o())
  85. }
  86. return e(null)
  87. }
  88. )
  89. }
  90. function debugIncognito() {
  91. var e = detects.map(function(e) {
  92. var t = _slicedToArray(e, 3)
  93. , n = t[0]
  94. , i = t[1];
  95. return (0,
  96. t[2])().then(function(e) {
  97. return {
  98. label: n,
  99. browser: i(),
  100. incognito: e
  101. }
  102. })
  103. });
  104. return Promise.all(e)
  105. }
  106. function incognitoCheckIsDisabled() {
  107. return hasIncognitoCheckDisabledCookie() || hasIncognitoCheckDisabledQuery()
  108. }
  109. function hasIncognitoCheckDisabledCookie() {
  110. return new RegExp(COOKIE_NAME + "=" + COOKIE_VALUE).test(document.cookie)
  111. }
  112. function hasIncognitoCheckDisabledQuery() {
  113. return new RegExp("[?&]" + URL_PARAM).test(window.location.search)
  114. }
  115. function setIncognitoCheckDisabled() {
  116. var e = new Date;
  117. e.setTime(e.getTime() + 31104e6),
  118. document.cookie = COOKIE_NAME + "=" + COOKIE_VALUE + "; expires=" + e.toUTCString() + "; path=/"
  119. }
  120. function init() {
  121. hasIncognitoCheckDisabledQuery() && setIncognitoCheckDisabled()
  122. }
  123. var _slicedToArray = function() {
  124. function e(e, t) {
  125. var n = []
  126. , i = !0
  127. , o = !1
  128. , r = void 0;
  129. try {
  130. for (var c, u = e[Symbol.iterator](); !(i = (c = u.next()).done) && (n.push(c.value),
  131. !t || n.length !== t); i = !0)
  132. ;
  133. } catch (e) {
  134. o = !0,
  135. r = e
  136. } finally {
  137. try {
  138. !i && u.return && u.return()
  139. } finally {
  140. if (o)
  141. throw r
  142. }
  143. }
  144. return n
  145. }
  146. return function(t, n) {
  147. if (Array.isArray(t))
  148. return t;
  149. if (Symbol.iterator in Object(t))
  150. return e(t, n);
  151. throw new TypeError("Invalid attempt to destructure non-iterable instance")
  152. }
  153. }()
  154. , _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
  155. return typeof e
  156. }
  157. : function(e) {
  158. return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  159. }
  160. , COOKIE_NAME = "mittr-incognito-check-disabled"
  161. , COOKIE_VALUE = "1"
  162. , URL_PARAM = "disable-incognito-check"
  163. , detects = [["Webkit RequestFileSystem", isWebkitRequestFileSystem, detectWebkitRequestFileSystem], ["Firefox IndexedDB", isFirefoxIndexedDB, detectFirefoxIndexedDB], ["IE10+ / Edge", isIE10PlusOrEdge, detectIE10PlusOrEdge], ["Safari LocalStorage", isSafariLocalStorage, detectSafariLocalStorage]];
  164. init(),
  165. module.exports = {
  166. detectIncognito: detectIncognito,
  167. debugIncognito: debugIncognito
  168. };
  169. }
Add Comment
Please, Sign In to add comment