m24111

Untitled

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