EyEBURNeR

steamgifts eleg manager

May 12th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. // ==UserScript==
  2. // @id steamlove
  3. // @name steamlove
  4. // @version 1.0
  5. // @namespace
  6. // @author EyEBURNeR
  7. // @description giveaway management helper
  8. // @include http://www.steamgifts.com/*
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. var $ = unsafeWindow.jQuery;
  13.  
  14. //prepare globals
  15. var bundle_list=[];
  16. var ga_list=[];
  17. var ga=[];
  18. var ga_count=0;
  19. var ga_progress=0;
  20.  
  21. //add eleg menu
  22. var obj=$('#navigation ol > li:eq(1)').clone();
  23. $(obj).attr('id','elegmenu').find('.arrow').text('Eleg');
  24. $('#navigation ol').append(obj);
  25. var elegmenu=$('#elegmenu .absolute-dropdown ul');
  26. var obj_li=$('li:first', elegmenu).clone();
  27. $('li', elegmenu).remove();
  28. //add eleg menu links
  29. $('a', obj_li).attr('href','/support/list').text('Check GA list');
  30. $(elegmenu).append($(obj_li).clone());
  31.  
  32. // Check GA list page
  33. if(document.location.href.indexOf('/support/list')!==-1){
  34. elegInit();
  35.  
  36. $('#eleg').html('<div>Paste source code of <a target="_blank" href="http://steamcommunity.com/groups/EverybodyLEG/discussions/0/864957817400238292/">eleg open ga list</a> then click the button:</div>');
  37. $('#eleg').append($('<textarea/>').attr('id','source').attr('style','width:100%')) .append($('<button/>').click(elegCheckGaList).text('Check'));
  38. function parseGaDone(){
  39. ga_progress++;
  40. $('#progress').val(ga_progress);
  41. if(ga_progress==ga_count){
  42. $('#progress').remove();
  43. elegCheckDone();
  44. }
  45.  
  46. }
  47. }
  48.  
  49. function elegCheckGaList(){
  50. $(this).after('<progress id="progress"></progress>');
  51. $(this).remove();
  52. var list=$('.forum_op .content', $('#source').val());
  53. console.log('Begin of process');
  54.  
  55. $('a[href*="/giveaway/"]', list).each(function(){
  56. ga_list.push($(this).attr('href'));
  57. });
  58. for(i in ga_list)
  59. ga[i]={'href':ga_list[i]}
  60.  
  61. ga_count=ga.length;
  62. $('#progress').attr('max',ga_count);
  63. getBundleList();
  64.  
  65. for(i=0;i<ga_count;i++){
  66. populateGa(i);
  67. }
  68. }
  69. function elegCheckDone(){
  70. $('#eleg').append('<h4>Result : </h4>');
  71. var obj=$('<table/>');
  72. var tr=$('<tr/>');
  73. $(tr)
  74. .append($('<th/>').text('link'))
  75. .append($('<th/>').text('title'))
  76. .append($('<th/>').text('giver'))
  77. .append($('<th/>').text('cv'))
  78. .append($('<th/>').text('status/winner'))
  79. .append($('<th/>').text('B'))
  80. .append($('<th/>').text('NB'))
  81. ;
  82. $(obj).append(tr);
  83. for(i in ga){
  84. var g=ga[i];
  85. var tr=$('<tr/>');
  86. $(tr)
  87. .append($('<td/>').text('http://www.steamgifts.com/giveaway/'+g.id))
  88. .append($('<td/>').text(g.title+','))
  89. .append($('<td/>').text(g.giver))
  90. .append($('<td/>').text(g.is_bundle ? 0:g.cv))
  91. .append($('<td/>').text(g.status=='CLOSED' ? g.winner:g.status))
  92. .append($('<td/>').text(g.is_bundle ? 1:0))
  93. .append($('<td/>').text(g.is_bundle ? 0:1))
  94. ;
  95. $(obj).append(tr);
  96. }
  97. GM_addStyle("#eleg table td{border:1px solid #333}");
  98. $('#eleg').append(obj);
  99. }
  100.  
  101. function populateGa(gaIdx){
  102. var url=ga[gaIdx].href;
  103. $.ajax({
  104. url: url,
  105. success: function (page) {
  106. ga[gaIdx] = $.extend(ga[gaIdx], parseGa(page,url));
  107. console.log(ga[gaIdx]);
  108. parseGaDone();
  109. },
  110. dataType: 'html'
  111. });
  112. }
  113.  
  114. function parseGa(page,url){
  115. var g={};
  116. try{
  117. var winners=[];
  118. g.title=$.trim( $('.featured .title', page ).contents(':not(span)').text() );
  119. g.is_bundle=($.inArray(g.title, bundle_list)>-1);
  120. g.giver=$('.hosted_by a span',page).text();
  121. g.winner='';
  122. g.winners=[];
  123. g.status='';
  124. g.is_failed=false;
  125. g.is_open=false;
  126. g.is_closed=false;
  127. g.is_pending=false;
  128. g.id=url.split('/giveaway/')[1].split('/')[0];
  129. g.cv=$('.steam_store', page ).text().split('$')[1].split(')')[0];
  130. if($('.winners_heading',page).length){
  131. g.is_closed=true;
  132. g.status='CLOSED';
  133. var received=$('.winners .username',page);
  134. if(received.length){
  135. $('.winners .username a', page).each(function(){
  136. if($(this).closest('.details').find('.negative').length){
  137. winners.push('NOT RECEIVED');
  138. }else{
  139. winners.push($(this).text());
  140. }
  141. });
  142. }else{
  143. winners.push('FAILED');
  144. g.is_failed=true;
  145. g.status='FAILED';
  146. }
  147. if(!winners.length){
  148. g.is_pending=true;
  149. g.status='PENDING';
  150. }
  151. g.winners=winners;
  152. g.winner=winners.join(',');
  153. }else{
  154. g.is_open=true;
  155. g.status='OPEN';
  156. }
  157. }catch(e){
  158. console.log(e);
  159.  
  160. }
  161. return g;
  162. }
  163.  
  164. function elegInit(){
  165. $('.wrapper .content:first').attr('id','eleg');
  166. $('.notification', '#eleg').remove();
  167. document.title='Steam Gifts Eleg Management';
  168. }
  169.  
  170. function getBundleList(){
  171. $.ajax({
  172. url: 'http://www.steamgifts.com/create',
  173. async:false,
  174. success: function (page) {
  175. $('#create_form', page).find('option','select:first').each(function(){
  176. if($(this).text().replace(/[^*]/g, "").length)
  177. bundle_list.push($(this).text().replace(' *',''));
  178. });
  179. },
  180. dataType: 'html'
  181. });
  182. }
Advertisement
Add Comment
Please, Sign In to add comment