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.

97 lines
3.2 KiB

  1. import loadPolyfills from '../mastodon/load_polyfills';
  2. import { processBio } from '../glitch/util/bio_metadata';
  3. function main() {
  4. const { length } = require('stringz');
  5. const IntlRelativeFormat = require('intl-relativeformat').default;
  6. const { delegate } = require('rails-ujs');
  7. const emojify = require('../mastodon/emoji').default;
  8. const { getLocale } = require('../mastodon/locales');
  9. const ready = require('../mastodon/ready').default;
  10. const { localeData } = getLocale();
  11. localeData.forEach(IntlRelativeFormat.__addLocaleData);
  12. ready(() => {
  13. const locale = document.documentElement.lang;
  14. const dateTimeFormat = new Intl.DateTimeFormat(locale, {
  15. year: 'numeric',
  16. month: 'long',
  17. day: 'numeric',
  18. hour: 'numeric',
  19. minute: 'numeric',
  20. });
  21. const relativeFormat = new IntlRelativeFormat(locale);
  22. [].forEach.call(document.querySelectorAll('.emojify'), (content) => {
  23. content.innerHTML = emojify(content.innerHTML);
  24. });
  25. [].forEach.call(document.querySelectorAll('time.formatted'), (content) => {
  26. const datetime = new Date(content.getAttribute('datetime'));
  27. const formattedDate = dateTimeFormat.format(datetime);
  28. content.title = formattedDate;
  29. content.textContent = formattedDate;
  30. });
  31. [].forEach.call(document.querySelectorAll('time.time-ago'), (content) => {
  32. const datetime = new Date(content.getAttribute('datetime'));
  33. content.textContent = relativeFormat.format(datetime);
  34. });
  35. });
  36. delegate(document, '.video-player video', 'click', ({ target }) => {
  37. if (target.paused) {
  38. target.play();
  39. } else {
  40. target.pause();
  41. }
  42. });
  43. delegate(document, '.activity-stream .media-spoiler-wrapper .media-spoiler', 'click', function() {
  44. this.parentNode.classList.add('media-spoiler-wrapper__visible');
  45. });
  46. delegate(document, '.activity-stream .media-spoiler-wrapper .spoiler-button', 'click', function() {
  47. this.parentNode.classList.remove('media-spoiler-wrapper__visible');
  48. });
  49. delegate(document, '.webapp-btn', 'click', ({ target, button }) => {
  50. if (button !== 0) {
  51. return true;
  52. }
  53. window.location.href = target.href;
  54. return false;
  55. });
  56. delegate(document, '.status__content__spoiler-link', 'click', ({ target }) => {
  57. const contentEl = target.parentNode.parentNode.querySelector('.e-content');
  58. if (contentEl.style.display === 'block') {
  59. contentEl.style.display = 'none';
  60. target.parentNode.style.marginBottom = 0;
  61. } else {
  62. contentEl.style.display = 'block';
  63. target.parentNode.style.marginBottom = null;
  64. }
  65. return false;
  66. });
  67. delegate(document, '.account_display_name', 'input', ({ target }) => {
  68. const nameCounter = document.querySelector('.name-counter');
  69. if (nameCounter) {
  70. nameCounter.textContent = 30 - length(target.value);
  71. }
  72. });
  73. delegate(document, '.account_note', 'input', ({ target }) => {
  74. const noteCounter = document.querySelector('.note-counter');
  75. if (noteCounter) {
  76. const noteWithoutMetadata = processBio(target.value).text;
  77. noteCounter.textContent = 500 - length(noteWithoutMetadata);
  78. }
  79. });
  80. }
  81. loadPolyfills().then(main).catch(error => {
  82. console.error(error);
  83. });