Oppaitime'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 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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_0").data("gazelle-autocomplete")) {
  90. $(ArtistField).on('focus', function() {
  91. $(ArtistField).autocomplete({
  92. deferRequestBy: 300,
  93. serviceUrl : ARTIST_AUTOCOMPLETE_URL
  94. });
  95. });
  96. }
  97. ArtistCount++;
  98. }
  99. function RemoveArtistField() {
  100. var ArtistCount = document.getElementsByName("artists[]").length;
  101. if (ArtistCount == 1) {
  102. return;
  103. }
  104. var x = $('#artistfields').raw();
  105. while (x.lastChild.tagName != "INPUT") {
  106. x.removeChild(x.lastChild);
  107. }
  108. x.removeChild(x.lastChild);
  109. x.removeChild(x.lastChild); //Remove trailing new line.
  110. ArtistCount--;
  111. }
  112. function Categories() {
  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. function add_tag() {
  141. if ($('#tags').raw().value == "") {
  142. $('#tags').raw().value = $('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value;
  143. } else if ($('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value == "---") {
  144. } else {
  145. $('#tags').raw().value = $('#tags').raw().value + ", " + $('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value;
  146. }
  147. }
  148. function Toggle(id, disable) {
  149. var arr = document.getElementsByName(id + '[]');
  150. var master = $('#toggle_' + id).raw().checked;
  151. for (var x in arr) {
  152. arr[x].checked = master;
  153. if (disable == 1) {
  154. arr[x].disabled = master;
  155. }
  156. }
  157. if (id == "formats") {
  158. ToggleLogCue();
  159. }
  160. }
  161. function ToggleLogCue() {
  162. var formats = document.getElementsByName('formats[]');
  163. var flac = false;
  164. if (formats[1].checked) {
  165. flac = true;
  166. }
  167. if (flac) {
  168. $('#logcue_tr').gshow();
  169. } else {
  170. $('#logcue_tr').ghide();
  171. }
  172. ToggleLogScore();
  173. }
  174. function ToggleLogScore() {
  175. if ($('#needlog').raw().checked) {
  176. $('#minlogscore_span').gshow();
  177. } else {
  178. $('#minlogscore_span').ghide();
  179. }
  180. }
  181. function JavAutofill() {
  182. var map = { cn: 'javdb',
  183. idols: 'artist',
  184. title: 'title',
  185. title_jp: 'title_jp',
  186. image: 'image',
  187. tags: 'tags',
  188. description: 'req_desc' }
  189. var cn = $('#catalogue').raw().value.toUpperCase()
  190. $.getJSON('/ajax.php?action=javfill&cn='+cn, function(data) {
  191. if (data.status != "success") {
  192. $('#catalogue').raw().value = 'Failed'
  193. return
  194. } else {
  195. $('#catalogue').raw().value = data.response.cn
  196. }
  197. for (i in data.response) {
  198. if (Array.isArray(data.response[i])) {
  199. for (j in data.response[i]) {
  200. if (i == 'idols') {
  201. if (!($('#'+map[i]+'_'+j).raw())) {
  202. AddArtistField()
  203. }
  204. $('#'+map[i]+'_'+j).raw().value = data.response[i][j]
  205. }
  206. if (map[i] == 'tags' && !($('#'+map[i]).raw().value)) {
  207. $('#'+map[i]).raw().value = data.response[i].join(', ')
  208. }
  209. }
  210. }
  211. if (map[i] && $('#'+map[i]).raw() && !($('#'+map[i]).raw().value)) {
  212. $('#'+map[i]).raw().value = data.response[i]
  213. }
  214. }
  215. })
  216. }
  217. $(function() {
  218. Categories()
  219. Calculate()
  220. document.querySelectorAll('[autofill]').forEach(function(el) {
  221. el.addEventListener('click', function(event) {
  222. ({'jav':JavAutofill})[el.attributes['autofill'].value]()
  223. })
  224. })
  225. $(document).on('click', '.add_artist_button', AddArtistField);
  226. $(document).on('click', '.remove_artist_button', RemoveArtistField);
  227. })