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.

75 lines
2.8 KiB

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