EyEBURNeR

Untitled

Apr 23rd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. // ==UserScript==
  4. // @id steamlove
  5. // @name steamlove
  6. // @version 2.0.3
  7. // @namespace
  8. // @author http://www.steamgifts.com/user/EyEBURNeR
  9. // @description giveaway management helper. working with steamgifts v2
  10. // @include http://www.steamgifts.com/*
  11. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js
  12. // @run-at document-end
  13. // ==/UserScript==
  14.  
  15. //prepare globals
  16. var bundle_list = [];
  17. var ga_list = [];
  18. var ga = [];
  19. var ga_count = 0;
  20. var ga_progress = 0;
  21.  
  22. eleg_menu();
  23.  
  24. function eleg_menu() {
  25. //add eleg menu
  26. var btn_tpl = $('nav:first .nav__button[href*="support"]').parent();
  27. $('.fa', btn_tpl).removeClass('.fa-plus-circle icon-green');
  28.  
  29. var nav = $(btn_tpl).clone();
  30. $('.nav__button:first', nav).text('ELEG').attr('href', '#');
  31. var navrow_tpl = $('.nav__row:first', nav).clone();
  32.  
  33. $('.nav__row', nav).remove();
  34.  
  35. var row = [{name: 'Current ELEG giveaways', description: 'FTW', href: '#', icon: 'fa-trophy icon-green', id: 'eleg_ftw'}];
  36. for (i in row) {
  37. var navrow = $(navrow_tpl).clone();
  38. $(navrow).attr('href', row[i].href).attr('id', row[i].id);
  39. $('.nav__row__summary__name', navrow).text(row[i].name);
  40. $('.nav__row__summary__description', navrow).text(row[i].description);
  41.  
  42. $('.fa', navrow).addClass(row[i].icon);
  43. $('.nav__absolute-dropdown', nav).append(navrow);
  44. }
  45. $(btn_tpl).parent().append(nav);
  46. }
  47. $('nav:first').on('click', '#eleg_ftw', function () {
  48. $('.featured__container').remove();
  49. var box = $('.page__inner-wrap:first');
  50. $(box).html('test').attr('id', 'eleg');
  51. $('.notification', '#eleg').remove();
  52. document.title = 'Steam Gifts Eleg Management';
  53. $('#eleg').html('<div>Paste source code of <a target="_blank" style="font-weight:bold;color:green;" href="http://steamcommunity.com/groups/EverybodyLEG/discussions/0/864972399765669380/"> <li class="fa fa-external-link"></li> eleg open ga list</a> then click the button:</div>');
  54. $('#eleg')
  55. .append($('<div style="height:100px !important;overflow:hidden"></div>')
  56. .append($('<textarea/>').attr('id', 'source').attr('style', 'width:100%')))
  57. .append($('<a class="featured__action-button" href="#"><i class="fa fa-arrow-circle-right"></i> Check</a>').click(elegCheckGaList))
  58. ;
  59. });
  60. function parseGaDone() {
  61. ga_progress++;
  62. $('#progress').val(ga_progress);
  63. if (ga_progress == ga_count) {
  64. $('#progress').remove();
  65. elegCheckDone();
  66. }
  67.  
  68. }
  69. function elegCheckGaList() {
  70. $(this).after('<progress id="progress"></progress>');
  71. $(this).remove();
  72. var list = $('#source').val();
  73. if( $('.forum_op .content', list).length>0){
  74. var list = $('.forum_op .content',list);
  75. }
  76.  
  77. $('a[href*="/giveaway/"]', list).each(function(){
  78. ga_list.push($(this).attr('href'));
  79. });
  80. for(i in ga_list)
  81. ga[i]={'href':ga_list[i]}
  82.  
  83. ga_count=ga.length;
  84. $('#progress').attr('max',ga_count);
  85. //getBundleList();
  86.  
  87. for(i=0;i<ga_count;i++){
  88. populateGa(i);
  89. }
  90. }
  91. function elegCheckDone() {
  92. $('#eleg').append('<h4>Result : </h4>');
  93. var obj = $('<table/>');
  94. var tr = $('<tr/>');
  95. $(tr)
  96. .append($('<th/>').text('link'))
  97. .append($('<th/>').text('title'))
  98. .append($('<th/>').text('giver'))
  99. .append($('<th/>').text('cv'))
  100. .append($('<th/>').text('status/winner'))
  101. .append($('<th/>').text('B'))
  102. .append($('<th/>').text('NB'))
  103. .append($('<th/>').text('entries'))
  104. .append($('<th/>').text('date'))
  105. ;
  106. $(obj).append(tr);
  107. for (i in ga) {
  108. var g = ga[i];
  109. var tr = $('<tr/>');
  110. var ga_url='http://www.steamgifts.com/giveaway/' + g.id +'/';
  111. $(tr)
  112. .append($('<td/>').html('<a href="'+ga_url+'">'+ga_url+'</a>'))
  113. .append($('<td/>').text(g.title + ','))
  114. .append($('<td/>').text(g.giver))
  115. .append($('<td/>').text(g.is_bundle ? 0 : g.cv))
  116. .append($('<td/>').text(g.status == 'CLOSED' ? g.winner : g.status))
  117. //.append($('<td/>').text(g.is_bundle ? 1 : 0))
  118. //.append($('<td/>').text(g.is_bundle ? 0 : 1))
  119. .append($('<td/>').text('?'))
  120. .append($('<td/>').text('?'))
  121. .append($('<td/>').text(g.entries))
  122. .append($('<td/>').text(g.date))
  123. ;
  124. $(obj).append(tr);
  125. }
  126. $('td',obj).css('border','1px solid #333');
  127. $('#eleg').append(obj);
  128. }
  129.  
  130.  
  131. function populateGa(gaIdx) {
  132. var url = ga[gaIdx].href;
  133. url = url.substring(url.indexOf('url=') + 4);
  134. $.ajax({
  135. url: url,
  136. success: function (page) {
  137.  
  138. ga[gaIdx] = $.extend(ga[gaIdx], parseGa(page, url));
  139. parseGaDone();
  140. },
  141. dataType: 'html'
  142. });
  143. }
  144.  
  145. function parseGa(page, url) {
  146. var g = {};
  147. try {
  148. var winners = [];
  149. g.title = $.trim($('.featured__heading__medium:first', page).text());
  150. g.giver = $('.featured__column a[href*="/user/"]:first', page).text();
  151. g.winner = '';
  152. g.winners = [];
  153. g.status = '';
  154. g.is_failed = false;
  155. g.is_open = false;
  156. g.is_closed = false;
  157. g.is_pending = false;
  158. g.date = $('.featured__column .fa-clock-o', page).parent().find('span:last').text();
  159. g.entries = parseInt($('.live__entry-count', page).text());
  160. g.id = url.split('/giveaway/')[1].split('/')[0];
  161. g.cv = $('.featured__heading>div.featured__heading__small:last', page).text().split('(')[1].split('P')[0];
  162.  
  163. if (g.date.indexOf('Ended ') > -1) {
  164.  
  165. urlwinners = $('.sidebar__navigation__item__link[href*="/winners"]', page).attr('href');
  166. var wdiv;
  167. $.ajax({
  168. url: urlwinners,
  169. async: false,
  170. success: function (wpage) {
  171. wdiv = $('.page__inner-wrap', wpage);
  172. },
  173. dataType: 'html'
  174. });
  175.  
  176. g.is_closed = true;
  177. g.status = 'CLOSED';
  178.  
  179. var received = $('.table__row-inner-wrap', wdiv);
  180. if (received.length) {
  181. $(received).each(function () {
  182. if ($(this).closest('.table__row-outer-wrap').find('.fa-check-circle').length) {
  183. winners.push($('a[href*="/user/"]',this).text());
  184. } else if($(this).closest('.table__row-outer-wrap').find('.fa-question-circle').length) {
  185. winners.push('PENDING');
  186. g.is_pending = true;
  187. g.status = 'PENDING';
  188. }else {
  189. winners.push('NOT RECEIVED');
  190. }
  191. });
  192. } else {
  193. winners.push('FAILED');
  194. g.is_failed = true;
  195. g.status = 'FAILED';
  196. }
  197. g.winners = winners;
  198. g.winner = winners.join(',');
  199. } else {
  200. g.is_open = true;
  201. g.status = 'OPEN';
  202. }
  203.  
  204. /*
  205. g.is_bundle=($.inArray(g.title, bundle_list)>-1);
  206.  
  207. */
  208. } catch (e) {
  209.  
  210. }
  211. return g;
  212. }
  213.  
  214.  
  215. /*
  216. function getBundleList(){
  217. $.ajax({
  218. url: 'http://www.steamgifts.com/create',
  219. async:false,
  220. success: function (page) {
  221. $('#create_form', page).find('option','select:first').each(function(){
  222. if($(this).text().replace(/[^*]/g, "").length)
  223. bundle_list.push($(this).text().replace(' *',''));
  224. });
  225. },
  226. dataType: 'html'
  227. });
  228. }
  229.  
  230. */
Advertisement
Add Comment
Please, Sign In to add comment