CowboySoberano

Renomeador_Ataques_(Cowboy Soberano)

Jun 8th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //----------------------------------------------------------------
  2. //Projeto:      Etiquetar Ataques
  3. //Autor:        Nicholas Toby (cheesasaurus@gmail.com)
  4. //Editor:       Marcos Vinicius Dos Santos Marques (Cowboy soberano)
  5. //Email:                marcosvinicius.santosmarques@gmail.com
  6. //Versão:      Br 1.0 - 25/05/2017
  7. //Changelog:
  8. //                  Master > 8.21
  9. //              Br > 8.22
  10. //------------------------------------
  11. /*==== Pack Conteudo Tw ====*/
  12.  
  13. if(!twcheese)
  14.     var twcheese={};
  15.  
  16. twcheese.MassTag = {
  17.     widget: {},
  18.     format: '',
  19.     config: {
  20.         options: [
  21.             {
  22.                 name:'Unidade',
  23.                 description:'A velocidade unitaria mais lenta estimada',
  24.                 defaultLabel:' ',
  25.                 enabled: true
  26.             }, {
  27.                 name:'Coordenada',
  28.                 description:'As coordenadas das tropas de envio da aldeia',
  29.                 defaultLabel:' ',
  30.                 enabled: true
  31.             }, {
  32.                 name:'Jogador',
  33.                 description:'O jogador que enviou tropas',
  34.                 defaultLabel:' ',
  35.                 enabled: true
  36.             }, {
  37.                 name:'Duracao',
  38.                 description:'A duracao do ataque',
  39.                 defaultLabel:' ',
  40.                 enabled: false
  41.             }, {
  42.                 name:'Distancia',
  43.                 description:'A distancia (campos) entre aldeias',
  44.                 defaultLabel:' ',
  45.                 enabled: false
  46.             }, {
  47.                 name:'Retorno',
  48.                 description:'A data estimada e as horas que as tropas retornam',
  49.                 defaultLabel:' ',
  50.                 enabled: false
  51.             }, {
  52.                 name:'Enviada',
  53.                 description:'A data estimada e a hora em que as tropas foram enviadas',
  54.                 defaultLabel:' ',
  55.                 enabled: false
  56.             }, {
  57.                 name:'Chegada',
  58.                 description:'Data e hora da chegada',
  59.                 defaultLabel:' ',
  60.                 enabled: false
  61.             }, {
  62.                 name:'Origem',
  63.                 description:'Enviado de Aldeia: Nome (xxx|yyy) KYX',
  64.                 defaultLabel:' ',
  65.                 enabled: false
  66.             }, {
  67.                 name:'Destino',
  68.                 description:'Aldeia alvo: Nome (xxx|yyy) KYX',
  69.                 defaultLabel:' ',
  70.                 enabled: false
  71.             }
  72.         ]  
  73.     },     
  74.    
  75.     init: function () {
  76.         this.loadConfig();
  77.         this.widget = this.createWidget();
  78.         this.preview();
  79.     },
  80.  
  81.     createWidget: function () {
  82.         console.log('opening config widget');
  83.        
  84.         var widget = document.createElement('div');
  85.         widget.id = 'twcheese_tag_config_container';
  86.         widget.style.display = 'block';
  87.         widget.style.position = 'fixed';
  88.         widget.style.zIndex = 13000;
  89.         widget.style.top = '60px'; //below top menu
  90.         widget.style.left = '50%';
  91.         widget.style.width = '600px';
  92.         widget.style.marginLeft = '-300px';
  93.         widget.style.borderStyle = 'solid';
  94.         widget.style.borderWidth = '1px';
  95.         widget.style.borderRadius = '8px 8px 4px 4px';
  96.         widget.style.borderColor = '#804000 #603000 #402000 #804000';
  97.         widget.style.backgroundColor = '#ffe8cc';      
  98.        
  99.             /*==== title bar ====*/            
  100.                 var title_bar = document.createElement('div');
  101.                 title_bar.style.backgroundColor = '#00FFFF';
  102.                 title_bar.style.borderRadius = '8px 8px 0px 0px';
  103.                 title_bar.style.cursor = 'move';
  104.                
  105.                 /*==== title ====*/
  106.                 var title = document.createElement('span');
  107.                 title.innerHTML = "<b><span style=\"color:red;\">ETIQUETAR ATAQUES</span></b>";
  108.                 title.style.fontWeight = 700;
  109.                 title.style.fontSize = '12px';
  110.                 title.marginLeft = '10px';
  111.                 title_bar.appendChild(title);
  112.                
  113.                 twcheese.style.popupTitleBar(title_bar, function(){
  114.                     twcheese.MassTag.closeWidget();
  115.                 });
  116.                
  117.                 /*==== narcissism ====*/
  118.                 var contactEle = document.createElement('span');
  119.                 contactEle.innerHTML = '<a href="http://www.br.twstats.com/br82/index.php?page=player&id=8270061" target="_blank"><i><span style=\"color:aqua;\">Cowboy Soberano\</span></i><hr><br><span style=\"color:purple;\"> marcosvinicius.santosmarques@gmail.com </span></br><hr></a>';
  120.                 contactEle.style.fontSize = '12px';
  121.                 contactEle.style.cssFloat = 'right';
  122.                 contactEle.style.marginRight = '8px';
  123.                 title_bar.appendChild(contactEle);
  124.                
  125.             widget.appendChild(title_bar);
  126.             $(widget).draggable({handle:'.twcheese_title_bar'});               
  127.            
  128.             var content = document.createElement('div');
  129.             content.id = 'twcheese_tag_config';        
  130.            
  131.             /*==== preview ====*/
  132.             var preview_container = document.createElement('div');
  133.             preview_container.innerHTML = '<b>Pre-visualizacao: </b>';
  134.             preview_container.style.margin = '10px';
  135.            
  136.                 var preview = document.createElement('span');
  137.                 preview.id = 'twcheese_MassTag_preview';               
  138.                 preview.innerHTML = 'blahblahblah';        
  139.                 preview_container.appendChild(preview);
  140.                
  141.             content.appendChild(preview_container);        
  142.            
  143.             /*==== config ====*/
  144.             var options = this.config.options;         
  145.             var optionsTable = document.createElement('table');
  146.             optionsTable.style.marginLeft = '10px';
  147.             optionsTable.style.width = '580px';
  148.             optionsTable.id = 'twcheese_config_table';
  149.            
  150.             for(var i=0; i<twcheese.MassTag.config.options.length; i++)
  151.             {
  152.                 optionsTable.insertRow(-1);
  153.                 optionsTable.rows[i].optionData = options[i];
  154.                 optionsTable.rows[i].insertCell(-1);
  155.                 optionsTable.className = 'vis';
  156.                
  157.                 /*==== checkbox ====*/
  158.                 var checkbox = document.createElement('input');
  159.                 checkbox.type = 'checkbox';
  160.                 checkbox.checked = options[i].enabled;
  161.                 checkbox.onchange = function() {
  162.                     twcheese.MassTag.preview();
  163.                     this.parentNode.parentNode.optionData.enabled = this.checked;
  164.                     twcheese.MassTag.saveConfig();
  165.                 };
  166.                 optionsTable.rows[i].cells[0].appendChild(checkbox);
  167.                
  168.                 /*==== custom text ====*/
  169.                 optionsTable.rows[i].insertCell(-1);
  170.                 var label = document.createElement('input');
  171.                 label.type = 'text';
  172.                 label.size = 10;
  173.                 if(options[i].label != null)
  174.                     label.value = options[i].label;
  175.                 else
  176.                     label.value = options[i].defaultLabel;
  177.                 label.onkeyup = function(){                
  178.                     twcheese.MassTag.preview();
  179.                     if (!this.value) {
  180.                         this.parentNode.parentNode.optionData.label = '';
  181.                     } else {
  182.                         this.parentNode.parentNode.optionData.label = this.value;  
  183.                     }                                  
  184.                     twcheese.MassTag.saveConfig();
  185.                 };
  186.                 optionsTable.rows[i].cells[1].appendChild(label);
  187.                
  188.                 /*==== short name ====*/
  189.                 optionsTable.rows[i].insertCell(-1);
  190.                 optionsTable.rows[i].cells[2].innerHTML = options[i].name;
  191.                
  192.                 /*==== description ====*/
  193.                 optionsTable.rows[i].insertCell(-1);
  194.                 optionsTable.rows[i].cells[3].innerHTML = options[i].description;
  195.                
  196.                 /*==== handles ====*/
  197.                 optionsTable.rows[i].insertCell(-1);
  198.                 optionsTable.rows[i].cells[4].innerHTML = '<div style="width: 11px; height:11px; background-image: url(' + image_base + 'sorthandle.png); cursor:move" class="qbhandle" title="Arraste para reordenar"> </div>';
  199.             }
  200.             content.appendChild(optionsTable);
  201.            
  202.             /*==== buttons ====*/
  203.             var button_container = document.createElement('div');
  204.             button_container.style = 'text-align:center; margin:10px;';
  205.                 /*==== label button ====*/
  206.                 var label_button = document.createElement('a');
  207.                 label_button.className = 'btn';
  208.                 label_button.style.marginRight = '5px';
  209.                 label_button.innerHTML = "<b><span style=\"color:gold;\">ETIQUETAR</span></b>";
  210.                 label_button.onclick = function () {
  211.                     twcheese.MassTag.label(twcheese.MassTag.getFormat());
  212.                 };
  213.                 button_container.appendChild(label_button);
  214.             content.appendChild(button_container);         
  215.            
  216.         widget.appendChild(content);           
  217.        
  218.         document.getElementById('content_value').appendChild(widget);
  219.         $('#twcheese_config_table > tbody').sortable({handle: '.qbhandle', placeholder: 'sortable-placeholder'});
  220.         $('#twcheese_config_table > tbody').on('sortstop', function(){
  221.             twcheese.MassTag.preview();
  222.             twcheese.MassTag.saveConfig();
  223.         });    
  224.        
  225.         return document.getElementById('twcheese_tag_config');
  226.     },
  227.    
  228.     closeWidget: function () {
  229.         $('#twcheese_tag_config_container').remove();
  230.     },
  231.    
  232.     getFormat: function () {
  233.         var format = '';
  234.         var inputs = this.widget.getElementsByTagName('input');
  235.         var rows = this.widget.getElementsByTagName('tr');
  236.         for(var i=0; i<twcheese.MassTag.config.options.length; i++){
  237.             if(inputs[i*2].checked)
  238.             {
  239.                 format += inputs[i*2+1].value;
  240.                 format += '%'+rows[i].optionData.name+'%';
  241.             }
  242.         }
  243.         return format;
  244.     },
  245.    
  246.     preview: function () {
  247.         document.getElementById('twcheese_MassTag_preview').innerHTML = this.getFormat();
  248.     },
  249.    
  250.     saveConfig: function () {
  251.         var rows = this.widget.getElementsByTagName('tr');
  252.         var options = new Array();
  253.         for (var i=0; i<twcheese.MassTag.config.options.length; i++) {
  254.             options[i] = rows[i].optionData;           
  255.         }
  256.        
  257.         this.config.options = options;
  258.        
  259.         localStorage.setItem('twcheese.MassTag.config',JSON.stringify(this.config));
  260.         console.log('config saved');
  261.     },
  262.    
  263.     loadConfig: function () {
  264.         if (localStorage.getItem('twcheese.MassTag.config')) {
  265.             this.config = JSON.parse(localStorage.getItem('twcheese.MassTag.config'));
  266.             return true;
  267.         } else {
  268.             return false;
  269.         }
  270.     },
  271.    
  272.     label: function (format) {
  273.         $('#select_all').click();
  274.         $('input[name=label_format]').val(format).parents('form').find('input[name=label]').click();
  275.     }
  276. };
  277.  
  278. /*==== styles ====*/
  279. if(!twcheese.style)
  280.     twcheese.style = {};
  281.  
  282. /**
  283.  *  @param element:HTMLElement
  284.  *  @param topColor:String
  285.  *  @param bottomColor:String
  286.  */
  287. twcheese.style.bgVertGradient = function(element, topColor, bottomColor)
  288. {
  289.     element.style.backgroundColor = bottomColor;
  290.     var browser;
  291.     if(/Chrome/.test(navigator.userAgent)|| /AppleWebKit/.test(navigator.userAgent))
  292.         browser = 'webkit';
  293.     else if(/Firefox/.test(navigator.userAgent))
  294.         browser = 'moz';
  295.     else if(window.opera)
  296.         browser = 'o';
  297.     else if(/MSIE/.test(navigator.userAgent))
  298.         browser = 'ms';
  299.    
  300.     if(browser)
  301.         element.style.background = '-' + browser + '-linear-gradient(top, ' + topColor + ', ' + bottomColor +')';
  302. };
  303.    
  304. /**
  305.  *  @param element:HTMLElement
  306.  */
  307. twcheese.style.popupTitleBar = function (element, exit_function) {
  308.     element.className = 'twcheese_title_bar';
  309.     twcheese.style.bgVertGradient(element, '#52d87e', '#c1517f');
  310.     element.style.height = '22px';
  311.     element.style.padding = '7px';
  312.    
  313.     /*==== exit button ====*/
  314.     var exit_button = document.createElement('span');
  315.     exit_button.style.backgroundImage = 'url("' + image_base + 'login_close.png")';
  316.     exit_button.style.height = '20px';
  317.     exit_button.style.width = '20px';
  318.     exit_button.style.display = 'inline-block';
  319.     exit_button.style.cssFloat = 'right';
  320.     exit_button.style.cursor = 'pointer';
  321.     exit_button.onclick = exit_function;
  322.     element.appendChild(exit_button);
  323. };
  324.  
  325. /*==== register ====*/
  326. var script = {
  327.     scriptname: 'Etiquetar Ataques',
  328.     version: 8.21,
  329.     author: 'Nicholas Toby',
  330.     email: 'cheesasaurus@gmail.com',
  331.     broken: false
  332. };
  333. $.post(ScriptAPI.url,script);
  334.  
  335. /*==== Main ====*/
  336. if (game_data.screen == 'overview_villages' && game_data.mode == 'incomings') {
  337.     twcheese.MassTag.init();
  338. } else {
  339.     UI.InfoMessage('Iremos Lhe Redirecionar Para Visualizacoes Gerais...', 3000, 'exito');
  340.     document.location = game_data.link_base_pure + 'overview_villages&mode=incomings';
  341. };
Add Comment
Please, Sign In to add comment