Last active
July 15, 2016 20:31
-
-
Save jeffstephens/0cecc83f5e763c8f9c90d1b2243d221a to your computer and use it in GitHub Desktop.
Modified "tumblr welcome page" script to hide a custom interstitial rather than redirecting to a custom page.
This file contains 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
/** | |
* Tumblr Welcome Page | |
* | |
* This JS snippet should be installed in your Tumblr theme. | |
* Every new browser session, this will hide the custom interstitial | |
* if the user has already seen it once. | |
*/ | |
$(document).ready( function() { | |
function atBaseUrl() { | |
return window.location.pathname == "/"; | |
} | |
// source: https://mathiasbynens.be/notes/localstorage-pattern | |
var hasStorage = (function() { | |
try { | |
sessionStorage.setItem('mod', 'mod'); | |
sessionStorage.removeItem('mod'); | |
return true; | |
} catch (exception) { | |
return false; | |
} | |
}()); | |
// make sure we support sessionStorage, otherwise do nothing | |
if (hasStorage) { | |
// make sure we're at the root of the current page, otherwise do nothing | |
if (atBaseUrl()) { | |
// if we don't have the sessionStorage entry, create it | |
if (sessionStorage.getItem('visited') === null) { | |
sessionStorage.setItem('visited', 'true'); | |
} else { | |
// otherwise, we've already been here - hide the interstitial immediately | |
$('header.cover').hide(); | |
$('.holder').addClass('visible'); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment