BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

requests.js 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. function Vote(amount, requestid) {
  2. if (typeof amount == 'undefined') {
  3. amount = parseInt($('#amount').raw().value);
  4. }
  5. if (amount == 0) {
  6. amount = 20 * 1024 * 1024;
  7. }
  8. var index;
  9. var votecount;
  10. if (!requestid) {
  11. requestid = $('#requestid').raw().value;
  12. votecount = $('#votecount').raw();
  13. index = false;
  14. } else {
  15. votecount = $('#vote_count_' + requestid).raw();
  16. bounty = $('#bounty_' + requestid).raw();
  17. index = true;
  18. }
  19. if (amount > 20 * 1024 * 1024) {
  20. upload = $('#current_uploaded').raw().value;
  21. download = $('#current_downloaded').raw().value;
  22. rr = $('#current_rr').raw().value;
  23. if (amount > 0.3 * (upload - rr * download)) {
  24. if (!confirm('This vote is more than 30% of your buffer. Please confirm that you wish to place this large of a vote.')) {
  25. return false;
  26. }
  27. }
  28. }
  29. ajax.get('requests.php?action=takevote&id=' + requestid + '&auth=' + authkey + '&amount=' + amount, function (response) {
  30. if (response == 'bankrupt') {
  31. save_message("You do not have sufficient upload credit to add " + get_size(amount) + " to this request", true);
  32. return;
  33. } else if (response == 'dupesuccess') {
  34. //No increment
  35. } else if (response == 'success') {
  36. votecount.innerHTML = (parseInt(votecount.innerHTML)) + 1;
  37. }
  38. if ($('#total_bounty').length > 0) {
  39. totalBounty = parseInt($('#total_bounty').raw().value);
  40. totalBounty += (amount * (1 - $('#request_tax').raw().value));
  41. $('#total_bounty').raw().value = totalBounty;
  42. $('#formatted_bounty').raw().innerHTML = get_size(totalBounty);
  43. save_message("Your vote of " + get_size(amount) + ", adding a " + get_size(amount * (1 - $('#request_tax').raw().value)) + " bounty, has been added");
  44. $('#button').raw().disabled = true;
  45. } else {
  46. save_message("Your vote of " + get_size(amount) + " has been added");
  47. }
  48. }
  49. );
  50. }
  51. function Calculate() {
  52. if (!$('#unit').raw()) { return; }
  53. var mul = (($('#unit').raw().options[$('#unit').raw().selectedIndex].value == 'mb') ? (1024 * 1024) : (1024 * 1024 * 1024));
  54. var amt = Math.floor($('#amount_box').raw().value * mul);
  55. if (amt > $('#current_uploaded').raw().value) {
  56. $('#new_uploaded').raw().innerHTML = "You can't afford that request!";
  57. $('#new_bounty').raw().innerHTML = "0.00 MB";
  58. $('#bounty_after_tax').raw().innerHTML = "0.00 MB";
  59. $('#button').raw().disabled = true;
  60. } else if (isNaN($('#amount_box').raw().value)
  61. || (window.location.search.indexOf('action=new') != -1 && $('#amount_box').raw().value * mul < 100 * 1024 * 1024)
  62. || (window.location.search.indexOf('action=view') != -1 && $('#amount_box').raw().value * mul < 20 * 1024 * 1024)) {
  63. $('#new_uploaded').raw().innerHTML = get_size(($('#current_uploaded').raw().value));
  64. $('#new_bounty').raw().innerHTML = "0.00 MB";
  65. $('#bounty_after_tax').raw().innerHTML = "0.00 MB";
  66. $('#button').raw().disabled = true;
  67. } else {
  68. $('#button').raw().disabled = false;
  69. $('#amount').raw().value = amt;
  70. $('#new_uploaded').raw().innerHTML = get_size(($('#current_uploaded').raw().value) - amt);
  71. $('#new_ratio').raw().innerHTML = ratio($('#current_uploaded').raw().value - amt, $('#current_downloaded').raw().value);
  72. $('#new_bounty').raw().innerHTML = get_size(mul * $('#amount_box').raw().value);
  73. $('#bounty_after_tax').raw().innerHTML = get_size(mul * 0.9 * $('#amount_box').raw().value);
  74. }
  75. }
  76. /*
  77. var ArtistCount = 1;
  78. function AddArtistField() {
  79. window.getSelection().removeAllRanges()
  80. ArtistCount = $('input[name="artists[]"]').length;
  81. if (ArtistCount >= 200) {
  82. return;
  83. }
  84. var ArtistField = document.createElement("input");
  85. ArtistField.type = "text";
  86. ArtistField.id = "artists_" + ArtistCount;
  87. ArtistField.name = "artists[]";
  88. ArtistField.size = 45;
  89. var x = $('#artistfields').raw();
  90. x.appendChild(document.createElement("br"));
  91. x.appendChild(ArtistField);
  92. x.appendChild(document.createTextNode('\n'));
  93. if ($("#artists_0").data("gazelle-autocomplete")) {
  94. $(ArtistField).on('focus', function () {
  95. $(ArtistField).autocomplete({
  96. serviceUrl: ARTIST_AUTOCOMPLETE_URL
  97. });
  98. });
  99. }
  100. ArtistCount++;
  101. }
  102. */
  103. /*
  104. function RemoveArtistField() {
  105. window.getSelection().removeAllRanges()
  106. ArtistCount = $('input[name="artists[]"]').length;
  107. if (ArtistCount == 1) {
  108. return;
  109. }
  110. var x = $('#artistfields').raw();
  111. for (i = 0; i < 3; i++) {
  112. x.removeChild(x.lastChild);
  113. }
  114. ArtistCount--;
  115. }
  116. */
  117. function add_tag() {
  118. if ($('#tags').raw().value == "") {
  119. $('#tags').raw().value = $('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value;
  120. } else if ($('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value == "---") {
  121. } else {
  122. $('#tags').raw().value = $('#tags').raw().value + ", " + $('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value;
  123. }
  124. }
  125. function Toggle(id, disable) {
  126. var arr = document.getElementsByName(id + '[]');
  127. var master = $('#toggle_' + id).raw().checked;
  128. for (var x in arr) {
  129. arr[x].checked = master;
  130. if (disable == 1) {
  131. arr[x].disabled = master;
  132. }
  133. }
  134. if (id == "formats") {
  135. ToggleLogCue();
  136. }
  137. }
  138. function ToggleLogCue() {
  139. var formats = document.getElementsByName('formats[]');
  140. var flac = false;
  141. if (formats[1].checked) {
  142. flac = true;
  143. }
  144. if (flac) {
  145. $('#logcue_tr').gshow();
  146. } else {
  147. $('#logcue_tr').ghide();
  148. }
  149. ToggleLogScore();
  150. }
  151. function ToggleLogScore() {
  152. if ($('#needlog').raw().checked) {
  153. $('#minlogscore_span').gshow();
  154. } else {
  155. $('#minlogscore_span').ghide();
  156. }
  157. }
  158. function JavAutofill() {
  159. var map = {
  160. cn: 'javdb',
  161. idols: 'artist',
  162. title: 'title',
  163. title_jp: 'title_jp',
  164. image: 'image',
  165. tags: 'tags',
  166. description: 'req_desc'
  167. }
  168. var cn = $('#catalogue').raw().value.toUpperCase()
  169. $.getJSON('/api.php?action=javfill&cn=' + cn, function (data) {
  170. if (data.status != "success") {
  171. $('#catalogue').raw().value = 'Failed'
  172. return
  173. } else {
  174. $('#catalogue').raw().value = data.response.cn
  175. }
  176. for (i in data.response) {
  177. if (Array.isArray(data.response[i])) {
  178. for (j in data.response[i]) {
  179. if (i == 'idols') {
  180. if (!($('#' + map[i] + '_' + j).raw())) {
  181. AddArtistField()
  182. }
  183. $('#' + map[i] + '_' + j).raw().value = data.response[i][j]
  184. }
  185. if (map[i] == 'tags' && !($('#' + map[i]).raw().value)) {
  186. $('#' + map[i]).raw().value = data.response[i].join(', ')
  187. }
  188. }
  189. }
  190. if (map[i] && $('#' + map[i]).raw() && !($('#' + map[i]).raw().value)) {
  191. $('#' + map[i]).raw().value = data.response[i]
  192. }
  193. }
  194. })
  195. }
  196. $(function () {
  197. Categories()
  198. Calculate()
  199. document.querySelectorAll('[autofill]').forEach(function (el) {
  200. el.addEventListener('click', function (event) {
  201. ({ 'jav': JavAutofill })[el.attributes['autofill'].value]()
  202. })
  203. })
  204. $(document).on('click', '.add_artist_button', AddArtistField);
  205. $(document).on('click', '.remove_artist_button', RemoveArtistField);
  206. })