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.

69 lines
2.4 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 React = require('react');
  9. const ReactDOM = require('react-dom');
  10. localeData.forEach(IntlRelativeFormat.__addLocaleData);
  11. ready(() => {
  12. const locale = document.documentElement.lang;
  13. const dateTimeFormat = new Intl.DateTimeFormat(locale, {
  14. year: 'numeric',
  15. month: 'long',
  16. day: 'numeric',
  17. hour: 'numeric',
  18. minute: 'numeric',
  19. });
  20. const relativeFormat = new IntlRelativeFormat(locale);
  21. [].forEach.call(document.querySelectorAll('.emojify'), (content) => {
  22. content.innerHTML = emojify(content.innerHTML);
  23. });
  24. [].forEach.call(document.querySelectorAll('time.formatted'), (content) => {
  25. const datetime = new Date(content.getAttribute('datetime'));
  26. const formattedDate = dateTimeFormat.format(datetime);
  27. content.title = formattedDate;
  28. content.textContent = formattedDate;
  29. });
  30. [].forEach.call(document.querySelectorAll('time.time-ago'), (content) => {
  31. const datetime = new Date(content.getAttribute('datetime'));
  32. content.title = dateTimeFormat.format(datetime);
  33. content.textContent = relativeFormat.format(datetime);
  34. });
  35. [].forEach.call(document.querySelectorAll('.logo-button'), (content) => {
  36. content.addEventListener('click', (e) => {
  37. e.preventDefault();
  38. window.open(e.target.href, 'mastodon-intent', 'width=400,height=400,resizable=no,menubar=no,status=no,scrollbars=yes');
  39. });
  40. });
  41. const reactComponents = document.querySelectorAll('[data-component]');
  42. if (reactComponents.length > 0) {
  43. import(/* webpackChunkName: "containers/media_container" */ '../mastodon/containers/media_container')
  44. .then(({ default: MediaContainer }) => {
  45. const content = document.createElement('div');
  46. ReactDOM.render(<MediaContainer locale={locale} components={reactComponents} />, content);
  47. document.body.appendChild(content);
  48. })
  49. .catch(error => console.error(error));
  50. }
  51. });
  52. }
  53. loadPolyfills().then(main).catch(error => {
  54. console.error(error);
  55. });