The code powering m.abunchtell.com https://m.abunchtell.com
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

108 righe
2.4 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. window.jQuery = window.$ = require('jquery');
  6. require('jquery-ujs');
  7. require.context('../images/', true);
  8. const parseFormat = (format) => format.replace(/%(\w)/g, (_, modifier) => {
  9. switch (modifier) {
  10. case '%':
  11. return '%';
  12. case 'a':
  13. return 'ddd';
  14. case 'A':
  15. return 'ddd';
  16. case 'b':
  17. return 'MMM';
  18. case 'B':
  19. return 'MMMM';
  20. case 'd':
  21. return 'DD';
  22. case 'H':
  23. return 'HH';
  24. case 'I':
  25. return 'hh';
  26. case 'l':
  27. return 'H';
  28. case 'm':
  29. return 'M';
  30. case 'M':
  31. return 'mm';
  32. case 'p':
  33. return 'A';
  34. case 'S':
  35. return 'ss';
  36. case 'w':
  37. return 'd';
  38. case 'y':
  39. return 'YY';
  40. case 'Y':
  41. return 'YYYY';
  42. default:
  43. return `%${modifier}`;
  44. }
  45. });
  46. $(() => {
  47. $.each($('.emojify'), (_, content) => {
  48. const $content = $(content);
  49. $content.html(emojify($content.html()));
  50. });
  51. $('time[data-format]').each((_, content) => {
  52. const $content = $(content);
  53. const format = parseFormat($content.data('format'));
  54. const formattedDate = dateFormat($content.attr('datetime'), format);
  55. $content.text(formattedDate);
  56. });
  57. $('time.time-ago').each((_, content) => {
  58. const $content = $(content);
  59. const timeAgo = distanceInWordsStrict(new Date(), $content.attr('datetime'), { addSuffix: true });
  60. $content.text(timeAgo);
  61. });
  62. $('.video-player video').on('click', e => {
  63. if (e.target.paused) {
  64. e.target.play();
  65. } else {
  66. e.target.pause();
  67. }
  68. });
  69. $('.media-spoiler').on('click', e => {
  70. $(e.target).hide();
  71. });
  72. $('.webapp-btn').on('click', e => {
  73. if (e.button === 0) {
  74. e.preventDefault();
  75. window.location.href = $(e.target).attr('href');
  76. }
  77. });
  78. $('.status__content__spoiler-link').on('click', e => {
  79. e.preventDefault();
  80. const contentEl = $(e.target).parent().parent().find('div');
  81. if (contentEl.is(':visible')) {
  82. contentEl.hide();
  83. $(e.target).parent().attr('style', 'margin-bottom: 0');
  84. } else {
  85. contentEl.show();
  86. $(e.target).parent().attr('style', null);
  87. }
  88. });
  89. $('.account_display_name').on('input', e => {
  90. $('.name-counter').text(30 - length($(e.target).val()));
  91. });
  92. $('.account_note').on('input', e => {
  93. $('.note-counter').text(160 - length($(e.target).val()));
  94. });
  95. });