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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. function AddArtistField() {
  77. var ArtistCount = document.getElementsByName("artists[]").length;
  78. if (ArtistCount >= 200) {
  79. return;
  80. }
  81. var ArtistField = document.createElement("input");
  82. ArtistField.type = "text";
  83. ArtistField.id = "artist_" + ArtistCount;
  84. ArtistField.name = "artists[]";
  85. ArtistField.size = 45;
  86. var x = $('#artistfields').raw();
  87. x.appendChild(document.createElement("br"));
  88. x.appendChild(ArtistField);
  89. if ($("#artist").data("gazelle-autocomplete")) {
  90. $(ArtistField).live('focus', function () {
  91. $(ArtistField).autocomplete({
  92. serviceUrl: 'artist.php?action=autocomplete'
  93. });
  94. });
  95. }
  96. ArtistCount++;
  97. }
  98. function RemoveArtistField() {
  99. var ArtistCount = document.getElementsByName("artists[]").length;
  100. if (ArtistCount == 1) {
  101. return;
  102. }
  103. var x = $('#artistfields').raw();
  104. while (x.lastChild.tagName != "INPUT") {
  105. x.removeChild(x.lastChild);
  106. }
  107. x.removeChild(x.lastChild);
  108. x.removeChild(x.lastChild); // Remove trailing new line.
  109. ArtistCount--;
  110. }
  111. function Categories() {
  112. /*
  113. var cat = $('#categories').raw() ? $('#categories').raw().options[$('#categories').raw().selectedIndex].value : '';
  114. if (cat == "Movies") {
  115. $('#artist_tr').gshow();
  116. $('#cataloguenumber_tr').gshow();
  117. $('#dlsiteid_tr').ghide();
  118. } else if (cat == "Anime") {
  119. $('#artist_tr').gshow();
  120. $('#cataloguenumber_tr').ghide();
  121. $('#dlsiteid_tr').ghide();
  122. } else if (cat == "Manga") {
  123. $('#artist_tr').gshow();
  124. $('#cataloguenumber_tr').ghide();
  125. $('#dlsiteid_tr').ghide();
  126. } else if (cat == "Games") {
  127. $('#artist_tr').gshow();
  128. $('#dlsiteid_tr').gshow();
  129. $('#cataloguenumber_tr').ghide();
  130. } else if (cat == "Audio") {
  131. $('#artist_tr').gshow();
  132. $('#dlsiteid_tr').ghide();
  133. $('#cataloguenumber_tr').ghide();
  134. } else {
  135. $('#artist_tr').ghide();
  136. $('#cataloguenumber_tr').ghide();
  137. $('#dlsiteid_tr').ghide();
  138. }
  139. */
  140. }
  141. function add_tag() {
  142. if ($('#tags').raw().value == "") {
  143. $('#tags').raw().value = $('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value;
  144. } else if ($('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value == "---") {
  145. } else {
  146. $('#tags').raw().value = $('#tags').raw().value + ", " + $('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value;
  147. }
  148. }
  149. function Toggle(id, disable) {
  150. var arr = document.getElementsByName(id + '[]');
  151. var master = $('#toggle_' + id).raw().checked;
  152. for (var x in arr) {
  153. arr[x].checked = master;
  154. if (disable == 1) {
  155. arr[x].disabled = master;
  156. }
  157. }
  158. if (id == "formats") {
  159. ToggleLogCue();
  160. }
  161. }
  162. function ToggleLogCue() {
  163. var formats = document.getElementsByName('formats[]');
  164. var flac = false;
  165. if (formats[1].checked) {
  166. flac = true;
  167. }
  168. if (flac) {
  169. $('#logcue_tr').gshow();
  170. } else {
  171. $('#logcue_tr').ghide();
  172. }
  173. ToggleLogScore();
  174. }
  175. function ToggleLogScore() {
  176. if ($('#needlog').raw().checked) {
  177. $('#minlogscore_span').gshow();
  178. } else {
  179. $('#minlogscore_span').ghide();
  180. }
  181. }
  182. function JavAutofill() {
  183. var map = {
  184. cn: 'javdb',
  185. idols: 'artist',
  186. title: 'title',
  187. title_jp: 'title_jp',
  188. image: 'image',
  189. tags: 'tags',
  190. description: 'req_desc'
  191. }
  192. var cn = $('#catalogue').raw().value.toUpperCase()
  193. $.getJSON('/ajax.php?action=javfill&cn=' + cn, function (data) {
  194. if (data.status != "success") {
  195. $('#catalogue').raw().value = 'Failed'
  196. return
  197. } else {
  198. $('#catalogue').raw().value = data.response.cn
  199. }
  200. for (i in data.response) {
  201. if (Array.isArray(data.response[i])) {
  202. for (j in data.response[i]) {
  203. if (i == 'idols') {
  204. if (!($('#' + map[i] + '_' + j).raw())) {
  205. AddArtistField()
  206. }
  207. $('#' + map[i] + '_' + j).raw().value = data.response[i][j]
  208. }
  209. if (map[i] == 'tags' && !($('#' + map[i]).raw().value)) {
  210. $('#' + map[i]).raw().value = data.response[i].join(', ')
  211. }
  212. }
  213. }
  214. if (map[i] && $('#' + map[i]).raw() && !($('#' + map[i]).raw().value)) {
  215. $('#' + map[i]).raw().value = data.response[i]
  216. }
  217. }
  218. })
  219. }
  220. $(function () {
  221. Categories()
  222. Calculate()
  223. document.querySelectorAll('[autofill]').forEach(function (el) {
  224. el.addEventListener('click', function (event) {
  225. ({ 'jav': JavAutofill })[el.attributes['autofill'].value]()
  226. })
  227. })
  228. $(document).on('click', '.add_artist_button', AddArtistField);
  229. $(document).on('click', '.remove_artist_button', RemoveArtistField);
  230. })