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.

79 lines
2.9 KiB

  1. import loadPolyfills from '../mastodon/load_polyfills';
  2. import ready from '../mastodon/ready';
  3. function main() {
  4. const IntlRelativeFormat = require('intl-relativeformat').default;
  5. const emojify = require('../mastodon/features/emoji/emoji').default;
  6. const { getLocale } = require('../mastodon/locales');
  7. const { localeData } = getLocale();
  8. const VideoContainer = require('../mastodon/containers/video_container').default;
  9. const CardContainer = require('../mastodon/containers/card_container').default;
  10. const React = require('react');
  11. const ReactDOM = require('react-dom');
  12. localeData.forEach(IntlRelativeFormat.__addLocaleData);
  13. ready(() => {
  14. const locale = document.documentElement.lang;
  15. const dateTimeFormat = new Intl.DateTimeFormat(locale, {
  16. year: 'numeric',
  17. month: 'long',
  18. day: 'numeric',
  19. hour: 'numeric',
  20. minute: 'numeric',
  21. });
  22. const relativeFormat = new IntlRelativeFormat(locale);
  23. [].forEach.call(document.querySelectorAll('.emojify'), (content) => {
  24. content.innerHTML = emojify(content.innerHTML);
  25. });
  26. [].forEach.call(document.querySelectorAll('time.formatted'), (content) => {
  27. const datetime = new Date(content.getAttribute('datetime'));
  28. const formattedDate = dateTimeFormat.format(datetime);
  29. content.title = formattedDate;
  30. content.textContent = formattedDate;
  31. });
  32. [].forEach.call(document.querySelectorAll('time.time-ago'), (content) => {
  33. const datetime = new Date(content.getAttribute('datetime'));
  34. content.title = dateTimeFormat.format(datetime);
  35. content.textContent = relativeFormat.format(datetime);
  36. });
  37. [].forEach.call(document.querySelectorAll('.logo-button'), (content) => {
  38. content.addEventListener('click', (e) => {
  39. e.preventDefault();
  40. window.open(e.target.href, 'mastodon-intent', 'width=400,height=400,resizable=no,menubar=no,status=no,scrollbars=yes');
  41. });
  42. });
  43. [].forEach.call(document.querySelectorAll('[data-component="Video"]'), (content) => {
  44. const props = JSON.parse(content.getAttribute('data-props'));
  45. ReactDOM.render(<VideoContainer locale={locale} {...props} />, content);
  46. });
  47. [].forEach.call(document.querySelectorAll('[data-component="Card"]'), (content) => {
  48. const props = JSON.parse(content.getAttribute('data-props'));
  49. ReactDOM.render(<CardContainer locale={locale} {...props} />, content);
  50. });
  51. const mediaGalleries = document.querySelectorAll('[data-component="MediaGallery"]');
  52. if (mediaGalleries.length > 0) {
  53. const MediaGalleriesContainer = require('../mastodon/containers/media_galleries_container').default;
  54. const content = document.createElement('div');
  55. ReactDOM.render(<MediaGalleriesContainer locale={locale} galleries={mediaGalleries} />, content);
  56. document.body.appendChild(content);
  57. }
  58. });
  59. }
  60. loadPolyfills().then(main).catch(error => {
  61. console.error(error);
  62. });