initial_state.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // @ts-check
  2. /**
  3. * @typedef {[code: string, name: string, localName: string]} InitialStateLanguage
  4. */
  5. /**
  6. * @typedef InitialStateMeta
  7. * @property {string} access_token
  8. * @property {boolean=} advanced_layout
  9. * @property {boolean} auto_play_gif
  10. * @property {boolean} activity_api_enabled
  11. * @property {string} admin
  12. * @property {boolean=} boost_modal
  13. * @property {boolean=} delete_modal
  14. * @property {boolean=} disable_swiping
  15. * @property {string=} disabled_account_id
  16. * @property {string} display_media
  17. * @property {string} domain
  18. * @property {boolean=} expand_spoilers
  19. * @property {boolean} limited_federation_mode
  20. * @property {string} locale
  21. * @property {string | null} mascot
  22. * @property {string=} me
  23. * @property {string=} moved_to_account_id
  24. * @property {string=} owner
  25. * @property {boolean} profile_directory
  26. * @property {boolean} registrations_open
  27. * @property {boolean} reduce_motion
  28. * @property {string} repository
  29. * @property {boolean} search_enabled
  30. * @property {boolean} trends_enabled
  31. * @property {boolean} single_user_mode
  32. * @property {string} source_url
  33. * @property {string} streaming_api_base_url
  34. * @property {boolean} timeline_preview
  35. * @property {string} title
  36. * @property {boolean} show_trends
  37. * @property {boolean} trends_as_landing_page
  38. * @property {boolean} unfollow_modal
  39. * @property {boolean} use_blurhash
  40. * @property {boolean=} use_pending_items
  41. * @property {string} version
  42. * @property {string} sso_redirect
  43. */
  44. /**
  45. * @typedef InitialState
  46. * @property {Record<string, import("./api_types/accounts").ApiAccountJSON>} accounts
  47. * @property {InitialStateLanguage[]} languages
  48. * @property {boolean=} critical_updates_pending
  49. * @property {InitialStateMeta} meta
  50. */
  51. const element = document.getElementById('initial-state');
  52. /** @type {InitialState | undefined} */
  53. const initialState = element?.textContent && JSON.parse(element.textContent);
  54. /** @type {string} */
  55. const initialPath = document.querySelector("head meta[name=initialPath]")?.getAttribute("content") ?? '';
  56. /** @type {boolean} */
  57. export const hasMultiColumnPath = initialPath === '/'
  58. || initialPath === '/getting-started'
  59. || initialPath === '/home'
  60. || initialPath.startsWith('/deck');
  61. /**
  62. * @template {keyof InitialStateMeta} K
  63. * @param {K} prop
  64. * @returns {InitialStateMeta[K] | undefined}
  65. */
  66. const getMeta = (prop) => initialState?.meta && initialState.meta[prop];
  67. export const activityApiEnabled = getMeta('activity_api_enabled');
  68. export const autoPlayGif = getMeta('auto_play_gif');
  69. export const boostModal = getMeta('boost_modal');
  70. export const deleteModal = getMeta('delete_modal');
  71. export const disableSwiping = getMeta('disable_swiping');
  72. export const disabledAccountId = getMeta('disabled_account_id');
  73. export const displayMedia = getMeta('display_media');
  74. export const domain = getMeta('domain');
  75. export const expandSpoilers = getMeta('expand_spoilers');
  76. export const forceSingleColumn = !getMeta('advanced_layout');
  77. export const limitedFederationMode = getMeta('limited_federation_mode');
  78. export const mascot = getMeta('mascot');
  79. export const me = getMeta('me');
  80. export const movedToAccountId = getMeta('moved_to_account_id');
  81. export const owner = getMeta('owner');
  82. export const profile_directory = getMeta('profile_directory');
  83. export const reduceMotion = getMeta('reduce_motion');
  84. export const registrationsOpen = getMeta('registrations_open');
  85. export const repository = getMeta('repository');
  86. export const searchEnabled = getMeta('search_enabled');
  87. export const trendsEnabled = getMeta('trends_enabled');
  88. export const showTrends = getMeta('show_trends');
  89. export const singleUserMode = getMeta('single_user_mode');
  90. export const source_url = getMeta('source_url');
  91. export const timelinePreview = getMeta('timeline_preview');
  92. export const title = getMeta('title');
  93. export const trendsAsLanding = getMeta('trends_as_landing_page');
  94. export const unfollowModal = getMeta('unfollow_modal');
  95. export const useBlurhash = getMeta('use_blurhash');
  96. export const usePendingItems = getMeta('use_pending_items');
  97. export const version = getMeta('version');
  98. export const languages = initialState?.languages;
  99. export const criticalUpdatesPending = initialState?.critical_updates_pending;
  100. // @ts-expect-error
  101. export const statusPageUrl = getMeta('status_page_url');
  102. export const sso_redirect = getMeta('sso_redirect');
  103. export default initialState;