GLB AI Output Namer

renames outputs to match the name of the play chosen

当前为 2015-03-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GLB AI Output Namer
  3. // @description renames outputs to match the name of the play chosen
  4. // @namespace monsterkill
  5. // @include http://glb.warriorgeneral.com/game/team_defense_ai.pl?team_id=*
  6. // @include http://glb.warriorgeneral.com/game/team_offense_ai.pl?team_id=*
  7. // @version 0.0.1.20150302041958
  8. // ==/UserScript==
  9.  
  10. var rbtn = document.createElement('input');
  11. rbtn.id = "testid";
  12. rbtn.type = "button";
  13. rbtn.value = 'Rename Outputs to match play and package names';
  14. rbtn.addEventListener("click", renameOutputsForSpecificPlays, true);
  15. var elmts = document.getElementsByClassName('description_text');
  16. elmts[0].appendChild(rbtn);
  17.  
  18. function renameOutputsForSpecificPlays() {
  19. //gets all the anchor elements for specific play names
  20. var iterator = document.evaluate("//span[contains(@id,'specific_play_name')]/a", document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null );
  21. try {
  22. var thisNode = iterator.iterateNext();
  23. var count=0;
  24. while (thisNode) {
  25. count++;
  26. var tmp = 'output_name_';
  27. tmp += thisNode.parentNode.id.split('_')[4];
  28. var outputNameElement = document.getElementById(tmp);
  29. outputNameElement.value = thisNode.innerHTML;
  30. thisNode = iterator.iterateNext();
  31. }
  32. alert('Renamed '+count+' outputs to match specific plays.'+((count>0)?'\n\nBe sure to save the AI to keep these names.':''));
  33. renameOutputsForSpecificPackages();
  34. }
  35. catch (e) {
  36. dump( 'Error: Document tree modified during iteration ' + e );
  37. }
  38. }
  39. function renameOutputsForSpecificPackages() {
  40. //gets all the anchor elements for specific packages
  41. var iterator = document.evaluate("//span[contains(@id,'package_name')]", document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null );
  42. try {
  43. var thisNode = iterator.iterateNext();
  44. var count=0;
  45. while (thisNode) {
  46. if (thisNode.innerHTML!='none') {
  47. count++;
  48. var tmp = 'output_name_';
  49. tmp += thisNode.id.split('_')[3];
  50. var outputNameElement = document.getElementById(tmp);
  51. outputNameElement.value = thisNode.innerHTML;
  52. }
  53. thisNode = iterator.iterateNext();
  54. }
  55. alert('Renamed '+count+' outputs to match packages.'+((count>0)?'\n\nBe sure to save the AI to keep these names.':''));
  56. }
  57. catch (e) {
  58. dump( 'Error: Document tree modified during iteration ' + e );
  59. }
  60. }