The version of vichan running on lainchan.org
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

87 řádky
2.0KB

  1. /*
  2. * show-own-posts.js
  3. * https://github.com/savetheinternet/Tinyboard/blob/master/js/show-op.js
  4. *
  5. * Adds "(You)" to a name field when the post is yours. Update references as well.
  6. *
  7. * Released under the MIT license
  8. * Copyright (c) 2014 Marcin Łabanowski <marcin@6irc.net>
  9. *
  10. * Usage:
  11. * $config['additional_javascript'][] = 'js/jquery.min.js';
  12. * $config['additional_javascript'][] = 'js/ajax.js';
  13. * $config['additional_javascript'][] = 'js/show-own-posts.js';
  14. *
  15. */
  16. +function(){
  17. var update_own = function() {
  18. if ($(this).is('.you')) return;
  19. var thread = $(this).parents('[id^="thread_"]').first();
  20. if (!thread.length) {
  21. thread = $(this);
  22. }
  23. var board = thread.attr('data-board');
  24. var posts = JSON.parse(localStorage.own_posts || '{}');
  25. var id = $(this).attr('id').split('_')[1];
  26. if (posts[board] && posts[board].indexOf(id) !== -1) { // Own post!
  27. $(this).addClass('you');
  28. $(this).find('span.name').first().append(' <span class="own_post">'+_('(You)')+'</span>');
  29. }
  30. // Update references
  31. $(this).find('div.body:first a:not([rel="nofollow"])').each(function() {
  32. var postID;
  33. if(postID = $(this).text().match(/^>>(\d+)$/))
  34. postID = postID[1];
  35. else
  36. return;
  37. if (posts[board] && posts[board].indexOf(postID) !== -1) {
  38. $(this).after(' <small>'+_('(You)')+'</small>');
  39. }
  40. });
  41. };
  42. var update_all = function() {
  43. $('div[id^="thread_"], div.post.reply').each(update_own);
  44. };
  45. var board = null;
  46. $(function() {
  47. board = $('input[name="board"]').first().val();
  48. update_all();
  49. });
  50. $(document).on('ajax_after_post', function(e, r) {
  51. var posts = JSON.parse(localStorage.own_posts || '{}');
  52. posts[board] = posts[board] || [];
  53. posts[board].push(r.id);
  54. localStorage.own_posts = JSON.stringify(posts);
  55. });
  56. $(document).on('new_post', function(e,post) {
  57. var $post = $(post);
  58. if ($post.is('div.post.reply')) { // it's a reply
  59. $post.each(update_own);
  60. }
  61. else {
  62. $post.each(update_own); // first OP
  63. $post.find('div.post.reply').each(update_own); // then replies
  64. }
  65. });
  66. }();