app.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. require('./polyfill');
  2. window._ = require('lodash');
  3. window.Popper = require('popper.js').default;
  4. window.pixelfed = window.pixelfed || {};
  5. window.$ = window.jQuery = require('jquery');
  6. require('bootstrap');
  7. window.axios = require('axios');
  8. window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
  9. require('readmore-js');
  10. window.blurhash = require("blurhash");
  11. let token = document.head.querySelector('meta[name="csrf-token"]');
  12. if (token) {
  13. window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
  14. } else {
  15. console.error('CSRF token not found.');
  16. }
  17. window.App = window.App || {};
  18. window.App.redirect = function() {
  19. document.querySelectorAll('a').forEach(function(i,k) {
  20. let a = i.getAttribute('href');
  21. if(a && a.length > 5 && a.startsWith('https://')) {
  22. let url = new URL(a);
  23. if(url.host !== window.location.host && url.pathname !== '/i/redirect') {
  24. i.setAttribute('href', '/i/redirect?url=' + encodeURIComponent(a));
  25. }
  26. }
  27. });
  28. }
  29. window.App.boot = function() {
  30. new Vue({ el: '#content'});
  31. }
  32. window.App.util = {
  33. compose: {
  34. post: (function() {
  35. let path = window.location.pathname;
  36. let whitelist = [
  37. '/',
  38. '/timeline/public'
  39. ];
  40. if(whitelist.includes(path)) {
  41. $('#composeModal').modal('show');
  42. } else {
  43. window.location.href = '/?a=co';
  44. }
  45. }),
  46. circle: (function() {
  47. console.log('Unsupported method.');
  48. }),
  49. collection: (function() {
  50. console.log('Unsupported method.');
  51. }),
  52. loop: (function() {
  53. console.log('Unsupported method.');
  54. }),
  55. story: (function() {
  56. console.log('Unsupported method.');
  57. }),
  58. },
  59. time: (function() {
  60. return new Date;
  61. }),
  62. version: 1,
  63. format: {
  64. count: (function(count = 0, locale = 'en-GB', notation = 'compact') {
  65. if(count < 1) {
  66. return 0;
  67. }
  68. return new Intl.NumberFormat(locale, { notation: notation , compactDisplay: "short" }).format(count);
  69. }),
  70. timeAgo: (function(ts) {
  71. let date = Date.parse(ts);
  72. let seconds = Math.floor((new Date() - date) / 1000);
  73. let interval = Math.floor(seconds / 63072000);
  74. if (interval >= 1) {
  75. return interval + "y";
  76. }
  77. interval = Math.floor(seconds / 604800);
  78. if (interval >= 1) {
  79. return interval + "w";
  80. }
  81. interval = Math.floor(seconds / 86400);
  82. if (interval >= 1) {
  83. return interval + "d";
  84. }
  85. interval = Math.floor(seconds / 3600);
  86. if (interval >= 1) {
  87. return interval + "h";
  88. }
  89. interval = Math.floor(seconds / 60);
  90. if (interval >= 1) {
  91. return interval + "m";
  92. }
  93. return Math.floor(seconds) + "s";
  94. }),
  95. rewriteLinks: (function(i) {
  96. let tag = i.innerText;
  97. if(i.href.startsWith(window.location.origin)) {
  98. return i.href;
  99. }
  100. if(tag.startsWith('#') == true) {
  101. tag = '/discover/tags/' + tag.substr(1) +'?src=rph';
  102. } else if(tag.startsWith('@') == true) {
  103. tag = '/' + i.innerText + '?src=rpp';
  104. } else {
  105. tag = '/i/redirect?url=' + encodeURIComponent(tag);
  106. }
  107. return tag;
  108. })
  109. },
  110. filters: [
  111. ['1977','filter-1977'],
  112. ['Aden','filter-aden'],
  113. ['Amaro','filter-amaro'],
  114. ['Ashby','filter-ashby'],
  115. ['Brannan','filter-brannan'],
  116. ['Brooklyn','filter-brooklyn'],
  117. ['Charmes','filter-charmes'],
  118. ['Clarendon','filter-clarendon'],
  119. ['Crema','filter-crema'],
  120. ['Dogpatch','filter-dogpatch'],
  121. ['Earlybird','filter-earlybird'],
  122. ['Gingham','filter-gingham'],
  123. ['Ginza','filter-ginza'],
  124. ['Hefe','filter-hefe'],
  125. ['Helena','filter-helena'],
  126. ['Hudson','filter-hudson'],
  127. ['Inkwell','filter-inkwell'],
  128. ['Kelvin','filter-kelvin'],
  129. ['Kuno','filter-juno'],
  130. ['Lark','filter-lark'],
  131. ['Lo-Fi','filter-lofi'],
  132. ['Ludwig','filter-ludwig'],
  133. ['Maven','filter-maven'],
  134. ['Mayfair','filter-mayfair'],
  135. ['Moon','filter-moon'],
  136. ['Nashville','filter-nashville'],
  137. ['Perpetua','filter-perpetua'],
  138. ['Poprocket','filter-poprocket'],
  139. ['Reyes','filter-reyes'],
  140. ['Rise','filter-rise'],
  141. ['Sierra','filter-sierra'],
  142. ['Skyline','filter-skyline'],
  143. ['Slumber','filter-slumber'],
  144. ['Stinson','filter-stinson'],
  145. ['Sutro','filter-sutro'],
  146. ['Toaster','filter-toaster'],
  147. ['Valencia','filter-valencia'],
  148. ['Vesper','filter-vesper'],
  149. ['Walden','filter-walden'],
  150. ['Willow','filter-willow'],
  151. ['X-Pro II','filter-xpro-ii']
  152. ],
  153. filterCss: {
  154. 'filter-1977': 'sepia(.5) hue-rotate(-30deg) saturate(1.4)',
  155. 'filter-aden': 'sepia(.2) brightness(1.15) saturate(1.4)',
  156. 'filter-amaro': 'sepia(.35) contrast(1.1) brightness(1.2) saturate(1.3)',
  157. 'filter-ashby': 'sepia(.5) contrast(1.2) saturate(1.8)',
  158. 'filter-brannan': 'sepia(.4) contrast(1.25) brightness(1.1) saturate(.9) hue-rotate(-2deg)',
  159. 'filter-brooklyn': 'sepia(.25) contrast(1.25) brightness(1.25) hue-rotate(5deg)',
  160. 'filter-charmes': 'sepia(.25) contrast(1.25) brightness(1.25) saturate(1.35) hue-rotate(-5deg)',
  161. 'filter-clarendon': 'sepia(.15) contrast(1.25) brightness(1.25) hue-rotate(5deg)',
  162. 'filter-crema': 'sepia(.5) contrast(1.25) brightness(1.15) saturate(.9) hue-rotate(-2deg)',
  163. 'filter-dogpatch': 'sepia(.35) saturate(1.1) contrast(1.5)',
  164. 'filter-earlybird': 'sepia(.25) contrast(1.25) brightness(1.15) saturate(.9) hue-rotate(-5deg)',
  165. 'filter-gingham': 'contrast(1.1) brightness(1.1)',
  166. 'filter-ginza': 'sepia(.25) contrast(1.15) brightness(1.2) saturate(1.35) hue-rotate(-5deg)',
  167. 'filter-hefe': 'sepia(.4) contrast(1.5) brightness(1.2) saturate(1.4) hue-rotate(-10deg)',
  168. 'filter-helena': 'sepia(.5) contrast(1.05) brightness(1.05) saturate(1.35)',
  169. 'filter-hudson': 'sepia(.25) contrast(1.2) brightness(1.2) saturate(1.05) hue-rotate(-15deg)',
  170. 'filter-inkwell': 'brightness(1.25) contrast(.85) grayscale(1)',
  171. 'filter-kelvin': 'sepia(.15) contrast(1.5) brightness(1.1) hue-rotate(-10deg)',
  172. 'filter-juno': 'sepia(.35) contrast(1.15) brightness(1.15) saturate(1.8)',
  173. 'filter-lark': 'sepia(.25) contrast(1.2) brightness(1.3) saturate(1.25)',
  174. 'filter-lofi': 'saturate(1.1) contrast(1.5)',
  175. 'filter-ludwig': 'sepia(.25) contrast(1.05) brightness(1.05) saturate(2)',
  176. 'filter-maven': 'sepia(.35) contrast(1.05) brightness(1.05) saturate(1.75)',
  177. 'filter-mayfair': 'contrast(1.1) brightness(1.15) saturate(1.1)',
  178. 'filter-moon': 'brightness(1.4) contrast(.95) saturate(0) sepia(.35)',
  179. 'filter-nashville': 'sepia(.25) contrast(1.5) brightness(.9) hue-rotate(-15deg)',
  180. 'filter-perpetua': 'contrast(1.1) brightness(1.25) saturate(1.1)',
  181. 'filter-poprocket': 'sepia(.15) brightness(1.2)',
  182. 'filter-reyes': 'sepia(.75) contrast(.75) brightness(1.25) saturate(1.4)',
  183. 'filter-rise': 'sepia(.25) contrast(1.25) brightness(1.2) saturate(.9)',
  184. 'filter-sierra': 'sepia(.25) contrast(1.5) brightness(.9) hue-rotate(-15deg)',
  185. 'filter-skyline': 'sepia(.15) contrast(1.25) brightness(1.25) saturate(1.2)',
  186. 'filter-slumber': 'sepia(.35) contrast(1.25) saturate(1.25)',
  187. 'filter-stinson': 'sepia(.35) contrast(1.25) brightness(1.1) saturate(1.25)',
  188. 'filter-sutro': 'sepia(.4) contrast(1.2) brightness(.9) saturate(1.4) hue-rotate(-10deg)',
  189. 'filter-toaster': 'sepia(.25) contrast(1.5) brightness(.95) hue-rotate(-15deg)',
  190. 'filter-valencia': 'sepia(.25) contrast(1.1) brightness(1.1)',
  191. 'filter-vesper': 'sepia(.35) contrast(1.15) brightness(1.2) saturate(1.3)',
  192. 'filter-walden': 'sepia(.35) contrast(.8) brightness(1.25) saturate(1.4)',
  193. 'filter-willow': 'brightness(1.2) contrast(.85) saturate(.05) sepia(.2)',
  194. 'filter-xpro-ii': 'sepia(.45) contrast(1.25) brightness(1.75) saturate(1.3) hue-rotate(-5deg)'
  195. },
  196. emoji: ['๐Ÿ˜‚','๐Ÿ’ฏ','โค๏ธ','๐Ÿ™Œ','๐Ÿ‘','๐Ÿ‘Œ','๐Ÿ˜','๐Ÿ˜ฏ','๐Ÿ˜ข','๐Ÿ˜…','๐Ÿ˜','๐Ÿ™‚','๐Ÿ˜Ž','๐Ÿ˜€','๐Ÿคฃ','๐Ÿ˜ƒ','๐Ÿ˜„','๐Ÿ˜†','๐Ÿ˜‰','๐Ÿ˜Š','๐Ÿ˜‹','๐Ÿ˜˜','๐Ÿ˜—','๐Ÿ˜™','๐Ÿ˜š','๐Ÿค—','๐Ÿคฉ','๐Ÿค”','๐Ÿคจ','๐Ÿ˜','๐Ÿ˜‘','๐Ÿ˜ถ','๐Ÿ™„','๐Ÿ˜','๐Ÿ˜ฃ','๐Ÿ˜ฅ','๐Ÿ˜ฎ','๐Ÿค','๐Ÿ˜ช','๐Ÿ˜ซ','๐Ÿ˜ด','๐Ÿ˜Œ','๐Ÿ˜›','๐Ÿ˜œ','๐Ÿ˜','๐Ÿคค','๐Ÿ˜’','๐Ÿ˜“','๐Ÿ˜”','๐Ÿ˜•','๐Ÿ™ƒ','๐Ÿค‘','๐Ÿ˜ฒ','๐Ÿ™','๐Ÿ˜–','๐Ÿ˜ž','๐Ÿ˜Ÿ','๐Ÿ˜ค','๐Ÿ˜ญ','๐Ÿ˜ฆ','๐Ÿ˜ง','๐Ÿ˜จ','๐Ÿ˜ฉ','๐Ÿคฏ','๐Ÿ˜ฌ','๐Ÿ˜ฐ','๐Ÿ˜ฑ','๐Ÿ˜ณ','๐Ÿคช','๐Ÿ˜ต','๐Ÿ˜ก','๐Ÿ˜ ','๐Ÿคฌ','๐Ÿ˜ท','๐Ÿค’','๐Ÿค•','๐Ÿคข','๐Ÿคฎ','๐Ÿคง','๐Ÿ˜‡','๐Ÿค ','๐Ÿคก','๐Ÿคฅ','๐Ÿคซ','๐Ÿคญ','๐Ÿง','๐Ÿค“','๐Ÿ˜ˆ','๐Ÿ‘ฟ','๐Ÿ‘น','๐Ÿ‘บ','๐Ÿ’€','๐Ÿ‘ป','๐Ÿ‘ฝ','๐Ÿค–','๐Ÿ’ฉ','๐Ÿ˜บ','๐Ÿ˜ธ','๐Ÿ˜น','๐Ÿ˜ป','๐Ÿ˜ผ','๐Ÿ˜ฝ','๐Ÿ™€','๐Ÿ˜ฟ','๐Ÿ˜พ','๐Ÿคฒ','๐Ÿ‘','๐Ÿค','๐Ÿ‘','๐Ÿ‘Ž','๐Ÿ‘Š','โœŠ','๐Ÿค›','๐Ÿคœ','๐Ÿคž','โœŒ๏ธ','๐ŸคŸ','๐Ÿค˜','๐Ÿ‘ˆ','๐Ÿ‘‰','๐Ÿ‘†','๐Ÿ‘‡','โ˜๏ธ','โœ‹','๐Ÿคš','๐Ÿ–','๐Ÿ––','๐Ÿ‘‹','๐Ÿค™','๐Ÿ’ช','๐Ÿ–•','โœ๏ธ','๐Ÿ™','๐Ÿ’','๐Ÿ’„','๐Ÿ’‹','๐Ÿ‘„','๐Ÿ‘…','๐Ÿ‘‚','๐Ÿ‘ƒ','๐Ÿ‘ฃ','๐Ÿ‘','๐Ÿ‘€','๐Ÿง ','๐Ÿ—ฃ','๐Ÿ‘ค','๐Ÿ‘ฅ'
  197. ],
  198. embed: {
  199. post: (function(url, caption = true, likes = false, layout = 'full') {
  200. let u = url + '/embed?';
  201. u += caption ? 'caption=true&' : 'caption=false&';
  202. u += likes ? 'likes=true&' : 'likes=false&';
  203. u += layout == 'compact' ? 'layout=compact' : 'layout=full';
  204. return '<iframe src="'+u+'" class="pixelfed__embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script async defer src="'+window.location.origin +'/embed.js"><\/script>';
  205. }),
  206. profile: (function(url) {
  207. let u = url + '/embed';
  208. return '<iframe src="'+u+'" class="pixelfed__embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script async defer src="'+window.location.origin +'/embed.js"><\/script>';
  209. })
  210. },
  211. clipboard: (function(data) {
  212. return navigator.clipboard.writeText(data);
  213. }),
  214. navatar: (function() {
  215. $('#navbarDropdown .far').addClass('d-none');
  216. $('#navbarDropdown img').attr('src',window._sharedData.curUser.avatar)
  217. .removeClass('d-none')
  218. .addClass('rounded-circle border shadow')
  219. .attr('width', 34).attr('height', 34);
  220. })
  221. };