Advertisement
enbyted

Generowanie listy (mailingowej) z przeglądu graczy w plemieniu (aktualizacja)

Jan 12th, 2021
1,554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // author DNSTW (stivens)
  3. // Updated by grabie2 on 13.01.2021
  4. //
  5. (function() {
  6.     let mode = game_data.mode;
  7.     if (mode === null)
  8.         mode = (new URL(window.location)).searchParams.get('mode');
  9.  
  10.     if ((game_data.screen == 'ally' && mode == 'members')) {
  11.         try {
  12.             $('table.vis:contains(Ranking globalny)').attr('id', 'ally_content');
  13.         } catch {
  14.             ;
  15.         }
  16.         var table = $('#ally_content');
  17.         var theader = $('table th:contains(Funkcje)').clone().text('Dodać?');
  18.     } else if (game_data.screen == 'info_ally') {
  19.         try {
  20.             $('table.vis:contains(Ranking globalny)').attr('id', 'ally_content');
  21.         } catch {
  22.             ;
  23.         }
  24.         var table = $('#ally_content');
  25.         var theader = $('table th:contains(Nazwa)').clone().text('Dodać?');
  26.     } else if (game_data.screen == 'info_member') {
  27.         var table = $('th:contains(Ranking globalny)').parent().parent().parent();
  28.         var theader = $('table th:contains(Wioski)').clone().find('a').text('Dodać?');
  29.     } else {
  30.         UI.InfoMessage('Skryptu należy używać z przeglądu członków plemienia.', 5000, 'error');
  31.         throw new Error('Skrypt przerwany.');
  32.     }
  33.     var popup_content = `<div style="text-align:center" id="mailing_popup">
  34.                         <input type="radio" name="type" value="mailing" checked> Lista mailingowa<br>
  35.                         <input type="radio" name="type" value="bbcode"> Lista z bbcode<br><br><br>
  36.                         <button type="button" class="btn" id="check_all_btn">Zaznacz wszystkich</button>
  37.                         <button type="button" class="btn" id="ready_btn">Stwórz listę</button><br><br><hr><br><br>
  38.                         <textarea id="list_textar" style="width: 90%" rows="7"></textarea>
  39.                     </div>`;
  40.  
  41.     function createPopup(title, content, options) {
  42.         const {
  43.             width,
  44.             height,
  45.             onClose
  46.         } = options;
  47.         const updateContainement = (element) => {
  48.             const maxBottom = $(document).height() - $(element).outerHeight();
  49.             const maxRight = $(document).width() - $(element).outerWidth();
  50.             const minTop = $(".top_bar").height();
  51.             element.draggable("option", "containment", [0, minTop, maxRight, maxBottom])
  52.         };
  53.         const closeLink = $('<a href="#">X</a>');
  54.         const titleBar = $('<div class="popup_menu"></div>').append(title).append(closeLink);
  55.         const contentDiv = $('<div class="popup_content"></div>').append(content);
  56.         if (height)
  57.             contentDiv.css({
  58.                 height
  59.             });
  60.         const popup = $('<div class="popup_style" style="position: fixed;"></div>').append(titleBar).append(contentDiv);
  61.         if (width)
  62.             popup.css({
  63.                 width
  64.             });
  65.         const helper = $('<div class="popup_helper"></div>').append(popup);
  66.         UI.Draggable(popup);
  67.         $('#ds_body').append(helper);
  68.         closeLink.click(() => {
  69.             if (onClose)
  70.                 onClose(popup);
  71.             helper.remove();
  72.         });
  73.         updateContainement(popup);
  74.         $(window).resize(() => updateContainement(popup));
  75.         popup.show();
  76.     };
  77.     if ($('#mailing_popup').length === 0) {
  78.         createPopup('Tworzenie listy graczy', popup_content, {
  79.             width: 400
  80.         });
  81.         $('#ready_btn').on('click', function() {
  82.             var type = $('input[name = "type"]:checked').val();
  83.             var result = '';
  84.             switch (type) {
  85.                 case 'mailing':
  86.                     $('.mailing_chkbox').each(function() {
  87.                         if ($(this).is(':checked')) {
  88.                             result += $(this).attr('value') + ";";
  89.                         }
  90.                     });
  91.                     break;
  92.                 case 'bbcode':
  93.                     $('.mailing_chkbox').each(function() {
  94.                         if ($(this).is(':checked')) {
  95.                             result += '[player]' + $(this).attr('value') + "[/player]\r\n";
  96.                         }
  97.                     });
  98.                     break;
  99.             }
  100.             $('#list_textar').text(result);
  101.         });
  102.         $('#check_all_btn').on('click', function() {
  103.             $('.mailing_chkbox').each((index, checkbox) => {
  104.                 $(checkbox).attr('checked', true);
  105.             });
  106.         });
  107.         $(table).find('th:first').before(theader);
  108.         var members = $(table).find('tr:not(:first-child)');
  109.         $(members).each(function() {
  110.             var name = $(this).find('td')[0];
  111.             name = $(name).find('a').text().trim();
  112.             if ($(this).find('input.mailing_chkbox').length === 0)
  113.                 $(this).find('td:first').before('<td class="lit-item"><input type="checkbox" class="mailing_chkbox" value="' + name + '"></td>');
  114.         });
  115.     }
  116. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement