Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (!twcheese)
  2.   var twcheese = {};
  3. twcheese.MassTag = {
  4.   widget: {},
  5.   format: '',
  6.   config: {
  7.     options: [{
  8.       name: 'unit',
  9.       description: 'Определяет юнит (по скорости)',
  10.       defaultLabel: ' ',
  11.       enabled: true
  12.     }, {
  13.       name: 'coords',
  14.       description: 'Координаты деревни, откуда идёт атака',
  15.       defaultLabel: ' ',
  16.       enabled: true
  17.     }, {
  18.       name: 'player',
  19.       description: 'Ник игрока, от которого идёт атака',
  20.       defaultLabel: ' ',
  21.       enabled: true
  22.     }, {
  23.       name: 'duration',
  24.       description: 'Время хода атаки',
  25.       defaultLabel: ' ',
  26.       enabled: false
  27.     }, {
  28.       name: 'distance',
  29.       description: 'Расстояние между деревнями (в клетках)',
  30.       defaultLabel: ' ',
  31.       enabled: false
  32.     }, {
  33.       name: 'return',
  34.       description: 'Дата и время возврата войск',
  35.       defaultLabel: ' ',
  36.       enabled: false
  37.     }, {
  38.       name: 'sent',
  39.       description: 'Дата и время отправки войск',
  40.       defaultLabel: ' ',
  41.       enabled: false
  42.     }, {
  43.       name: 'arrival',
  44.       description: 'Дата и время прибытия войск',
  45.       defaultLabel: ' ',
  46.       enabled: false
  47.     }, {
  48.       name: 'origin',
  49.       description: 'Координаты деревни отправки',
  50.       defaultLabel: ' ',
  51.       enabled: false
  52.     }, {
  53.       name: 'destination',
  54.       description: 'Координаты деревни-цели',
  55.       defaultLabel: ' ',
  56.       enabled: false
  57.     }]
  58.   },
  59.   init: function () {
  60.     this.loadConfig();
  61.     this.widget = this.createWidget();
  62.     this.preview();
  63.   },
  64.   createWidget: function () {
  65.     console.log('opening config widget');
  66.     var widget = document.createElement('div');
  67.     widget.id = 'twcheese_tag_config_container';
  68.     widget.style.display = 'block';
  69.     widget.style.position = 'fixed';
  70.     widget.style.zIndex = 13000;
  71.     widget.style.top = '60px'; //below top menu
  72.     widget.style.left = '50%';
  73.     widget.style.width = '600px';
  74.     widget.style.marginLeft = '-300px';
  75.     widget.style.borderStyle = 'solid';
  76.     widget.style.borderWidth = '1px';
  77.     widget.style.borderRadius = '8px 8px 4px 4px';
  78.     widget.style.borderColor = '#804000 #603000 #402000 #804000';
  79.     widget.style.backgroundColor = '#f7eed3';
  80.  
  81.     /*==== title bar ====*/
  82.     var title_bar = document.createElement('div');
  83.     title_bar.style.backgroundColor = '#dfcca6';
  84.     title_bar.style.borderRadius = '8px 8px 0px 0px';
  85.     title_bar.style.cursor = 'move';
  86.  
  87.     /*==== title ====*/
  88.     var title = document.createElement('span');
  89.     title.innerHTML = 'Настроить Метку';
  90.     title.style.fontWeight = 700;
  91.     title.style.fontSize = '14px';
  92.     title.marginLeft = '10px';
  93.     title_bar.appendChild(title);
  94.  
  95.     twcheese.style.popupTitleBar(title_bar, function() {
  96.       twcheese.MassTag.closeWidget();
  97.     });
  98.  
  99.     widget.appendChild(title_bar);
  100.     $(widget).draggable({
  101.       handle: '.twcheese_title_bar'
  102.     });
  103.  
  104.     var content = document.createElement('div');
  105.     content.id = 'twcheese_tag_config';
  106.  
  107.     /*==== preview ====*/
  108.     var preview_container = document.createElement('div');
  109.     preview_container.innerHTML = '<b>Просмотр: </b>';
  110.     preview_container.style.margin = '10px';
  111.  
  112.     var preview = document.createElement('span');
  113.     preview.id = 'twcheese_MassTag_preview';
  114.     preview.innerHTML = 'blahblahblah';
  115.     preview_container.appendChild(preview);
  116.  
  117.     content.appendChild(preview_container);
  118.  
  119.     /*==== config ====*/
  120.     var options = this.config.options;
  121.     var optionsTable = document.createElement('table');
  122.     optionsTable.style.marginLeft = '10px';
  123.     optionsTable.style.width = '580px';
  124.     optionsTable.id = 'twcheese_config_table';
  125.  
  126.     for (var i = 0; i < twcheese.MassTag.config.options.length; i++) {
  127.       optionsTable.insertRow(-1);
  128.       optionsTable.rows[i].optionData = options[i];
  129.       optionsTable.rows[i].insertCell(-1);
  130.       optionsTable.className = 'vis';
  131.  
  132.       /*==== checkbox ====*/
  133.       var checkbox = document.createElement('input');
  134.       checkbox.type = 'checkbox';
  135.       checkbox.checked = options[i].enabled;
  136.       checkbox.onchange = function() {
  137.         twcheese.MassTag.preview();
  138.         this.parentNode.parentNode.optionData.enabled = this.checked;
  139.         twcheese.MassTag.saveConfig();
  140.       };
  141.       optionsTable.rows[i].cells[0].appendChild(checkbox);
  142.  
  143.       /*==== custom text ====*/
  144.       optionsTable.rows[i].insertCell(-1);
  145.       var label = document.createElement('input');
  146.       label.type = 'text';
  147.       label.size = 10;
  148.       if (options[i].label != null)
  149.         label.value = options[i].label;
  150.       else
  151.         label.value = options[i].defaultLabel;
  152.       label.onkeyup = function() {
  153.         twcheese.MassTag.preview();
  154.         if (!this.value) {
  155.           this.parentNode.parentNode.optionData.label = '';
  156.         } else {
  157.           this.parentNode.parentNode.optionData.label = this.value;
  158.         }
  159.         twcheese.MassTag.saveConfig();
  160.       };
  161.       optionsTable.rows[i].cells[1].appendChild(label);
  162.  
  163.       /*==== short name ====*/
  164.       optionsTable.rows[i].insertCell(-1);
  165.       optionsTable.rows[i].cells[2].innerHTML = options[i].name;
  166.  
  167.       /*==== description ====*/
  168.       optionsTable.rows[i].insertCell(-1);
  169.       optionsTable.rows[i].cells[3].innerHTML = options[i].description;
  170.  
  171.       /*==== handles ====*/
  172.       optionsTable.rows[i].insertCell(-1);
  173.       optionsTable.rows[i].cells[4].innerHTML = '<div style="width: 11px; height:11px; background-image: url(' + image_base + 'sorthandle.png); cursor:move" class="qbhandle" title="drag to re-order"> </div>';
  174.     }
  175.     content.appendChild(optionsTable);
  176.  
  177.     /*==== buttons ====*/
  178.     var button_container = document.createElement('div');
  179.     button_container.style = 'text-align:center; margin:10px;';
  180.     /*==== label button ====*/
  181.     var label_button = document.createElement('a');
  182.     label_button.className = 'btn';
  183.     label_button.style.marginRight = '5px';
  184.     label_button.innerHTML = 'Label';
  185.     label_button.onclick = function () {
  186.       twcheese.MassTag.label(twcheese.MassTag.getFormat());
  187.     };
  188.     button_container.appendChild(label_button);
  189.     content.appendChild(button_container);
  190.  
  191.     widget.appendChild(content);
  192.  
  193.     document.getElementById('content_value').appendChild(widget);
  194.     $('#twcheese_config_table > tbody').sortable({
  195.       handle: '.qbhandle', placeholder: 'sortable-placeholder'
  196.     });
  197.     $('#twcheese_config_table > tbody').on('sortstop', function() {
  198.       twcheese.MassTag.preview();
  199.       twcheese.MassTag.saveConfig();
  200.     });
  201.  
  202.     return document.getElementById('twcheese_tag_config');
  203.   },
  204.  
  205.   closeWidget: function () {
  206.     $('#twcheese_tag_config_container').remove();
  207.   },
  208.  
  209.   getFormat: function () {
  210.     var format = '';
  211.     var inputs = this.widget.getElementsByTagName('input');
  212.     var rows = this.widget.getElementsByTagName('tr');
  213.     for (var i = 0; i < twcheese.MassTag.config.options.length; i++) {
  214.       if (inputs[i*2].checked) {
  215.         format += inputs[i*2+1].value;
  216.         format += '%'+rows[i].optionData.name+'%';
  217.       }
  218.     }
  219.     return format;
  220.   },
  221.  
  222.   preview: function () {
  223.     document.getElementById('twcheese_MassTag_preview').innerHTML = this.getFormat();
  224.   },
  225.  
  226.   saveConfig: function () {
  227.     var rows = this.widget.getElementsByTagName('tr');
  228.     var options = new Array();
  229.     for (var i = 0; i < twcheese.MassTag.config.options.length; i++) {
  230.       options[i] = rows[i].optionData;
  231.     }
  232.  
  233.     this.config.options = options;
  234.  
  235.     localStorage.setItem('twcheese.MassTag.config', JSON.stringify(this.config));
  236.     console.log('config saved');
  237.   },
  238.  
  239.   loadConfig: function () {
  240.     if (localStorage.getItem('twcheese.MassTag.config')) {
  241.       this.config = JSON.parse(localStorage.getItem('twcheese.MassTag.config'));
  242.       return true;
  243.     } else {
  244.       return false;
  245.     }
  246.   },
  247.  
  248.   label: function (format) {
  249.     $('#select_all').click();
  250.     $('input[name=label_format]').val(format).parents('form').find('input[name=label]').click();
  251.   }
  252. };
  253.  
  254. if (!twcheese.style)
  255.   twcheese.style = {};
  256.  
  257. twcheese.style.bgVertGradient = function(element, topColor, bottomColor) {
  258.   element.style.backgroundColor = bottomColor;
  259.   var browser;
  260.   if (/Chrome/.test(navigator.userAgent) || /AppleWebKit/.test(navigator.userAgent))
  261.     browser = 'webkit';
  262.   else if (/Firefox/.test(navigator.userAgent))
  263.     browser = 'moz';
  264.   else if (window.opera)
  265.     browser = 'o';
  266.   else if (/MSIE/.test(navigator.userAgent))
  267.     browser = 'ms';
  268.  
  269.   if (browser)
  270.     element.style.background = '-' + browser + '-linear-gradient(top, ' + topColor + ', ' + bottomColor +')';
  271. };
  272.  
  273. twcheese.style.popupTitleBar = function (element, exit_function) {
  274.   element.className = 'twcheese_title_bar';
  275.   twcheese.style.bgVertGradient(element, '#DEC378', '#BDA666');
  276.   element.style.height = '22px';
  277.   element.style.padding = '4px';
  278.  
  279.   /*==== exit button ====*/
  280.   var exit_button = document.createElement('span');
  281.   exit_button.style.backgroundImage = 'url("' + image_base + 'login_close.png")';
  282.   exit_button.style.height = '20px';
  283.   exit_button.style.width = '20px';
  284.   exit_button.style.display = 'inline-block';
  285.   exit_button.style.cssFloat = 'right';
  286.   exit_button.style.cursor = 'pointer';
  287.   exit_button.onclick = exit_function;
  288.   element.appendChild(exit_button);
  289. };
  290.  
  291.  
  292.  
  293. /*==== Main ====*/
  294. if (game_data.screen == 'overview_villages' && game_data.mode == 'incomings') {
  295.   twcheese.MassTag.init();
  296. } else {
  297.   UI.InfoMessage('Переход к входящему обзору ...', 3000, 'success');
  298.   document.location = game_data.link_base_pure + 'overview_villages&mode=incomings';
  299. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement