You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.7 KiB

  1. // @ts-check
  2. /**
  3. * @typedef Emoji
  4. * @property {string} shortcode
  5. * @property {string} static_url
  6. * @property {string} url
  7. */
  8. /**
  9. * @typedef AccountField
  10. * @property {string} name
  11. * @property {string} value
  12. * @property {string} verified_at
  13. */
  14. /**
  15. * @typedef Account
  16. * @property {string} acct
  17. * @property {string} avatar
  18. * @property {string} avatar_static
  19. * @property {boolean} bot
  20. * @property {string} created_at
  21. * @property {boolean=} discoverable
  22. * @property {string} display_name
  23. * @property {Emoji[]} emojis
  24. * @property {AccountField[]} fields
  25. * @property {number} followers_count
  26. * @property {number} following_count
  27. * @property {boolean} group
  28. * @property {string} header
  29. * @property {string} header_static
  30. * @property {string} id
  31. * @property {string=} last_status_at
  32. * @property {boolean} locked
  33. * @property {string} note
  34. * @property {number} statuses_count
  35. * @property {string} url
  36. * @property {string} username
  37. */
  38. /**
  39. * @typedef {[code: string, name: string, localName: string]} InitialStateLanguage
  40. */
  41. /**
  42. * @typedef InitialStateMeta
  43. * @property {string} access_token
  44. * @property {boolean=} advanced_layout
  45. * @property {boolean} auto_play_gif
  46. * @property {boolean} activity_api_enabled
  47. * @property {string} admin
  48. * @property {boolean=} boost_modal
  49. * @property {boolean} crop_images
  50. * @property {boolean=} delete_modal
  51. * @property {boolean=} disable_swiping
  52. * @property {string=} disabled_account_id
  53. * @property {boolean} display_media
  54. * @property {string} domain
  55. * @property {boolean=} expand_spoilers
  56. * @property {boolean} limited_federation_mode
  57. * @property {string} locale
  58. * @property {string | null} mascot
  59. * @property {string=} me
  60. * @property {string=} moved_to_account_id
  61. * @property {string=} owner
  62. * @property {boolean} profile_directory
  63. * @property {boolean} registrations_open
  64. * @property {boolean} reduce_motion
  65. * @property {string} repository
  66. * @property {boolean} search_enabled
  67. * @property {boolean} single_user_mode
  68. * @property {string} source_url
  69. * @property {string} streaming_api_base_url
  70. * @property {boolean} timeline_preview
  71. * @property {string} title
  72. * @property {boolean} trends
  73. * @property {boolean} trends_as_landing_page
  74. * @property {boolean} unfollow_modal
  75. * @property {boolean} use_blurhash
  76. * @property {boolean=} use_pending_items
  77. * @property {string} version
  78. */
  79. /**
  80. * @typedef InitialState
  81. * @property {Record<string, Account>} accounts
  82. * @property {InitialStateLanguage[]} languages
  83. * @property {InitialStateMeta} meta
  84. */
  85. const element = document.getElementById('initial-state');
  86. /** @type {InitialState | undefined} */
  87. const initialState = element?.textContent && JSON.parse(element.textContent);
  88. /**
  89. * @template {keyof InitialStateMeta} K
  90. * @param {K} prop
  91. * @returns {InitialStateMeta[K] | undefined}
  92. */
  93. const getMeta = (prop) => initialState?.meta && initialState.meta[prop];
  94. export const activityApiEnabled = getMeta('activity_api_enabled');
  95. export const autoPlayGif = getMeta('auto_play_gif');
  96. export const boostModal = getMeta('boost_modal');
  97. export const cropImages = getMeta('crop_images');
  98. export const deleteModal = getMeta('delete_modal');
  99. export const disableSwiping = getMeta('disable_swiping');
  100. export const disabledAccountId = getMeta('disabled_account_id');
  101. export const displayMedia = getMeta('display_media');
  102. export const domain = getMeta('domain');
  103. export const expandSpoilers = getMeta('expand_spoilers');
  104. export const forceSingleColumn = !getMeta('advanced_layout');
  105. export const limitedFederationMode = getMeta('limited_federation_mode');
  106. export const mascot = getMeta('mascot');
  107. export const me = getMeta('me');
  108. export const movedToAccountId = getMeta('moved_to_account_id');
  109. export const owner = getMeta('owner');
  110. export const profile_directory = getMeta('profile_directory');
  111. export const reduceMotion = getMeta('reduce_motion');
  112. export const registrationsOpen = getMeta('registrations_open');
  113. export const repository = getMeta('repository');
  114. export const searchEnabled = getMeta('search_enabled');
  115. export const showTrends = getMeta('trends');
  116. export const singleUserMode = getMeta('single_user_mode');
  117. export const source_url = getMeta('source_url');
  118. export const timelinePreview = getMeta('timeline_preview');
  119. export const title = getMeta('title');
  120. export const trendsAsLanding = getMeta('trends_as_landing_page');
  121. export const unfollowModal = getMeta('unfollow_modal');
  122. export const useBlurhash = getMeta('use_blurhash');
  123. export const usePendingItems = getMeta('use_pending_items');
  124. export const version = getMeta('version');
  125. export const languages = initialState?.languages;
  126. export const statusPageUrl = getMeta('status_page_url');
  127. // Glitch-soc-specific settings
  128. export const maxChars = (initialState && initialState.max_toot_chars) || 500;
  129. export default initialState;