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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. var cat = $('#categories').raw() ? $('#categories').raw().options[$('#categories').raw().selectedIndex].value : '';
  113. if (cat == "Movies") {
  114. $('#artist_tr').gshow();
  115. $('#cataloguenumber_tr').gshow();
  116. $('#dlsiteid_tr').ghide();
  117. } else if (cat == "Anime") {
  118. $('#artist_tr').gshow();
  119. $('#cataloguenumber_tr').ghide();
  120. $('#dlsiteid_tr').ghide();
  121. } else if (cat == "Manga") {
  122. $('#artist_tr').gshow();
  123. $('#cataloguenumber_tr').ghide();
  124. $('#dlsiteid_tr').ghide();
  125. } else if (cat == "Games") {
  126. $('#artist_tr').gshow();
  127. $('#dlsiteid_tr').gshow();
  128. $('#cataloguenumber_tr').ghide();
  129. } else if (cat == "Audio") {
  130. $('#artist_tr').gshow();
  131. $('#dlsiteid_tr').ghide();
  132. $('#cataloguenumber_tr').ghide();
  133. } else {
  134. $('#artist_tr').ghide();
  135. $('#cataloguenumber_tr').ghide();
  136. $('#dlsiteid_tr').ghide();
  137. }
  138. }
  139. function add_tag() {
  140. if ($('#tags').raw().value == "") {
  141. $('#tags').raw().value = $('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value;
  142. } else if ($('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value == "---") {
  143. } else {
  144. $('#tags').raw().value = $('#tags').raw().value + ", " + $('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value;
  145. }
  146. }
  147. function Toggle(id, disable) {
  148. var arr = document.getElementsByName(id + '[]');
  149. var master = $('#toggle_' + id).raw().checked;
  150. for (var x in arr) {
  151. arr[x].checked = master;
  152. if (disable == 1) {
  153. arr[x].disabled = master;
  154. }
  155. }
  156. if (id == "formats") {
  157. ToggleLogCue();
  158. }
  159. }
  160. function ToggleLogCue() {
  161. var formats = document.getElementsByName('formats[]');
  162. var flac = false;
  163. if (formats[1].checked) {
  164. flac = true;
  165. }
  166. if (flac) {
  167. $('#logcue_tr').gshow();
  168. } else {
  169. $('#logcue_tr').ghide();
  170. }
  171. ToggleLogScore();
  172. }
  173. function ToggleLogScore() {
  174. if ($('#needlog').raw().checked) {
  175. $('#minlogscore_span').gshow();
  176. } else {
  177. $('#minlogscore_span').ghide();
  178. }
  179. }
  180. function JavAutofill() {
  181. var map = { cn: 'javdb',
  182. idols: 'artist',
  183. title: 'title',
  184. title_jp: 'title_jp',
  185. image: 'image',
  186. tags: 'tags',
  187. description: 'req_desc' }
  188. var cn = $('#catalogue').raw().value.toUpperCase()
  189. $.getJSON('/ajax.php?action=javfill&cn='+cn, function(data) {
  190. if (data.status != "success") {
  191. $('#catalogue').raw().value = 'Failed'
  192. return
  193. } else {
  194. $('#catalogue').raw().value = data.response.cn
  195. }
  196. for (i in data.response) {
  197. if (Array.isArray(data.response[i])) {
  198. for (j in data.response[i]) {
  199. if (i == 'idols') {
  200. if (!($('#'+map[i]+'_'+j).raw())) {
  201. AddArtistField()
  202. }
  203. $('#'+map[i]+'_'+j).raw().value = data.response[i][j]
  204. }
  205. if (map[i] == 'tags' && !($('#'+map[i]).raw().value)) {
  206. $('#'+map[i]).raw().value = data.response[i].join(', ')
  207. }
  208. }
  209. }
  210. if (map[i] && $('#'+map[i]).raw() && !($('#'+map[i]).raw().value)) {
  211. $('#'+map[i]).raw().value = data.response[i]
  212. }
  213. }
  214. })
  215. }
  216. $(function() {
  217. Categories()
  218. Calculate()
  219. document.querySelectorAll('[autofill]').forEach(function(el) {
  220. el.addEventListener('click', function(event) {
  221. ({'jav':JavAutofill})[el.attributes['autofill'].value]()
  222. })
  223. })
  224. $(document).on('click', '.add_artist_button', AddArtistField);
  225. $(document).on('click', '.remove_artist_button', RemoveArtistField);
  226. })