Skip to content

Instantly share code, notes, and snippets.

@jeffstephens
Last active July 15, 2016 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffstephens/0cecc83f5e763c8f9c90d1b2243d221a to your computer and use it in GitHub Desktop.
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.
/**
* 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