Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @id steamlove
- // @name steamlove
- // @version 3.01
- // @namespace
- // @author http://www.steamgifts.com/user/EyEBURNeR
- // @description giveaway management helper. Rewritten and optimized, tested on FF but now should also works in Chrome.
- // @include https://www.steamgifts.com/*
- // @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js
- // @grant GM_xmlhttpRequest
- // @grant GM_addStyle
- // @run-at document-end
- // ==/UserScript==
- // http://pastebin.com/1GgePS99
- // static parameters
- var eleg_galist="http://steamcommunity.com/groups/EverybodyLEG/discussions/0/864972399765669380/";
- //prepare globals
- var bundle_list = [];
- var ga_list = [];
- var ga = [];
- var ga_count = 0;
- var ga_progress = 0;
- // add eleg button to SG menu
- $('.nav__left-container:first').append('<div class="nav__button-container"><a id="eleg_ftw" class="nav__button" href="#">ELEG</a></div>');
- // init ELEG GA list screen, automatically load the list from ELEG forum
- $('nav:first').on('click', '#eleg_ftw', function () {
- $('.featured__container').remove();
- var box = $('.page__inner-wrap:first');
- $(box).html('').attr('id', 'eleg');
- $('.notification', '#eleg').remove();
- document.title = 'Steam Gifts Eleg Management';
- $('#eleg').html('<div style="height:100px !important;overflow:hidden">Source code from <a href="'+eleg_galist+'" target="_blank">'+eleg_galist+'</a><textarea id="source" style="width:100%">Please wait, trying to automatically load the GA list from steam…</textarea></div>');
- GM_xmlhttpRequest({
- method: "GET",
- url: eleg_galist ,
- onload: function(response) {
- var source=optimise_raw_html(response.responseText);
- if(source.indexOf('An error was encountered while')==-1){
- $('#source').val(source);
- }else{
- $('#source').val('Could not retreive the source automatically, please manually paste it from:\n\n '+eleg_galist);
- }
- $('#eleg').append($('<a class="featured__action-button" href="#"><i class="fa fa-arrow-circle-right"></i> Check</a>').click(elegCheckGaList));
- }
- });
- });
- // optimise string to be parsed
- function optimise_raw_html(page){
- return page.replace(/<img[^>]+>/ig,'')
- }
- // parse source code to extract sg ga urls, will call populateGa() for each GA found
- function elegCheckGaList() {
- $(this).after('<progress id="progress"></progress>');
- $(this).remove();
- var list=optimise_raw_html($('#source').val());
- if( $('.forum_op .content', list).length>0){
- list=$('.forum_op .content', list); // the whole is available, keep only the op content
- }else{
- list='<b>'+list+'</b>'; // make it a valid DOM object
- }
- // find all GA urls
- $('a[href*="/giveaway/"]', list).each(function(){
- ga_list.push($(this).attr('href'));
- });
- for(i in ga_list){
- ga[i]={'href':ga_list[i]}
- }
- // keep track of the # of GA to be loaded and parsed
- ga_count=ga.length;
- $('#progress').attr('max',ga_count);
- //getBundleList(); still no easy way to get the list in SG v2.
- //begin the loading and parsing
- for(i=0;i<ga_count;i++){
- populateGa(i);
- }
- }
- // background loading of a GA page, will call parseGa() and parseGADone()
- function populateGa(gaIdx) {
- var url = ga[gaIdx].href;
- // get only the sg GA code and build the short url
- url = '/giveaway/'+url.substring(url.indexOf('url=') + 4).split('//www.steamgifts.com/giveaway/')[1].split('/')[0]+'/';
- $.ajax({
- url: url,
- contentType: 'text/plain',
- success: function (page) {
- ga[gaIdx]= $.extend(ga[gaIdx], parseGa(page, url));
- parseGaDone();
- },
- dataType: 'html'
- });
- }
- // parse a loaded GA page
- function parseGa(page, url) {
- var g = {};
- try {
- var winners = [];
- page=optimise_raw_html(page);
- g.title = $.trim($('.featured__heading__medium:first', page).text());
- g.giver = $('.featured__column a[href*="/user/"]:first', page).text();
- g.winner = '';
- g.winners = [];
- g.status = '';
- g.is_failed = false;
- g.is_open = false;
- g.is_closed = false;
- g.is_pending = false;
- g.date = $('.featured__column .fa-clock-o', page).parent().find('span:last').text();
- g.entries = parseInt($('.live__entry-count', page).text());
- g.id = url.split('/giveaway/')[1].split('/')[0];
- g.cv = $('.featured__heading>div.featured__heading__small:last', page).text().split('(')[1].split('P')[0];
- if (g.date.indexOf('Ended ') > -1) {
- urlwinners = $('.sidebar__navigation__item__link[href*="/winners"]', page).attr('href');
- var wdiv;
- $.ajax({
- url: urlwinners,
- async: false,
- success: function (wpage) {
- wpage=optimise_raw_html(wpage);
- wdiv = $('.page__inner-wrap', wpage);
- },
- dataType: 'html'
- });
- g.is_closed = true;
- g.status = 'CLOSED';
- var received = $('.table__row-inner-wrap', wdiv);
- if (received.length) {
- $(received).each(function () {
- if ($(this).closest('.table__row-outer-wrap').find('.fa-check-circle').length) {
- winners.push($('a[href*="/user/"]',this).text());
- } else if($(this).closest('.table__row-outer-wrap').find('.fa-question-circle').length) {
- winners.push('PENDING');
- g.is_pending = true;
- g.status = 'PENDING';
- }else {
- winners.push('NOT RECEIVED');
- }
- });
- } else {
- winners.push('FAILED');
- g.is_failed = true;
- g.status = 'FAILED';
- }
- g.winners = winners;
- g.winner = winners.join(',');
- } else {
- g.is_open = true;
- g.status = 'OPEN';
- }
- } catch (e) {
- console.log(e);
- g.title='ERROR - please check if GA is valid';
- }
- return g;
- }
- // check if all GA were parsed, and if yes, call elegCheckDone().
- function parseGaDone() {
- ga_progress++;
- $('#progress').val(ga_progress);
- if (ga_progress == ga_count) {
- $('#progress').remove();
- elegCheckDone();
- }
- }
- // display the parse results
- function elegCheckDone() {
- $('#eleg').append('<h4>Result : </h4>');
- var obj = $('<table/>').css('width','1200px');
- var tr = $('<tr/>');
- $(tr)
- .append($('<th/>').text('link'))
- .append($('<th/>').text('title'))
- .append($('<th/>').text('giver'))
- .append($('<th/>').text('cv'))
- .append($('<th/>').text('status/winner'))
- .append($('<th/>').text('B'))
- .append($('<th/>').text('NB'))
- .append($('<th/>').text('entries'))
- .append($('<th/>').text('date'))
- ;
- $(obj).append(tr);
- for (i in ga) {
- var g = ga[i];
- var tr = $('<tr/>');
- var ga_url='https://www.steamgifts.com/giveaway/' + g.id +'/';
- $(tr)
- .append($('<td/>').html('<a href="'+ga_url+'">'+ga_url+'</a>'))
- .append($('<td/>').text(g.title + ','))
- .append($('<td/>').text(g.giver))
- .append($('<td/>').text(g.is_bundle ? 0 : g.cv))
- .append($('<td/>').text(g.status == 'CLOSED' ? g.winner : g.status))
- .append($('<td/>').text('?')) // unknow in SG v2
- .append($('<td/>').text('?')) // unknow in SG v2
- .append($('<td/>').text(g.entries))
- .append($('<td/>').text(g.date))
- ;
- $(obj).append(tr);
- }
- GM_addStyle("#eleg table td{border:1px solid #333}");
- $('#eleg').append(obj);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement