diff --git a/src/scripts/tweaks.json b/src/scripts/tweaks.json index 1050fec4f..3fed2a862 100644 --- a/src/scripts/tweaks.json +++ b/src/scripts/tweaks.json @@ -107,6 +107,11 @@ "type": "checkbox", "label": "Hide the Tumblr Live carousel", "default": false + }, + "following_tab": { + "type": "checkbox", + "label": "Force the default dashboard tab to \"Following\"", + "default": false } } } diff --git a/src/scripts/tweaks/following_tab.js b/src/scripts/tweaks/following_tab.js new file mode 100644 index 000000000..95eb93b76 --- /dev/null +++ b/src/scripts/tweaks/following_tab.js @@ -0,0 +1,27 @@ +import { navigate } from '../../util/tumblr_helpers.js'; + +const attemptRedirect = () => { + if ( + ['/dashboard', '/'].includes(location.pathname) && + document + .querySelector('main > [data-timeline]') + ?.matches('[data-timeline^="/v2/tabs/for_you"]') + ) { + navigate('/dashboard/following'); + } +}; +const observer = new MutationObserver(attemptRedirect); + +export const main = async function () { + attemptRedirect(); + + observer.observe(document.getElementById('root'), { + childList: true, + subtree: true, + attributeFilter: ['data-timeline'] + }); +}; + +export const clean = async function () { + observer.disconnect(); +};