Last active
May 26, 2020 15:33
-
-
Save matyasfodor/15e8863ab15baf4791a5fa4c748b64af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var incognito = function(require, module, exports) { | |
"use strict"; | |
function isWebkitRequestFileSystem() { | |
return !!window.webkitRequestFileSystem | |
} | |
function isFirefoxIndexedDB() { | |
return !!window.indexedDB && /Firefox/.test(window.navigator.userAgent) | |
} | |
function isIE10PlusOrEdge() { | |
if (document.documentMode) { | |
var e = window.navigator.userAgent.match(/(?:MSIE|Trident.*rv:)\s*([\d\.]+)/i); | |
return "object" === (void 0 === e ? "undefined" : _typeof(e)) && parseInt(e[1]) >= 10 | |
} | |
return !!window.StyleMedia && /Edge\//i.test(window.navigator.userAgent) | |
} | |
function isSafariLocalStorage() { | |
return !!window.localStorage && /Safari/.test(window.navigator.userAgent) | |
} | |
function detectWebkitRequestFileSystem(e, t) { | |
return new Promise(function(e) { | |
if (!window.webkitRequestFileSystem) | |
return e(null); | |
window.webkitRequestFileSystem(window.TEMPORARY, 1, e.bind(null, !1), e.bind(null, !0)) | |
} | |
) | |
} | |
function detectFirefoxIndexedDB() { | |
return new Promise(function(e) { | |
if (!window.indexedDB) | |
return e(null); | |
var t = void 0; | |
try { | |
t = window.indexedDB.open("test") | |
} catch (t) { | |
return e(!0) | |
} | |
var n = 0 | |
, i = window.setInterval(function() { | |
if ("done" === t.readyState) { | |
var o = !t.result; | |
return window.clearInterval(i), | |
e(o) | |
} | |
if (++n >= 50) | |
return window.clearInterval(i), | |
e(null) | |
}, 10) | |
} | |
) | |
} | |
function detectIE10PlusOrEdge() { | |
return new Promise(function(e) { | |
try { | |
return e(window.indexedDB ? !1 : !0) | |
} catch (t) { | |
return e(!0) | |
} | |
} | |
) | |
} | |
function detectSafariLocalStorage() { | |
return new Promise(function(e) { | |
if (!window.localStorage) | |
return e(null); | |
try { | |
window.localStorage.setItem("test", 1), | |
window.localStorage.removeItem("test") | |
} catch (t) { | |
return e(!0) | |
} | |
return e(!1) | |
} | |
) | |
} | |
function detectIncognito() { | |
return new Promise(function(e) { | |
if (incognitoCheckIsDisabled()) | |
return e("disabled"); | |
for (var t in detects) { | |
var n = _slicedToArray(detects[t], 3) | |
, i = n[1] | |
, o = n[2]; | |
if (i()) | |
return e(o()) | |
} | |
return e(null) | |
} | |
) | |
} | |
function debugIncognito() { | |
var e = detects.map(function(e) { | |
var t = _slicedToArray(e, 3) | |
, n = t[0] | |
, i = t[1]; | |
return (0, | |
t[2])().then(function(e) { | |
return { | |
label: n, | |
browser: i(), | |
incognito: e | |
} | |
}) | |
}); | |
return Promise.all(e) | |
} | |
function incognitoCheckIsDisabled() { | |
return hasIncognitoCheckDisabledCookie() || hasIncognitoCheckDisabledQuery() | |
} | |
function hasIncognitoCheckDisabledCookie() { | |
return new RegExp(COOKIE_NAME + "=" + COOKIE_VALUE).test(document.cookie) | |
} | |
function hasIncognitoCheckDisabledQuery() { | |
return new RegExp("[?&]" + URL_PARAM).test(window.location.search) | |
} | |
function setIncognitoCheckDisabled() { | |
var e = new Date; | |
e.setTime(e.getTime() + 31104e6), | |
document.cookie = COOKIE_NAME + "=" + COOKIE_VALUE + "; expires=" + e.toUTCString() + "; path=/" | |
} | |
function init() { | |
hasIncognitoCheckDisabledQuery() && setIncognitoCheckDisabled() | |
} | |
var _slicedToArray = function() { | |
function e(e, t) { | |
var n = [] | |
, i = !0 | |
, o = !1 | |
, r = void 0; | |
try { | |
for (var c, u = e[Symbol.iterator](); !(i = (c = u.next()).done) && (n.push(c.value), | |
!t || n.length !== t); i = !0) | |
; | |
} catch (e) { | |
o = !0, | |
r = e | |
} finally { | |
try { | |
!i && u.return && u.return() | |
} finally { | |
if (o) | |
throw r | |
} | |
} | |
return n | |
} | |
return function(t, n) { | |
if (Array.isArray(t)) | |
return t; | |
if (Symbol.iterator in Object(t)) | |
return e(t, n); | |
throw new TypeError("Invalid attempt to destructure non-iterable instance") | |
} | |
}() | |
, _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) { | |
return typeof e | |
} | |
: function(e) { | |
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e | |
} | |
, COOKIE_NAME = "mittr-incognito-check-disabled" | |
, COOKIE_VALUE = "1" | |
, URL_PARAM = "disable-incognito-check" | |
, detects = [["Webkit RequestFileSystem", isWebkitRequestFileSystem, detectWebkitRequestFileSystem], ["Firefox IndexedDB", isFirefoxIndexedDB, detectFirefoxIndexedDB], ["IE10+ / Edge", isIE10PlusOrEdge, detectIE10PlusOrEdge], ["Safari LocalStorage", isSafariLocalStorage, detectSafariLocalStorage]]; | |
init(), | |
module.exports = { | |
detectIncognito: detectIncognito, | |
debugIncognito: debugIncognito | |
}; | |
} |
How can I use this?
Please refer to https://medium.com/free-code-camp/disabling-browser-incognito-check-cc84288e89b3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I use this?