EyEBURNeR

steamgifts eleg manager 2.0.2

May 29th, 2013
146
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.2
  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 = $('.forum_op .content', $('#source').val());
  73.         $('a[href*="/giveaway/"]', list).each(function(){
  74.         ga_list.push($(this).attr('href'));
  75.         });
  76.         for(i in ga_list)
  77.         ga[i]={'href':ga_list[i]}
  78.      
  79.         ga_count=ga.length;
  80.         $('#progress').attr('max',ga_count);
  81.         //getBundleList();
  82.      
  83.         for(i=0;i<ga_count;i++){
  84.         populateGa(i);
  85.         }
  86.     }
  87.     function elegCheckDone() {
  88.         $('#eleg').append('<h4>Result : </h4>');
  89.         var obj = $('<table/>');
  90.         var tr = $('<tr/>');
  91.         $(tr)
  92.                 .append($('<th/>').text('link'))
  93.                 .append($('<th/>').text('title'))
  94.                 .append($('<th/>').text('giver'))
  95.                 .append($('<th/>').text('cv'))
  96.                 .append($('<th/>').text('status/winner'))
  97.                 .append($('<th/>').text('B'))
  98.                 .append($('<th/>').text('NB'))
  99.                 .append($('<th/>').text('entries'))
  100.                 .append($('<th/>').text('date'))
  101.                 ;
  102.         $(obj).append(tr);
  103.         for (i in ga) {
  104.             var g = ga[i];
  105.             var tr = $('<tr/>');
  106.             var ga_url='http://www.steamgifts.com/giveaway/' + g.id +'/';
  107.             $(tr)
  108.                     .append($('<td/>').html('<a href="'+ga_url+'">'+ga_url+'</a>'))
  109.                     .append($('<td/>').text(g.title + ','))
  110.                     .append($('<td/>').text(g.giver))
  111.                     .append($('<td/>').text(g.is_bundle ? 0 : g.cv))
  112.                     .append($('<td/>').text(g.status == 'CLOSED' ? g.winner : g.status))
  113.                     //.append($('<td/>').text(g.is_bundle ? 1 : 0))
  114.                     //.append($('<td/>').text(g.is_bundle ? 0 : 1))
  115.                     .append($('<td/>').text('?'))
  116.                     .append($('<td/>').text('?'))
  117.                     .append($('<td/>').text(g.entries))
  118.                     .append($('<td/>').text(g.date))
  119.                     ;
  120.             $(obj).append(tr);
  121.         }
  122.         GM_addStyle("#eleg table td{border:1px solid #333}");
  123.         $('#eleg').append(obj);
  124.     }
  125.      
  126.      
  127.     function populateGa(gaIdx) {
  128.         var url = ga[gaIdx].href;
  129.         url = url.substring(url.indexOf('url=') + 4);
  130.         $.ajax({
  131.             url: url,
  132.             success: function (page) {
  133.      
  134.                 ga[gaIdx] = $.extend(ga[gaIdx], parseGa(page, url));
  135.                 parseGaDone();
  136.             },
  137.             dataType: 'html'
  138.         });
  139.     }
  140.      
  141.     function parseGa(page, url) {
  142.         var g = {};
  143.         try {
  144.             var winners = [];
  145.             g.title = $.trim($('.featured__heading__medium:first', page).text());
  146.             g.giver = $('.featured__column a[href*="/user/"]:first', page).text();
  147.             g.winner = '';
  148.             g.winners = [];
  149.             g.status = '';
  150.             g.is_failed = false;
  151.             g.is_open = false;
  152.             g.is_closed = false;
  153.             g.is_pending = false;
  154.             g.date = $('.featured__column .fa-clock-o', page).parent().find('span:last').text();
  155.             g.entries = parseInt($('.live__entry-count', page).text());
  156.             g.id = url.split('/giveaway/')[1].split('/')[0];
  157.             g.cv = $('.featured__heading>div.featured__heading__small:last', page).text().split('(')[1].split('P')[0];
  158.      
  159.             if (g.date.indexOf('Ended ') > -1) {
  160.      
  161.                 urlwinners = $('.sidebar__navigation__item__link[href*="/winners"]', page).attr('href');
  162.                 var wdiv;
  163.                 $.ajax({
  164.                     url: urlwinners,
  165.                     async: false,
  166.                     success: function (wpage) {
  167.                         wdiv = $('.page__inner-wrap', wpage);
  168.                     },
  169.                     dataType: 'html'
  170.                 });
  171.      
  172.                 g.is_closed = true;
  173.                 g.status = 'CLOSED';
  174.      
  175.                 var received = $('.table__row-inner-wrap', wdiv);
  176.                 if (received.length) {
  177.                     $(received).each(function () {
  178.                         if ($(this).closest('.table__row-outer-wrap').find('.fa-check-circle').length) {
  179.                             winners.push($('a[href*="/user/"]',this).text());
  180.                         } else if($(this).closest('.table__row-outer-wrap').find('.fa-question-circle').length)  {
  181.                             winners.push('PENDING');
  182.                             g.is_pending = true;
  183.                             g.status = 'PENDING';
  184.                         }else {
  185.                             winners.push('NOT RECEIVED');
  186.                         }
  187.                     });
  188.                 } else {
  189.                     winners.push('FAILED');
  190.                     g.is_failed = true;
  191.                     g.status = 'FAILED';
  192.                 }
  193.                 g.winners = winners;
  194.                 g.winner = winners.join(',');
  195.             } else {
  196.                 g.is_open = true;
  197.                 g.status = 'OPEN';
  198.             }
  199.      
  200.             /*
  201.              g.is_bundle=($.inArray(g.title, bundle_list)>-1);
  202.              
  203.              */
  204.         } catch (e) {
  205.      
  206.         }
  207.         return g;
  208.     }
  209.      
  210.      
  211.     /*
  212.      function getBundleList(){
  213.      $.ajax({
  214.      url: 'http://www.steamgifts.com/create',
  215.      async:false,
  216.      success: function (page) {                
  217.      $('#create_form', page).find('option','select:first').each(function(){
  218.      if($(this).text().replace(/[^*]/g, "").length)
  219.      bundle_list.push($(this).text().replace(' *',''));                                            
  220.      });
  221.      },
  222.      dataType: 'html'
  223.      });
  224.      }
  225.      
  226.      */
Advertisement
Add Comment
Please, Sign In to add comment