Last active
June 3, 2024 00:22
-
-
Save marcustyphoon/75e45dfe9395e5c1c00f703680c17b0c to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name Tumblr Blog Subs Default | |
// @namespace gist.github.com/marcustyphoon | |
// @version 0.2 | |
// @description Forces the default Tumblr dashboard tab to "Blog Subs" | |
// @author marcustyphoon | |
// @match https://www.tumblr.com/* | |
// @grant none | |
// @noframes | |
// ==/UserScript== | |
/* globals tumblr */ | |
/* eslint-disable no-unmodified-loop-condition */ | |
(async function () { | |
'use strict'; | |
let retries = 0; | |
while (typeof tumblr === 'undefined' || typeof tumblr.navigate === 'undefined') { | |
if (retries++ > 1000) return; | |
await new Promise((resolve) => setTimeout(resolve)); | |
} | |
const attemptRedirect = () => { | |
if ( | |
['/dashboard', '/'].includes(location.pathname) && | |
document | |
.querySelector('main > :is([data-timeline], [data-timeline-id])') | |
?.matches( | |
'[data-timeline^="/v2/timeline/dashboard"], [data-timeline^="/v2/tabs/for_you"], [data-timeline-id="/dashboard/following"], [data-timeline-id="/dashboard/stuff_for_you"]', | |
) | |
) { | |
tumblr.navigate('/dashboard/blog_subs'); | |
} | |
}; | |
attemptRedirect(); | |
new MutationObserver(attemptRedirect).observe(document.getElementById('root'), { | |
childList: true, | |
subtree: true, | |
attributeFilter: ['data-timeline', 'data-timeline-id'], | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment