The version of vichan running on lainchan.org
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

77 lignes
2.1KB

  1. /*
  2. * favorites.js - Allow user to favorite boards and put them in the bar
  3. *
  4. * Copyright (c) 2014 Fredrick Brennan <admin@8chan.co>
  5. *
  6. * Usage:
  7. * $config['additional_javascript'][] = 'js/jquery.min.js';
  8. * $config['additional_javascript'][] = 'js/favorites.js';
  9. *
  10. * XX: favorites.js may conflict with watch.js and compact-boardlist.js
  11. */
  12. if (!localStorage.favorites) {
  13. localStorage.favorites = '[]';
  14. }
  15. function favorite(board) {
  16. var favorites = JSON.parse(localStorage.favorites);
  17. favorites.push(board);
  18. localStorage.favorites = JSON.stringify(favorites);
  19. };
  20. function unfavorite(board) {
  21. var favorites = JSON.parse(localStorage.favorites);
  22. var index = $.inArray(board, favorites);
  23. if (~index) {
  24. favorites.splice(index, 1);
  25. }
  26. localStorage.favorites = JSON.stringify(favorites);
  27. };
  28. function handle_boards(data) {
  29. var boards = new Array();
  30. data = JSON.parse(data);
  31. $.each(data, function(k, v) {
  32. boards.push('<a href="/'+v+'">'+v+'</a>');
  33. })
  34. if (boards[0]) {
  35. return $('<span class="favorite-boards"></span>').append(' [ '+boards.slice(0,10).join(" / ")+' ] ');
  36. }
  37. }
  38. function add_favorites() {
  39. $('.favorite-boards').remove();
  40. var boards = handle_boards(localStorage.favorites);
  41. $('.boardlist').append(boards);
  42. };
  43. if (active_page == 'thread' || active_page == 'index' || active_page == 'catalog' || active_page == 'ukko') {
  44. $(document).ready(function(){
  45. var favorites = JSON.parse(localStorage.favorites);
  46. var is_board_favorite = ~$.inArray(board_name, favorites);
  47. $('header>h1').append('<a id="favorite-star" href="#" data-active="'+(is_board_favorite ? 'true' : 'false')+'" style="color: '+(is_board_favorite ? 'yellow' : 'grey')+'; text-decoration:none">\u2605</span>');
  48. add_favorites();
  49. $('#favorite-star').on('click', function(e) {
  50. e.preventDefault();
  51. if (!$(this).data('active')) {
  52. favorite(board_name);
  53. add_favorites();
  54. $(this).css('color', 'yellow');
  55. $(this).data('active', true);
  56. } else {
  57. unfavorite(board_name);
  58. add_favorites();
  59. $(this).css('color', 'grey');
  60. $(this).data('active', false);
  61. }
  62. });
  63. });
  64. }