Advertisement
Guest User

Untitled

a guest
Sep 18th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.09 KB | None | 0 0
  1. /**
  2. * Mass Tagger
  3. * @version 1.0.0
  4. * last updated: April 14, 2014
  5. * game compatability: version 20228 8.21
  6. * @author Nick Toby (cheesasaurus@gmail.com)
  7.  
  8. ==== pages where this can be used ====
  9. * incoming overview (screen=overview_villages&mode=incomings)
  10.  
  11. ==== changelog ====
  12. * 14 apr 2014 - released
  13.  
  14. ==== license ====
  15. * Copyright (C) 2014 Nick Toby
  16.  
  17. This program is free software: you can redistribute it and/or modify
  18. it under the terms of the GNU General Public License as published by
  19. the Free Software Foundation, either version 3 of the License, or
  20. (at your option) any later version.
  21.  
  22. This program is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. GNU General Public License for more details.
  26.  
  27. You should have received a copy of the GNU General Public License
  28. along with this program. If not, see http://www.gnu.org/licenses/
  29. */
  30.  
  31. if(!twcheese)
  32. var twcheese={};
  33.  
  34. twcheese.MassTag = {
  35. widget: {},
  36. format: '',
  37. config: {
  38. options: [
  39. {
  40. name:'unit',
  41. description:'The estimated slowest unit speed',
  42. defaultLabel:' ',
  43. enabled: true
  44. }, {
  45. name:'coords',
  46. description:'The coordinates of village sending troops',
  47. defaultLabel:' ',
  48. enabled: true
  49. }, {
  50. name:'player',
  51. description:'The player sending troops',
  52. defaultLabel:' ',
  53. enabled: true
  54. }, {
  55. name:'duration',
  56. description:'The duration of the attack',
  57. defaultLabel:' ',
  58. enabled: false
  59. }, {
  60. name:'distance',
  61. description:'The distance (fields) between villages',
  62. defaultLabel:' ',
  63. enabled: false
  64. }, {
  65. name:'return',
  66. description:'The estimated date and time the troops return',
  67. defaultLabel:' ',
  68. enabled: false
  69. }, {
  70. name:'sent',
  71. description:'The estimated date and time the troops were sent',
  72. defaultLabel:' ',
  73. enabled: false
  74. }, {
  75. name:'arrival',
  76. description:'The arrival date and time',
  77. defaultLabel:' ',
  78. enabled: false
  79. }, {
  80. name:'origin',
  81. description:'sending village: name (xxx|yyy) KYX',
  82. defaultLabel:' ',
  83. enabled: false
  84. }, {
  85. name:'destination',
  86. description:'target village: name (xxx|yyy) KYX',
  87. defaultLabel:' ',
  88. enabled: false
  89. }
  90. ]
  91. },
  92.  
  93. init: function () {
  94. this.loadConfig();
  95. this.widget = this.createWidget();
  96. this.preview();
  97. },
  98.  
  99. createWidget: function () {
  100. console.log('opening config widget');
  101.  
  102. var widget = document.createElement('div');
  103. widget.id = 'twcheese_tag_config_container';
  104. widget.style.display = 'block';
  105. widget.style.position = 'fixed';
  106. widget.style.zIndex = 13000;
  107. widget.style.top = '60px'; //below top menu
  108. widget.style.left = '50%';
  109. widget.style.width = '600px';
  110. widget.style.marginLeft = '-300px';
  111. widget.style.borderStyle = 'solid';
  112. widget.style.borderWidth = '1px';
  113. widget.style.borderRadius = '8px 8px 4px 4px';
  114. widget.style.borderColor = '#804000 #603000 #402000 #804000';
  115. widget.style.backgroundColor = '#f7eed3';
  116.  
  117. /*==== title bar ====*/
  118. var title_bar = document.createElement('div');
  119. title_bar.style.backgroundColor = '#dfcca6';
  120. title_bar.style.borderRadius = '8px 8px 0px 0px';
  121. title_bar.style.cursor = 'move';
  122.  
  123. /*==== title ====*/
  124. var title = document.createElement('span');
  125. title.innerHTML = 'Configure Label';
  126. title.style.fontWeight = 700;
  127. title.style.fontSize = '14px';
  128. title.marginLeft = '10px';
  129. title_bar.appendChild(title);
  130.  
  131. twcheese.style.popupTitleBar(title_bar, function(){
  132. twcheese.MassTag.closeWidget();
  133. });
  134.  
  135. /*==== narcissism ====*/
  136. var contactEle = document.createElement('span');
  137. contactEle.innerHTML = ' created by <a href="http://forum.tribalwars.net/member.php?u=28484">cheesasaurus</a>';
  138. contactEle.style.fontSize = '10px';
  139. contactEle.style.cssFloat = 'right';
  140. contactEle.style.marginRight = '5px';
  141. title_bar.appendChild(contactEle);
  142.  
  143. widget.appendChild(title_bar);
  144. $(widget).draggable({handle:'.twcheese_title_bar'});
  145.  
  146. var content = document.createElement('div');
  147. content.id = 'twcheese_tag_config';
  148.  
  149. /*==== preview ====*/
  150. var preview_container = document.createElement('div');
  151. preview_container.innerHTML = '<b>Preview: </b>';
  152. preview_container.style.margin = '10px';
  153.  
  154. var preview = document.createElement('span');
  155. preview.id = 'twcheese_MassTag_preview';
  156. preview.innerHTML = 'blahblahblah';
  157. preview_container.appendChild(preview);
  158.  
  159. content.appendChild(preview_container);
  160.  
  161. /*==== config ====*/
  162. var options = this.config.options;
  163. var optionsTable = document.createElement('table');
  164. optionsTable.style.marginLeft = '10px';
  165. optionsTable.style.width = '580px';
  166. optionsTable.id = 'twcheese_config_table';
  167.  
  168. for(var i=0; i<twcheese.MassTag.config.options.length; i++)
  169. {
  170. optionsTable.insertRow(-1);
  171. optionsTable.rows[i].optionData = options[i];
  172. optionsTable.rows[i].insertCell(-1);
  173. optionsTable.className = 'vis';
  174.  
  175. /*==== checkbox ====*/
  176. var checkbox = document.createElement('input');
  177. checkbox.type = 'checkbox';
  178. checkbox.checked = options[i].enabled;
  179. checkbox.onchange = function() {
  180. twcheese.MassTag.preview();
  181. this.parentNode.parentNode.optionData.enabled = this.checked;
  182. twcheese.MassTag.saveConfig();
  183. };
  184. optionsTable.rows[i].cells[0].appendChild(checkbox);
  185.  
  186. /*==== custom text ====*/
  187. optionsTable.rows[i].insertCell(-1);
  188. var label = document.createElement('input');
  189. label.type = 'text';
  190. label.size = 10;
  191. if(options[i].label != null)
  192. label.value = options[i].label;
  193. else
  194. label.value = options[i].defaultLabel;
  195. label.onkeyup = function(){
  196. twcheese.MassTag.preview();
  197. if (!this.value) {
  198. this.parentNode.parentNode.optionData.label = '';
  199. } else {
  200. this.parentNode.parentNode.optionData.label = this.value;
  201. }
  202. twcheese.MassTag.saveConfig();
  203. };
  204. optionsTable.rows[i].cells[1].appendChild(label);
  205.  
  206. /*==== short name ====*/
  207. optionsTable.rows[i].insertCell(-1);
  208. optionsTable.rows[i].cells[2].innerHTML = options[i].name;
  209.  
  210. /*==== description ====*/
  211. optionsTable.rows[i].insertCell(-1);
  212. optionsTable.rows[i].cells[3].innerHTML = options[i].description;
  213.  
  214. /*==== handles ====*/
  215. optionsTable.rows[i].insertCell(-1);
  216. 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>';
  217. }
  218. content.appendChild(optionsTable);
  219.  
  220. /*==== buttons ====*/
  221. var button_container = document.createElement('div');
  222. button_container.style = 'text-align:center; margin:10px;';
  223. /*==== label button ====*/
  224. var label_button = document.createElement('a');
  225. label_button.className = 'btn';
  226. label_button.id = 'label';
  227. label_button.style.marginRight = '5px';
  228. label_button.innerHTML = 'Label';
  229. label_button.onclick = function () {
  230. twcheese.MassTag.label(twcheese.MassTag.getFormat());
  231. };
  232. button_container.appendChild(label_button);
  233. content.appendChild(button_container);
  234.  
  235. widget.appendChild(content);
  236.  
  237. document.getElementById('content_value').appendChild(widget);
  238. $('#twcheese_config_table > tbody').sortable({handle: '.qbhandle', placeholder: 'sortable-placeholder'});
  239. $('#twcheese_config_table > tbody').on('sortstop', function(){
  240. twcheese.MassTag.preview();
  241. twcheese.MassTag.saveConfig();
  242. });
  243.  
  244. return document.getElementById('twcheese_tag_config');
  245. },
  246.  
  247. closeWidget: function () {
  248. $('#twcheese_tag_config_container').remove();
  249. },
  250.  
  251. getFormat: function () {
  252. var format = '';
  253. var inputs = this.widget.getElementsByTagName('input');
  254. var rows = this.widget.getElementsByTagName('tr');
  255. for(var i=0; i<twcheese.MassTag.config.options.length; i++){
  256. if(inputs[i*2].checked)
  257. {
  258. format += inputs[i*2+1].value;
  259. format += '%'+rows[i].optionData.name+'%';
  260. }
  261. }
  262. return format;
  263. },
  264.  
  265. preview: function () {
  266. document.getElementById('twcheese_MassTag_preview').innerHTML = this.getFormat();
  267. },
  268.  
  269. saveConfig: function () {
  270. var rows = this.widget.getElementsByTagName('tr');
  271. var options = new Array();
  272. for (var i=0; i<twcheese.MassTag.config.options.length; i++) {
  273. options[i] = rows[i].optionData;
  274. }
  275.  
  276. this.config.options = options;
  277.  
  278. localStorage.setItem('twcheese.MassTag.config',JSON.stringify(this.config));
  279. console.log('config saved');
  280. },
  281.  
  282. loadConfig: function () {
  283. if (localStorage.getItem('twcheese.MassTag.config')) {
  284. this.config = JSON.parse(localStorage.getItem('twcheese.MassTag.config'));
  285. return true;
  286. } else {
  287. return false;
  288. }
  289. },
  290.  
  291. label: function (format) {
  292. $('#select_all').click();
  293. $('input[name=label_format]').val(format).parents('form').find('input[name=label]').click();
  294. }
  295. };
  296.  
  297. /*==== styles ====*/
  298. if(!twcheese.style)
  299. twcheese.style = {};
  300.  
  301. /**
  302. * @param element:HTMLElement
  303. * @param topColor:String
  304. * @param bottomColor:String
  305. */
  306. twcheese.style.bgVertGradient = function(element, topColor, bottomColor)
  307. {
  308. element.style.backgroundColor = bottomColor;
  309. var browser;
  310. if(/Chrome/.test(navigator.userAgent)|| /AppleWebKit/.test(navigator.userAgent))
  311. browser = 'webkit';
  312. else if(/Firefox/.test(navigator.userAgent))
  313. browser = 'moz';
  314. else if(window.opera)
  315. browser = 'o';
  316. else if(/MSIE/.test(navigator.userAgent))
  317. browser = 'ms';
  318.  
  319. if(browser)
  320. element.style.background = '-' + browser + '-linear-gradient(top, ' + topColor + ', ' + bottomColor +')';
  321. };
  322.  
  323. /**
  324. * @param element:HTMLElement
  325. */
  326. twcheese.style.popupTitleBar = function (element, exit_function) {
  327. element.className = 'twcheese_title_bar';
  328. twcheese.style.bgVertGradient(element, '#DEC378', '#BDA666');
  329. element.style.height = '22px';
  330. element.style.padding = '4px';
  331.  
  332. /*==== exit button ====*/
  333. var exit_button = document.createElement('span');
  334. exit_button.style.backgroundImage = 'url("' + image_base + 'login_close.png")';
  335. exit_button.style.height = '20px';
  336. exit_button.style.width = '20px';
  337. exit_button.style.display = 'inline-block';
  338. exit_button.style.cssFloat = 'right';
  339. exit_button.style.cursor = 'pointer';
  340. exit_button.onclick = exit_function;
  341. element.appendChild(exit_button);
  342. };
  343.  
  344. /*==== register ====*/
  345. var script = {
  346. scriptname: 'Mass Incoming Tagger',
  347. version: 8.21,
  348. author: 'Nicholas Toby',
  349. email: 'cheesasaurus@gmail.com',
  350. broken: false
  351. };
  352. $.post(ScriptAPI.url,script);
  353.  
  354. /*==== Main ====*/
  355. if (game_data.screen == 'overview_villages' && game_data.mode == 'incomings') {
  356. twcheese.MassTag.init();
  357. } else {
  358. UI.InfoMessage('Going to Incoming overview ...', 3000, 'success');
  359. document.location = game_data.link_base_pure + 'overview_villages&mode=incomings';
  360. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement