The code powering m.abunchtell.com https://m.abunchtell.com
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

108 行
2.8 KiB

  1. import emojify from 'mastodon/emoji';
  2. import { length } from 'stringz';
  3. import { default as dateFormat } from 'date-fns/format';
  4. import distanceInWordsStrict from 'date-fns/distance_in_words_strict';
  5. import { delegate } from 'rails-ujs';
  6. require.context('../images/', true);
  7. const parseFormat = (format) => format.replace(/%(\w)/g, (_, modifier) => {
  8. switch (modifier) {
  9. case '%':
  10. return '%';
  11. case 'a':
  12. return 'ddd';
  13. case 'A':
  14. return 'ddd';
  15. case 'b':
  16. return 'MMM';
  17. case 'B':
  18. return 'MMMM';
  19. case 'd':
  20. return 'DD';
  21. case 'H':
  22. return 'HH';
  23. case 'I':
  24. return 'hh';
  25. case 'l':
  26. return 'H';
  27. case 'm':
  28. return 'M';
  29. case 'M':
  30. return 'mm';
  31. case 'p':
  32. return 'A';
  33. case 'S':
  34. return 'ss';
  35. case 'w':
  36. return 'd';
  37. case 'y':
  38. return 'YY';
  39. case 'Y':
  40. return 'YYYY';
  41. default:
  42. return `%${modifier}`;
  43. }
  44. });
  45. document.addEventListener('DOMContentLoaded', () => {
  46. for (const content of document.getElementsByClassName('emojify')) {
  47. content.innerHTML = emojify(content.innerHTML);
  48. }
  49. for (const content of document.querySelectorAll('time[data-format]')) {
  50. const format = parseFormat(content.dataset.format);
  51. const formattedDate = dateFormat(content.getAttribute('datetime'), format);
  52. content.textContent = formattedDate;
  53. }
  54. for (const content of document.querySelectorAll('time.time-ago')) {
  55. const timeAgo = distanceInWordsStrict(new Date(), content.getAttribute('datetime'), {
  56. addSuffix: true,
  57. });
  58. content.textContent = timeAgo;
  59. }
  60. delegate(document, '.video-player video', 'click', ({ target }) => {
  61. if (target.paused) {
  62. target.play();
  63. } else {
  64. target.pause();
  65. }
  66. });
  67. delegate(document, '.media-spoiler', 'click', ({ target }) => {
  68. target.style.display = 'none';
  69. });
  70. delegate(document, '.webapp-btn', 'click', ({ target, button }) => {
  71. if (button !== 0) {
  72. return true;
  73. }
  74. window.location.href = target.href;
  75. return false;
  76. });
  77. delegate(document, '.status__content__spoiler-link', 'click', ({ target }) => {
  78. const contentEl = target.parentNode.parentNode.querySelector('.e-content');
  79. if (contentEl.style.display === 'block') {
  80. contentEl.style.display = 'none';
  81. target.parentNode.style.marginBottom = 0;
  82. } else {
  83. contentEl.style.display = 'block';
  84. target.parentNode.style.marginBottom = null;
  85. }
  86. return false;
  87. });
  88. delegate(document, '.account_display_name', 'input', ({ target }) => {
  89. const [nameCounter, ] = document.getElementsByClassName('name-counter');
  90. nameCounter.textContent = 30 - length(target.value);
  91. });
  92. delegate(document, '.account_note', 'input', ({ target }) => {
  93. const [noteCounter, ] = document.getElementsByClassName('.note-counter');
  94. noteCounter.textContent = 160 - length(target.value);
  95. });
  96. });