m24111

Untitled

Jun 22nd, 2020
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         DS - Advanced View Army
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.1
  5. // @description  try to take over the world!
  6. // @author       XHunter
  7. // @match        *://command.drop-shock.com/view_army.php*
  8. // @require      http://code.jquery.com/jquery-3.4.1.min.js
  9. // @grant        none
  10. // ==/UserScript==
  11. const TF_COLORS = ['#666600', '#400000', '#005600', '#00008B', '#5a5a5a', '#452040', '#525100', 'purple']
  12.  
  13. const KEY_BACKTICK = 96
  14. const KEY_1 = 49
  15. const KEY_2 = 50
  16. const KEY_3 = 51
  17. const KEY_4 = 52
  18. const KEY_5 = 53
  19. const KEY_6 = 54
  20. const KEY_7 = 55
  21. const KEY_X = 120
  22. const KEY_Q = 113
  23. const KEY_W = 119
  24. const KEY_E = 101
  25. const KEY_R = 114
  26.  
  27. const KEY_TF_0 = KEY_BACKTICK
  28. const KEY_TF_1 = KEY_1
  29. const KEY_TF_2 = KEY_2
  30. const KEY_TF_3 = KEY_3
  31. const KEY_TF_4 = KEY_4
  32. const KEY_TF_5 = KEY_5
  33. const KEY_TF_6 = KEY_6
  34. const KEY_TF_7 = KEY_7
  35. const KEY_TF_NONE = KEY_X
  36. const KEY_TOGGLE_TOGGLE = KEY_Q
  37. const KEY_TOGGLE_RESERVE = KEY_W
  38. const KEY_TOGGLE_ARMY = KEY_E
  39. const KEY_TOGGLE_NONE = KEY_R
  40.  
  41.  
  42.  
  43. var units = $('tr.unittext')
  44. function is_commander(tr){
  45.     return tr.find('span:contains(Commander)').length > 0
  46. }
  47.  
  48. function set_task_force(tr, newtf){
  49.     var tf = tr.find('select')
  50.     tf.val(newtf).change()
  51. }
  52.  
  53. function toggle(tr){
  54.     tr.children('td[width=120]').children('a')[0].click()
  55. }
  56.  
  57. function is_reserve(tr){
  58.     var btn = tr.children('td[width=120]').children('a')
  59.     return btn.text().includes('Reserve')
  60. }
  61.  
  62. function is_army(tr){
  63.     return !is_reserve(tr)
  64. }
  65.  
  66. function set_reserve(tr){
  67.     if (is_commander(tr))
  68.         return
  69.     else if (is_reserve(tr))
  70.         return
  71.     else
  72.         tr.children('td[width=120]').children('a')[0].click()
  73. }
  74.  
  75. function set_army(tr){
  76.     if (is_commander(tr))
  77.         return
  78.     else if (is_army(tr))
  79.         return
  80.     else
  81.         tr.children('td[width=120]').children('a')[0].click()
  82. }
  83.  
  84. /*============================== One-time execution ==============================*/
  85. units.sort(function(a,b) {
  86.     if (is_commander($(a)))
  87.         return false
  88.     if (is_commander($(b)))
  89.         return true
  90.  
  91.     var a_unit = $(a).children('td.unittextb').children('a').text()
  92.     var b_unit = $(b).children('td.unittextb').children('a').text()
  93.  
  94.     var a_variant = $(a).children('td.unittextb').children('span').text()
  95.     var b_variant = $(b).children('td.unittextb').children('span').text()
  96.  
  97.     var a_modslot = $(a).children('td.datetext').children('span')[1].textContent
  98.     var b_modslot = $(b).children('td.datetext').children('span')[1].textContent
  99.  
  100.     var a_tf = $(a).find('select').val()
  101.     var b_tf = $(b).find('select').val()
  102.  
  103.     var a_mods = $(a).find('img.imgM')
  104.     var b_mods = $(b).find('img.imgM')
  105.  
  106.     if (a_unit == b_unit){
  107.         if (a_variant == b_variant){
  108.             if (a_modslot == b_modslot){
  109.                 if (a_mods.length == b_mods.length){
  110.                     for (var i = 0; i < a_mods.length; i++){
  111.                         if (a_mods[i].src == b_mods[i].src)
  112.                             continue
  113.                         else return a_mods[i].src > b_mods[i].src
  114.                     }
  115.                     return a_tf >= b_tf
  116.                 } else return a_mods.length > b_mods.length
  117.             } else return a_modslot > b_modslot
  118.         } else return a_variant > b_variant
  119.     } else return a_unit > b_unit
  120.  
  121. }).appendTo('tbody');
  122.  
  123. //Mouse logger
  124. var mouseDown = false
  125. $(document).mousedown(function(event){mouseDown = true})
  126. $(document).mouseup(function(event){mouseDown = false})
  127.  
  128.  
  129. units.mouseenter(function(event){
  130.     event.stopPropagation()
  131.     if (mouseDown){
  132.         var tf_sel = select_tf.val()
  133.         var toggle_sel = select_toggle.val()
  134.         if (tf_sel != 'none'){
  135.             set_task_force($(this), tf_sel)
  136.         }
  137.  
  138.         if (toggle_sel == 'toggle'){
  139.             toggle($(this))
  140.         } else if (toggle_sel == 'reserve'){
  141.             set_reserve($(this))
  142.         } else if (toggle_sel == 'army'){
  143.             set_army($(this))
  144.         }
  145.     }
  146. })
  147.  
  148. units.mousedown(function(event){
  149.     var tf_sel = select_tf.val()
  150.     var toggle_sel = select_toggle.val()
  151.     if (tf_sel != 'none'){
  152.         set_task_force($(this), tf_sel)
  153.     }
  154.  
  155.     if (toggle_sel == 'toggle'){
  156.         toggle($(this))
  157.     } else if (toggle_sel == 'reserve'){
  158.         set_reserve($(this))
  159.     } else if (toggle_sel == 'army'){
  160.         set_army($(this))
  161.     }
  162. })
  163.  
  164. for (var unit of units){
  165.  
  166.  
  167.     var tf = $(unit).find('select')
  168.     var togg = $(unit).children('td[width=120]')
  169.  
  170.     var tf_read_only = $($.parseHTML('<div></div>'))
  171.     tf_read_only.css('width', 40)
  172.     tf_read_only.css('height', '80%')
  173.     tf_read_only.css('margin-left',10)
  174.     tf_read_only.css('border', '1px blue solid')
  175.     tf_read_only.css('text-align', 'center')
  176.     tf_read_only.css('vertical-align', 'middle')
  177.     tf_read_only.css('line-height', '40px')
  178.     tf_read_only.css('font-size', '28px')
  179.     tf_read_only.text(tf.val())
  180.     tf.change(function(x){
  181.         $(this).next().text($(this).val())
  182.     })
  183.     tf.parent().append(tf_read_only)
  184.     bruteforce_set_color()
  185.  
  186.     tf.css('display','none')
  187.     togg.css('display','none')
  188. }
  189. /*============================== Function rewrites ==============================*/
  190. function queueCommand_2(myActor,myAction,myTarget) {
  191.     myCommand = myActor + "," + myAction + "," + myTarget;
  192.     commandQueue[(commandQueue.length)] = myCommand
  193.     drawQueue();
  194. }
  195. queueCommand = queueCommand_2
  196.  
  197. var sending = false
  198. function sendCommand_2(myCommand) {
  199.     commandArray = myCommand.split(',')
  200.     sending = true
  201.     $.post( "process_get_modify.php", { theactor: commandArray[0], theaction: commandArray[1], thetarget: commandArray[2] }, function(data){
  202.         thisactor = commandArray[0];
  203.         thisaction = commandArray[1];
  204.         thistarget = commandArray[2];
  205.  
  206.         if (thisaction=="toggleall") {
  207.             if (data=="ok") { toggleAllConfirm(parseInt(thisactor),parseInt(thistarget)); }
  208.         } else if (thisaction=="togglearmy") {
  209.             if (data=="ok") { togglearmyConfirm(parseInt(thisactor),thistarget); }
  210.         }
  211.  
  212.         dequeueCommand(0)
  213.         bruteforce_set_color()
  214.         sending = false
  215.     })
  216. }
  217. sendCommand = sendCommand_2
  218.  
  219. function bruteforce_set_color(){
  220.     for (var unit of units){
  221.         if (is_commander($(unit))) continue
  222.  
  223.         var tf = $(unit).children().first().children().val()
  224.         if ($(unit).children().first().next().children('a').text().includes('Army')){
  225.             if (tf == '')
  226.                 tf = '0'
  227.             $(unit).css('background', TF_COLORS[parseInt(tf)])
  228.         }
  229.         else{
  230.             $(unit).css('background', '')
  231.         }
  232.     }
  233. }
  234.  
  235. function changeTF_2(myUnit,myTF) {
  236.     queueCommand(myUnit,'changetf',myTF)
  237. }
  238.  
  239. changeTF = changeTF_2
  240. function runQueue_2() {
  241. }
  242. runQueue = runQueue_2
  243.  
  244. setInterval(function(){
  245.     if ((commandQueue.length > 0) && !sending) {
  246.         sendCommand(commandQueue[0])
  247.     }
  248. },50)
  249. /*============================== New GUI Buttons ==============================*/
  250. var select_tf = $($.parseHTML('<select></select>'))
  251. var select_toggle = $($.parseHTML('<select></select>'))
  252. var tf_options = {
  253.     none:{value:'none',text:'none'},
  254.     tf0:{value:'0',text:''},
  255.     tf1:{value:'1',text:1},
  256.     tf2:{value:'2',text:2},
  257.     tf3:{value:'3',text:3},
  258.     tf4:{value:'4',text:4},
  259.     tf5:{value:'5',text:5},
  260.     tf6:{value:'6',text:6},
  261.     tf7:{value:'7',text:7}
  262. }
  263. var toggle_options = {
  264.     toggle: {value:'toggle' ,text:'toggle'},
  265.     reserve:{value:'reserve',text:'reserve'},
  266.     army:   {value:'army'   ,text:'army'},
  267.     none:   {value:'none'   ,text:'none'}
  268. }
  269.  
  270. $.each(tf_options, function (i, item) {
  271.     select_tf.append($('<option>', {
  272.         value: item.value,
  273.         text : item.text
  274.     }));
  275. });
  276.  
  277. $.each(toggle_options, function (i, item) {
  278.     select_toggle.append($('<option>', {
  279.         value: item.value,
  280.         text : item.text
  281.     }));
  282. });
  283.  
  284. select_toggle.css('margin-right', 15)
  285. select_tf.css('margin-right', 15)
  286.  
  287. $('#topActions').prepend(select_toggle)
  288. $('#topActions').prepend(select_tf)
  289.  
  290. /*============================== Listeners and intervals ==============================*/
  291. $(document).keypress(function(event){
  292.     var keycode = (event.keyCode ? event.keyCode : event.which)
  293.     if (keycode == KEY_TF_0){
  294.         select_tf.val('').change()
  295.     }
  296.     else if (keycode == KEY_TF_1){
  297.         select_tf.val('1').change()
  298.     }
  299.     else if (keycode == KEY_TF_2){
  300.         select_tf.val('2').change()
  301.     }
  302.     else if (keycode == KEY_TF_3){
  303.         select_tf.val('3').change()
  304.     }
  305.     else if (keycode == KEY_TF_4){
  306.         select_tf.val('4').change()
  307.     }
  308.     else if (keycode == KEY_TF_5){
  309.         select_tf.val('5').change()
  310.     }
  311.     else if (keycode == KEY_TF_6){
  312.         select_tf.val('6').change()
  313.     }
  314.     else if (keycode == KEY_TF_7){
  315.         select_tf.val('7').change()
  316.     }
  317.     else if (keycode == KEY_TF_NONE){
  318.         select_tf.val('none').change()
  319.     }
  320.     else if (keycode == KEY_TOGGLE_TOGGLE){
  321.         select_toggle.val('toggle').change()
  322.     }
  323.     else if (keycode == KEY_TOGGLE_RESERVE){
  324.         select_toggle.val('reserve').change()
  325.     }
  326.     else if (keycode == KEY_TOGGLE_ARMY){
  327.         select_toggle.val('army').change()
  328.     }
  329.     else if (keycode == KEY_TOGGLE_NONE){
  330.         select_toggle.val('none').change()
  331.     }
  332. });
Add Comment
Please, Sign In to add comment