Advertisement
Guest User

Steamgifts Auto Entry - New Features v1

a guest
Apr 15th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Steamgifts Auto Entry
  3. // @namespace   steamgifts_autoentry
  4. // @description Automatically enters giveaways on steamgifts.com
  5. // @include     /https?://www.steamgifts.com//
  6. // @version     20
  7. // @grant       none
  8. // @require     http://code.jquery.com/jquery-2.1.4.min.js
  9. // @require     http://code.jquery.com/ui/1.11.4/jquery-ui.min.js
  10. // @require     https://raw.githubusercontent.com/marcj/css-element-queries/master/src/ResizeSensor.js
  11. // @require     https://raw.githubusercontent.com/marcj/css-element-queries/master/src/ElementQueries.js
  12. // ==/UserScript==
  13.  
  14.  
  15. //USER EDITABLE VARIABLES
  16. var enabledonload=true; //default --- var enabledonload=false;
  17. var maxentries=-1; //default --- var maxentries='';
  18. var maxpagenum=8; //default --- var maxpagenum=10;
  19. var minpointpageincr=220; //default --- var minpointpageincr=220;
  20. var enterfree=true; //default --- var enterfree=true;
  21. //
  22.  
  23. this.$ = this.jQuery = jQuery.noConflict(true);
  24.  
  25. /* jQuery Storage API Plugin 1.7.4 https://github.com/julien-maurel/jQuery-Storage-API */
  26. !function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e("object"==typeof exports?require("jquery"):jQuery)}(function(e){function t(t){var r,i,n,o=arguments.length,s=window[t],a=arguments,u=a[1];if(2>o)throw Error("Minimum 2 arguments must be given");if(e.isArray(u)){i={};for(var f in u){r=u[f];try{i[r]=JSON.parse(s.getItem(r))}catch(c){i[r]=s.getItem(r)}}return i}if(2!=o){try{i=JSON.parse(s.getItem(u))}catch(c){throw new ReferenceError(u+" is not defined in this storage")}for(var f=2;o-1>f;f++)if(i=i[a[f]],void 0===i)throw new ReferenceError([].slice.call(a,1,f+1).join(".")+" is not defined in this storage");if(e.isArray(a[f])){n=i,i={};for(var m in a[f])i[a[f][m]]=n[a[f][m]];return i}return i[a[f]]}try{return JSON.parse(s.getItem(u))}catch(c){return s.getItem(u)}}function r(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1],u=s[2],f={};if(2>n||!e.isPlainObject(a)&&3>n)throw Error("Minimum 3 arguments must be given or second parameter must be an object");if(e.isPlainObject(a)){for(var c in a)r=a[c],e.isPlainObject(r)?o.setItem(c,JSON.stringify(r)):o.setItem(c,r);return a}if(3==n)return"object"==typeof u?o.setItem(a,JSON.stringify(u)):o.setItem(a,u),u;try{i=o.getItem(a),null!=i&&(f=JSON.parse(i))}catch(m){}i=f;for(var c=2;n-2>c;c++)r=s[c],i[r]&&e.isPlainObject(i[r])||(i[r]={}),i=i[r];return i[s[c]]=s[c+1],o.setItem(a,JSON.stringify(f)),f}function i(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1];if(2>n)throw Error("Minimum 2 arguments must be given");if(e.isArray(a)){for(var u in a)o.removeItem(a[u]);return!0}if(2==n)return o.removeItem(a),!0;try{r=i=JSON.parse(o.getItem(a))}catch(f){throw new ReferenceError(a+" is not defined in this storage")}for(var u=2;n-1>u;u++)if(i=i[s[u]],void 0===i)throw new ReferenceError([].slice.call(s,1,u).join(".")+" is not defined in this storage");if(e.isArray(s[u]))for(var c in s[u])delete i[s[u][c]];else delete i[s[u]];return o.setItem(a,JSON.stringify(r)),!0}function n(t,r){var n=a(t);for(var o in n)i(t,n[o]);if(r)for(var o in e.namespaceStorages)u(o)}function o(r){var i=arguments.length,n=arguments,s=(window[r],n[1]);if(1==i)return 0==a(r).length;if(e.isArray(s)){for(var u=0;u<s.length;u++)if(!o(r,s[u]))return!1;return!0}try{var f=t.apply(this,arguments);e.isArray(n[i-1])||(f={totest:f});for(var u in f)if(!(e.isPlainObject(f[u])&&e.isEmptyObject(f[u])||e.isArray(f[u])&&!f[u].length)&&f[u])return!1;return!0}catch(c){return!0}}function s(r){var i=arguments.length,n=arguments,o=(window[r],n[1]);if(2>i)throw Error("Minimum 2 arguments must be given");if(e.isArray(o)){for(var a=0;a<o.length;a++)if(!s(r,o[a]))return!1;return!0}try{var u=t.apply(this,arguments);e.isArray(n[i-1])||(u={totest:u});for(var a in u)if(void 0===u[a]||null===u[a])return!1;return!0}catch(f){return!1}}function a(r){var i=arguments.length,n=window[r],o=arguments,s=(o[1],[]),a={};if(a=i>1?t.apply(this,o):n,a._cookie)for(var u in e.cookie())""!=u&&s.push(u.replace(a._prefix,""));else for(var f in a)s.push(f);return s}function u(t){if(!t||"string"!=typeof t)throw Error("First parameter must be a string");g?(window.localStorage.getItem(t)||window.localStorage.setItem(t,"{}"),window.sessionStorage.getItem(t)||window.sessionStorage.setItem(t,"{}")):(window.localCookieStorage.getItem(t)||window.localCookieStorage.setItem(t,"{}"),window.sessionCookieStorage.getItem(t)||window.sessionCookieStorage.setItem(t,"{}"));var r={localStorage:e.extend({},e.localStorage,{_ns:t}),sessionStorage:e.extend({},e.sessionStorage,{_ns:t})};return e.cookie&&(window.cookieStorage.getItem(t)||window.cookieStorage.setItem(t,"{}"),r.cookieStorage=e.extend({},e.cookieStorage,{_ns:t})),e.namespaceStorages[t]=r,r}function f(e){var t="jsapi";try{return window[e]?(window[e].setItem(t,t),window[e].removeItem(t),!0):!1}catch(r){return!1}}var c="ls_",m="ss_",g=f("localStorage"),l={_type:"",_ns:"",_callMethod:function(e,t){var r=[this._type],t=Array.prototype.slice.call(t),i=t[0];return this._ns&&r.push(this._ns),"string"==typeof i&&-1!==i.indexOf(".")&&(t.shift(),[].unshift.apply(t,i.split("."))),[].push.apply(r,t),e.apply(this,r)},get:function(){return this._callMethod(t,arguments)},set:function(){var t=arguments.length,i=arguments,n=i[0];if(1>t||!e.isPlainObject(n)&&2>t)throw Error("Minimum 2 arguments must be given or first parameter must be an object");if(e.isPlainObject(n)&&this._ns){for(var o in n)r(this._type,this._ns,o,n[o]);return n}var s=this._callMethod(r,i);return this._ns?s[n.split(".")[0]]:s},remove:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(i,arguments)},removeAll:function(e){return this._ns?(r(this._type,this._ns,{}),!0):n(this._type,e)},isEmpty:function(){return this._callMethod(o,arguments)},isSet:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(s,arguments)},keys:function(){return this._callMethod(a,arguments)}};if(e.cookie){window.name||(window.name=Math.floor(1e8*Math.random()));var h={_cookie:!0,_prefix:"",_expires:null,_path:null,_domain:null,setItem:function(t,r){e.cookie(this._prefix+t,r,{expires:this._expires,path:this._path,domain:this._domain})},getItem:function(t){return e.cookie(this._prefix+t)},removeItem:function(t){return e.removeCookie(this._prefix+t)},clear:function(){for(var t in e.cookie())""!=t&&(!this._prefix&&-1===t.indexOf(c)&&-1===t.indexOf(m)||this._prefix&&0===t.indexOf(this._prefix))&&e.removeCookie(t)},setExpires:function(e){return this._expires=e,this},setPath:function(e){return this._path=e,this},setDomain:function(e){return this._domain=e,this},setConf:function(e){return e.path&&(this._path=e.path),e.domain&&(this._domain=e.domain),e.expires&&(this._expires=e.expires),this},setDefaultConf:function(){this._path=this._domain=this._expires=null}};g||(window.localCookieStorage=e.extend({},h,{_prefix:c,_expires:3650}),window.sessionCookieStorage=e.extend({},h,{_prefix:m+window.name+"_"})),window.cookieStorage=e.extend({},h),e.cookieStorage=e.extend({},l,{_type:"cookieStorage",setExpires:function(e){return window.cookieStorage.setExpires(e),this},setPath:function(e){return window.cookieStorage.setPath(e),this},setDomain:function(e){return window.cookieStorage.setDomain(e),this},setConf:function(e){return window.cookieStorage.setConf(e),this},setDefaultConf:function(){return window.cookieStorage.setDefaultConf(),this}})}e.initNamespaceStorage=function(e){return u(e)},g?(e.localStorage=e.extend({},l,{_type:"localStorage"}),e.sessionStorage=e.extend({},l,{_type:"sessionStorage"})):(e.localStorage=e.extend({},l,{_type:"localCookieStorage"}),e.sessionStorage=e.extend({},l,{_type:"sessionCookieStorage"})),e.namespaceStorages={},e.removeAllStorages=function(t){e.localStorage.removeAll(t),e.sessionStorage.removeAll(t),e.cookieStorage&&e.cookieStorage.removeAll(t),t||(e.namespaceStorages={})}});
  27.  
  28. jQuery.fn.center = function () {
  29.     this.css("position","fixed");
  30.     this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) +
  31.                                                 $(window).scrollTop()) + "px");
  32.     this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
  33.                                                 $(window).scrollLeft()) + "px");
  34.     return this;
  35. }
  36.  
  37.   var myFunc = function() {
  38.     console.log('Height changed to' + $(this).height());
  39.   };
  40.  
  41. var gamelist=[];
  42. var minpoints=100;
  43. var enterwishlist=false;
  44. var entergroup=false;
  45. var enterfeatured=false;
  46. var checktimer;
  47. var sitepattern=new RegExp('https?://.*steamgifts.com');
  48. var siteurl=sitepattern.exec(document.URL.toString());
  49. var pointsavailable=0;
  50. var possibleentries=[];
  51. var timeout=600000;
  52. var enabled=false;
  53.  
  54. {
  55.     var s=$.localStorage;
  56.     if(s.isSet('games')) {
  57.         gamelist=s.get('games');
  58.     }
  59.     for(var i=0; i<gamelist.length; i++) {
  60.         gamelist[i].name=gamelist[i].name.trim();
  61.         if(typeof(gamelist[i].maxentries)=="nothing" || $.isNumeric(gamelist[i].maxentries)==false) {
  62.             gamelist[i].maxentries=-1;
  63.         }
  64.         if(typeof(gamelist[i].entergroup)=="nothing") {
  65.             gamelist[i].entergroup=true;
  66.         }
  67.     }
  68.     if(s.isSet('minpoints')) {
  69.         minpoints=s.get('minpoints');
  70.         if($.isNumeric(minpoints)==false) {
  71.             minpoints=100;
  72.         }
  73.     }
  74.     if(s.isSet('maxpagenum')) {
  75.         maxpagenum=s.get('maxpagenum');
  76.         if($.isNumeric(maxpagenum)==false) {
  77.             maxpagenum=8;
  78.         }
  79.     }
  80.     if(s.isSet('minpointpageincr')) {
  81.         minpointpageincr=s.get('minpointpageincr');
  82.         if($.isNumeric(minpointpageincr)==false) {
  83.             minpointpageincr=220;
  84.         }
  85.     }
  86.     if(s.isSet('maxentries')) {
  87.         maxentries=s.get('maxentries');
  88.         if($.isNumeric(maxentries)==false) {
  89.             maxentries=-1;
  90.         }
  91.     }
  92.     if(s.isSet('enterwishlist') && s.get('enterwishlist')!="undefined") {
  93.         enterwishlist=s.get('enterwishlist');
  94.     }
  95.     if(s.isSet('entergroup') && s.get('entergroup')!="undefined") {
  96.         entergroup=s.get('entergroup');
  97.     }
  98.     if(s.isSet('enterfeatured') && s.get('enterfeatured')!="undefined") {
  99.         enterfeatured=s.get('enterfeatured');
  100.     }
  101.     if(s.isSet('enterfree') && s.get('enterfree')!="undefined") {
  102.         enterfree=s.get('enterfree');
  103.     }
  104.     if(s.isSet('enabledonload') && s.get('enabledonload')!="undefined") {
  105.         enabledonload=s.get('enabledonload');
  106.     }
  107. }
  108.  
  109. function log(text) {
  110.     if(window.console && console.log) {
  111.         console.log(text);
  112.     }
  113. }
  114.  
  115. function doentry(resp) {
  116.     var submitted=false;
  117.     $('#hiddeniframe').unbind('load');
  118.     if($('#hiddeniframe').contents().find('.sidebar .sidebar__error').length==0 && $('#hiddeniframe').contents().find('.sidebar form').length>0 && $('#hiddeniframe').contents().find('.sidebar form').html().indexOf('Enter Giveaway')>=0) {
  119.         log('Entering giveaway '+$('#hiddeniframe').attr('src'));
  120.         $('#hiddeniframe').contents().find('.sidebar .sidebar__entry-insert').click();
  121.         submitted=true;
  122.     }
  123.    
  124.     if(submitted==true) {
  125.         // 10 second delay to give .click() time to submit form
  126.         setTimeout(startnextentry,10000);
  127.     } else {
  128.         if($('#hiddeniframe').contents().find('.nav__right-container').length>0) {
  129.             var pointregex=new RegExp("Account(?:[^>]*?)>(\\d+)<","gm");
  130.             var pointarr=pointregex.exec($('#hiddeniframe').contents().find('.nav__right-container').html());
  131.             if(pointarr!=null && pointarr.length==2) {
  132.                 pointsavailable=pointarr[1];
  133.             }
  134.         }
  135.         log('Unable to enter giveaway '+$('#hiddeniframe').attr('src')+'  pointsavailable='+pointsavailable);
  136.  
  137.         startnextentry();
  138.     }
  139. }
  140.  
  141. function startnextentry() {
  142.     if(possibleentries.length>0) {
  143.         for(var ei=0; ei<possibleentries.length; ei++) {
  144.             if((possibleentries[ei].force==true) && (pointsavailable-possibleentries[ei].points)>=minpoints) {
  145.                 // remove hidden iframe and readd each time to get around Firefox memory leak - doesn't fit it
  146.                 if($('#hiddeniframe').length>0) {
  147.                     $('#hiddeniframe').unbind('load');
  148.                     $('#hiddeniframe').attr('src','about:blank');
  149.                     log("Removing hidden iframe");
  150.                     $('#hiddeniframe').remove();
  151.                 }
  152.            
  153.                 if($('#hiddeniframe').length==0) {
  154.                     $('.footer__outer-wrap').append('<iframe id="hiddeniframe"></iframe>');
  155.                 }
  156.                 $('#hiddeniframe').hide();
  157.                 $('#hiddeniframe').load(doentry);
  158.                 $('#hiddeniframe').attr('src',siteurl+possibleentries[ei].url);
  159.  
  160.                 pointsavailable-=possibleentries[ei].points;
  161.                 possibleentries.splice(ei,1);
  162.                 return;
  163.             }
  164.         }
  165.         for(var ti=0; ti<gamelist.length; ti++) {
  166.             for(var ei=0; ei<possibleentries.length; ei++) {
  167.                 var rematch=new RegExp(gamelist[ti].name.replace("(", "\\(").replace(")", "\\)"),"i").test(possibleentries[ei].name); //TESTING added .replace("(", "\\(").replace(")", "\\)")
  168.                 if((gamelist[ti].name==possibleentries[ei].name || rematch==true) && (pointsavailable-possibleentries[ei].points)>=minpoints) {
  169.                
  170.                     // remove hidden iframe and readd each time to get around Firefox memory leak - doesn't fix it
  171.                     if($('#hiddeniframe').length>0) {
  172.                         $('#hiddeniframe').unbind('load');
  173.                         $('#hiddeniframe').attr('src','about:blank');
  174.                         log("Removing hidden iframe");
  175.                         $('#hiddeniframe').remove();
  176.                     }
  177.  
  178.                     if($('#hiddeniframe').length==0) {
  179.                         $('.footer__outer-wrap').append('<iframe id="hiddeniframe"></iframe>');
  180.                     }
  181.                     $('#hiddeniframe').hide();
  182.                     $('#hiddeniframe').load(doentry);
  183.                     $('#hiddeniframe').attr('src',siteurl+possibleentries[ei].url);
  184.  
  185.                     pointsavailable-=possibleentries[ei].points;
  186.                     possibleentries.splice(ei,1);
  187.                     return;
  188.                 }
  189.             }
  190.         }
  191.     }
  192.     // done with this update
  193.     // start the timer again for the next series of updates
  194.     checktimer=setTimeout(startupdate,timeout);
  195.    
  196.     log('Update done');
  197.    
  198. }
  199.  
  200. function startpagerequest(pagenum) {
  201.     log('Starting request for page '+pagenum.toString());
  202.     var pageurl;
  203.     if(pagenum=='wishlist' || pagenum=='group') {
  204.         pageurl=siteurl+'/giveaways/search?type='+pagenum;
  205.     } else {
  206.         pageurl=siteurl+'/giveaways/search?page='+pagenum.toString()+'&status=open';
  207.     }
  208.     jQuery.ajax({method: "GET",
  209.     url: pageurl,
  210.     success: backgroundpageload(pagenum),
  211.     error: loadfailure(pagenum)
  212.     });
  213. }
  214.  
  215. function backgroundpageload(pagenum) {
  216.     return function(resp) {
  217.  
  218.         entries=$(resp).find('.giveaway__row-outer-wrap');
  219.         nogiveaways=false;
  220.  
  221.         if(typeof(entries)!="undefined" && typeof(entries.length)!="undefined") {
  222.             if(entries.length == $('.pinned-giveaways__outer-wrap').find('.giveaway__row-outer-wrap').length) {
  223.                 log('No giveaways found on page '+pagenum);
  224.                 nogiveaways=true;
  225.             }
  226.             $(entries).each(function() {
  227.                 // skip class is-faded because we've already entered them
  228.                 if($(this).find('.giveaway__row-inner-wrap').hasClass('is-faded')==false) {
  229.                     var ok=true;
  230.                     var wantenter=true;
  231.                     var contrib=$(this).find('.contributor_only');
  232.                     if(contrib.length>0) {
  233.                         if($(contrib).hasClass('green')==false) {
  234.                             ok=false;
  235.                         }
  236.                     }
  237.                     var levelok=!($(this).find('.giveaway__column--contributor-level--negative').length>0);
  238.                     if(levelok==false) {
  239.                         log('Level not high enough');
  240.                         ok=false;
  241.                     }
  242.                     var isgroup=($(this).find('.giveaway__column--group').length>0);
  243.                     if(isgroup==true) {
  244.                         log('Group giveaway');
  245.                     }
  246.                     var isfeatured=($(this).parents('.pinned-giveaways__outer-wrap').length>0);
  247.                     //var name=$(this).find('.title').find('a[href^="/giveaway/"]').text();
  248.                     var name=$(this).find('.giveaway__heading__name').text();
  249.                     var gameidx=gamelist.map(function(el) { return el.name; }).indexOf(name);
  250.                     if(gameidx<0 && levelok==true) {
  251.                         for(var gi=0; gi<gamelist.length && gameidx<0; gi++) {
  252.                             //log(gamelist[gi].name.replace("(", "\\(").replace(")", "\\)")+' ~~ '+name);  //TESTING
  253.                             if(RegExp(gamelist[gi].name.replace("(", "\\(").replace(")", "\\)"),"i").test(name)==true) {
  254.                             //if(name.match('/'+gamelist[gi].name.replace("(", "\\(").replace(")", "\\)")+'/g')) {
  255.                                 log('Matched regex '+gamelist[gi].name+' for game '+name);
  256.                                 gameidx=gi;
  257.                             }
  258.                         }
  259.                         if(gameidx<0) {
  260.                             ok=false;
  261.                         }
  262.                     }
  263.                     if(ok==true && isgroup==true && gamelist[gameidx].entergroup==false) {
  264.                         wantenter=false;
  265.                         log('Skipping entry of ignored group giveaway for '+gamelist[gameidx].name);
  266.                     }
  267.                     if(ok==false && isfeatured==true && enterfeatured==true) {
  268.                         if(gameidx < 0) {
  269.                             ok=true;
  270.                         } else if(gamelist[gameidx].maxentries!=0) {
  271.                             ok=true;
  272.                         }
  273.                     }
  274.                     //log(ok); //testing
  275.                     var pointsregex=new RegExp("\\((\\d+)P\\)");
  276.                     var arr=pointsregex.exec($(this).find('.giveaway__heading').html());
  277.                     var entriesregex=new RegExp("(\\d+) entr");
  278.                     // remove , from string because it's used as a thousand separator
  279.                     var earr=entriesregex.exec($(this).find('.giveaway__links a').html().replace(',',''));
  280.                     if(ok==true && earr!=null && earr.length==2) {
  281.                         if(gameidx >= 0) {
  282.                             if(gamelist[gameidx].maxentries!="nothing" && gamelist[gameidx].maxentries!=-1 && parseInt(gamelist[gameidx].maxentries)<parseInt(earr[1])) {
  283.                                 ok=false;
  284.                                 if(gamelist[gameidx].maxentries!=0) {
  285.                                   log('Too many entries for '+$(this).find('a[href^="/giveaway/"]').attr('href'));
  286.                                 } else {
  287.                                     log('Entries not allowed for '+$(this).find('a[href^="/giveaway/"]').attr('href'));
  288.                                 }
  289.                             }
  290.                         }
  291.                     }
  292.                     var isfree=false;
  293.                     if(arr[1]==0 && enterfree==true) {
  294.                         isfree=true;
  295.                         ok=true;
  296.                         log('entered if statement'); //testing
  297.                     }
  298.                     //log(isfree+' ~~ '+ok+' ~~ '+enterfree); //testing
  299.                     //dfaklssdf.lenghts;
  300.                     if(levelok==true && wantenter==true && (ok==true || pagenum=='wishlist' || pagenum=='group')) {
  301.                         var thisurl=$(this).find('a[href^="/giveaway/"]').attr('href');
  302.                         var haveurl=false;
  303.                         for(var ei=0; ei<possibleentries.length; ei++) {
  304.                             if(possibleentries[ei].url==thisurl) {
  305.                                 haveurl=true;
  306.                             }
  307.                         }
  308.                         if(haveurl==false) {
  309.                             possibleentries.length+=1;
  310.                             possibleentries[possibleentries.length-1]={};
  311.                             possibleentries[possibleentries.length-1].url=thisurl;
  312.                             possibleentries[possibleentries.length-1].name=name;
  313.                             possibleentries[possibleentries.length-1].points=arr[1];
  314.                             possibleentries[possibleentries.length-1].force=(pagenum=='wishlist' || pagenum=='group' || (ok==true && isfeatured==true && enterfeatured==true) || (ok==true && isfree==true));
  315.                             possibleentries[possibleentries.length-1].isgroup=isgroup;
  316.                             log('Adding possible '+(pagenum=='wishlist' ? 'wishlist ' : (pagenum=='group' ? 'group ' : ''))+'entry '+possibleentries[possibleentries.length-1].url+'  points='+possibleentries[possibleentries.length-1].points+'  '+possibleentries.length);
  317.                         }
  318.                     }
  319.                 }
  320.             });
  321.         } else {
  322.             nogiveaways=true;
  323.         }
  324.        
  325.         var pointregex=new RegExp("Account(?:[^>]*?)>(\\d+)<","gm");
  326.         var pointarr=pointregex.exec(resp);
  327.         if(pointarr!=null && pointarr.length==2) {
  328.             pointsavailable=pointarr[1];
  329.         }
  330.        
  331.         if(pagenum=='wishlist') {
  332.             if(entergroup==true) {
  333.                 startpagerequest('group');
  334.                 return;
  335.             }
  336.             pagenum=0;
  337.         }
  338.        
  339.         if(pagenum=='group') {
  340.             pagenum=0;
  341.         }
  342.        
  343.         afterenterpointcount=pointsavailable;
  344.         for(var ei=0; ei<possibleentries.length; ei++) {
  345.       afterenterpointcount-=possibleentries[ei].points;
  346.     }
  347.         //log('points '+minpointpageincr);
  348.         if((pagenum<maxpagenum || afterenterpointcount>minpointpageincr) && nogiveaways==false) {
  349.             startpagerequest(pagenum+1);
  350.             return;
  351.         }
  352.        
  353.         log('Points Available='+pointsavailable);
  354.         startnextentry();
  355.        
  356.     }
  357. }
  358.  
  359. function loadfailure(pagenum) {
  360.     return function(resp) {
  361.    
  362.         if(pagenum=='wishlist') {
  363.             if(entergroup==true) {
  364.                 startpagerequest('group');
  365.                 return;
  366.             }
  367.             pagenum=0;
  368.         }
  369.            
  370.         if(pagenum=='group') {
  371.             pagenum=0;
  372.         }
  373.        
  374.         if(pagenum<maxpagenum) {
  375.             startpagerequest(pagenum+1);
  376.             return;
  377.         }
  378.         // done with this update
  379.         // start the timer again for the next series of updates
  380.         checktimer=setTimeout(startupdate,timeout);
  381.     }
  382. }
  383.  
  384. function startupdate() {
  385.     pointsavailable=0;
  386.     possibleentries=[];
  387.     if(enterwishlist==true) {
  388.         startpagerequest('wishlist');
  389.     } else if(entergroup==true) {
  390.         startpagerequest('group');
  391.     } else {
  392.         startpagerequest(1);
  393.     }
  394. }
  395.  
  396. function startautoentry(event) {
  397.     if(typeof(checktimeout)!="undefined") {
  398.         clearTimeout(checktimeout);
  399.     }
  400.     checktimer=setTimeout(startupdate,2000);
  401. }
  402.  
  403. function stopautoentry(event) {
  404.     clearTimeout(checktimer);
  405. }
  406.  
  407. function getgameli(game) {
  408.     var li=$('<li style="cursor:grab;"></li>');
  409.     var span=$('<span class="gamename" style="display:inline-block;width:350px;text-overflow:ellipsis;margin-right:10px;"></span>');
  410.     li.append(span);
  411.     span.text(game.name);
  412.     span=$('<span class="maxentries" style="display:inline-block;width:40px;margin-right:10px;"></span>');
  413.     li.append(span);
  414.     span.text(game.maxentries);
  415.     span=$('<span class="entergroup" style="display:inline-block;width:50px;margin-right:10px;"></span>');
  416.     li.append(span);
  417.     span.text((game.entergroup==true ? 'Yes' : 'No'));
  418.    
  419.     var removelink=$('<a style="cursor:pointer;">Remove</a>');
  420.     removelink.click(function() { $(this).parent().remove(); });
  421.     li.append(removelink);
  422.     return li;
  423. }
  424.  
  425. function createsettingsdiv() {
  426.     var outerdiv=$('<div id="autoentrysettingsdiv" style="position:absolute;width:550px;height:500px;background-color:#ffffff;display:none;border:1px solid;border-radius:4px;color:#6d7c87;font-size:11px;font-weight:bold;padding:5px 10px;"></div>');
  427.     outerdiv.append('<h2 style="text-align:center;color:#4f565a;">Auto Entry Settings</h2>');
  428.     outerdiv.append('<h3 style="color:#4f565a;">Games</h3><i>Reorder the list to have your most wanted games at the top</i>');
  429.     outerdiv.append('<div id="gamelist" style="height:350px;overflow-y:scroll;"></div>');
  430.     outerdiv.find('#gamelist').append('<span style="display:inline-block;width:350px;text-overflow:ellipsis;margin-right:10px;color:#4f565a;">Game</span>');
  431.     outerdiv.find('#gamelist').append('<span style="display:inline-block;width:40px;text-overflow:ellipsis;margin-right:10px;color:#4f565a;">Max Entries</span>');
  432.     outerdiv.find('#gamelist').append('<span style="display:inline-block;width:50px;text-overflow:ellipsis;margin-right:10px;color:#4f565a;">Enter Group</span>');
  433.     var ul=$('<ul id="autoentrygameul"></ul>');
  434.     outerdiv.find('#gamelist').append(ul);
  435.    
  436.     for(var i=0; i<gamelist.length; i++) {
  437.         ul.append(getgameli(gamelist[i]));
  438.     }
  439.     ul.sortable();
  440.     ul.disableSelection();
  441.     var addgamediv=$('<div id="addgame"><input type="text" id="addgamename" style="width:350px;margin-right:6px;padding:0px;" title="The full name of the game as it appears on steamgifts.com, or a regular expression to match the name against"><input type="text" id="addgamemaxentries" style="width:40px;margin-right:6px;padding:0px;" value="'+maxentries+'" title="Giveaways for this game will be entered as long as the number of existing entries is equal to or fewer than this.  Use -1 to always enter giveaways regardless of the number of entries."><input type="checkbox" id="addgameentergroup" style="width:50px;margin-right:18px;padding:0px;" title="Enter Group Giveaways for this game."></div>');
  442.  
  443.     var addgamelink=$('<a style="cursor:pointer;">Add</a>');
  444.     addgamelink.click(function() {
  445.         var game={};
  446.         game.name=$('#addgamename').val().trim();
  447.         game.maxentries=$('#addgamemaxentries').val();
  448.         game.entergroup=$('#addgameentergroup').prop("checked");
  449.        
  450.         if(game.name=='' || game.maxentries=='') {
  451.             alert('You must enter a game name and maximum entries');
  452.             return;
  453.         }
  454.        
  455.         if($.isNumeric(game.maxentries)==false) {
  456.             alert('Maximum entries must be a number');
  457.             return;
  458.         }
  459.  
  460.         var exists=false;
  461.         var existingli=null;
  462.         $('#gamelist ul li').each(function() {
  463.             if($(this).find('.gamename').text()==game.name) {
  464.                 exists=true;
  465.                 existingli=$(this);
  466.             }
  467.         });
  468.        
  469.         if(exists==true) {
  470.             $(existingli).find('.maxentries').text(game.maxentries);
  471.             $(existingli).find('.entergroup').text(game.entergroup==true ? 'Yes' : 'No');
  472.             alert('This game was already in the list and was replaced with your new settings');
  473.         }
  474.         else {
  475.             $('#gamelist').find('ul').append(getgameli(game));
  476.         }
  477.         $('#addgamename').val('');
  478.         $('#addgamemaxentries').val(maxentries);
  479.         $('#addgameentergroup').prop('checked',false);
  480.     });
  481.     addgamediv.append(addgamelink);
  482.     outerdiv.append(addgamediv);
  483.     var outerdivoptions='';
  484.     outerdivoptions+='<table width="100%">';   
  485.     outerdivoptions+='<tr><td>Min Points <input type="text" id="autoentryminpoints" pattern="\\d+" style="width:30px; padding:0px;" title="Giveaways will only be entered as long as your points available will remain at or above this number.  This allows you to have a spare pool of points to manually enter giveaways.">';
  486.     outerdivoptions+='</td><td>Default Max Entries <input type="text" id="autoentrymaxentries" pattern="*" style="width:30px; padding:0px;" title="After adding any game the Max Entries will be set to this default.">';
  487.     outerdivoptions+='</td><td>Max Page Number <input type="text" id="autoentrymaxpagenum" pattern="\\d+" style="width:30px; padding:0px;" title="Sets the maximum number of pages to go thru for giveaways. (Overridden by Min Point Increase Page)">';
  488.     outerdivoptions+='</td><td>Min Point Increase Page <input type="text" id="autoentryminpointpageincr" pattern="\\d+" style="width:30px; padding:0px;" title="Sets the minimum required points to search beyond the Max Page Number. (Prevents ending up with 300 points. Set to 300 to not use.)">';
  489.     outerdivoptions+='</td></tr>'; 
  490.     outerdivoptions+='<tr><td colspan=2><input type="checkbox" name="autoentryenterwishlist" id="autoentryenterwishlist" style="width:15px;vertical-align:top;">Enter any wishlist giveaways';
  491.     outerdivoptions+='</td><td colspan=2><input type="checkbox" name="autoentryentergroup" id="autoentryentergroup" style="width:15px;vertical-align:top;">Enter group giveaways';
  492.     outerdivoptions+='</td></tr><tr><td colspan=2><input type="checkbox" name="autoentryenterfeatured" id="autoentryenterfeatured" style="width:15px;vertical-align:top;" title="There are special giveaways that show up at the top of most pages on the site.">Enter featured giveaways';
  493.     outerdivoptions+='</td><td colspan=2><input type="checkbox" name="autoentryenterfree" id="autoentryenterfree" style="width:15px;vertical-align:top;" title="Check to enter any giveaways that cost 0 points.">Enter free giveaways';
  494.   outerdivoptions+='<tr><td colspan=2><input type="checkbox" name="autoentryenabledonload" id="autoentryenabledonload" style="width:15px;vertical-align:top;" title="Check to enable Auto Entry on page load. (only on steamgifts homepage)">Enable Auto Entry on page load';
  495.     outerdivoptions+='</td></tr></table>';
  496.     outerdiv.append(outerdivoptions);
  497.     var center=$('<center></center>');
  498.     outerdiv.append(center);
  499.     var savebutton=$('<button>Save</button>');
  500.     center.append(savebutton);
  501.     savebutton.click(function() {
  502.         $('#autoentrysettingsdiv').slideUp();
  503.         var storage=$.localStorage;
  504.        
  505.         gamelist=[];
  506.         $('#gamelist ul li').each(function() {
  507.             gamelist.push({
  508.                             name:$(this).find('.gamename').text(),
  509.                             maxentries:$(this).find('.maxentries').text(),
  510.                             entergroup:($(this).find('.entergroup').text()=='Yes' ? true : false)
  511.                         });
  512.         });
  513.        
  514.         storage.set('games',gamelist);
  515.         if($.isNumeric($('#autoentryminpoints').val())==true) {
  516.             minpoints=$('#autoentryminpoints').val();
  517.             storage.set('minpoints',minpoints);
  518.         }
  519.         if($.isNumeric($('#autoentrymaxentries').val())==true) {
  520.             maxentries=$('#autoentrymaxentries').val();
  521.             storage.set('maxentries',maxentries);
  522.         }
  523.         if($.isNumeric($('#autoentrymaxpagenum').val())==true) {
  524.             maxpagenum=$('#autoentrymaxpagenum').val();
  525.             storage.set('maxpagenum',maxpagenum);
  526.         }
  527.         if($.isNumeric($('#autoentryminpointpageincr').val())==true) {
  528.             minpointpageincr=$('#autoentryminpointpageincr').val();
  529.             storage.set('minpointpageincr',minpointpageincr);
  530.         }
  531.         enterwishlist=$('#autoentryenterwishlist').prop("checked");
  532.         storage.set('enterwishlist',enterwishlist);
  533.         entergroup=$('#autoentryentergroup').prop("checked");
  534.         storage.set('entergroup',entergroup);
  535.         enterfeatured=$('#autoentryenterfeatured').prop("checked");
  536.         storage.set('enterfeatured',enterfeatured);
  537.         enterfree=$('#autoentryenterfree').prop("checked");
  538.         storage.set('enterfree',enterfree);
  539.         enabledonload=$('#autoentryenabledonload').prop("checked");
  540.         storage.set('enabledonload',enabledonload);
  541.     });
  542.    
  543.     var closebutton=$('<button>Close</button>');
  544.     center.append(' ');
  545.     center.append(closebutton);
  546.     closebutton.click(function() {
  547.         $('#autoentrysettingsdiv').slideUp();
  548.     });
  549.    
  550.     return outerdiv;
  551. }
  552.  
  553. function createhelpdiv() {
  554.     var outerdiv=$('<div id="autoentryhelpdiv" style="position:absolute;width:740px;height:600px;background-color:#ffffff;display:none;border:1px solid;border-radius:4px;color:#6d7c87;font-size:11px;font-weight:bold;padding:5px 10px;overflow-y:scroll;"></div>');
  555.     outerdiv.append('<h2 style="text-align:center;">Help</h2>');
  556.     outerdiv.append('<br />');
  557.     var innerdiv=$('<div style="line-height:1.3em;">');
  558.     outerdiv.append(innerdiv);
  559.     innerdiv.append('How to use the Auto Entry feature<br /><br />');
  560.     innerdiv.append('You must be logged into steamgifts.com to use the Auto Entry feature.  All setup must be done on the Settings page under the Auto Entry menu<br /><br />');
  561.     innerdiv.append('First add the games you want to automatically enter.  To do this you need to enter either the name of the game as it appears on steamgifts.com or a regular expression, the maximum number of entries a giveaway can have before the auto entry will skip over it, and if you want to enter group giveaways for the game.  The maximum entries is only checked when entering giveaways.  Once you are entered in a giveaway it will not remove the entry if the number of entries goes over the maximum at a later time.  You can enter -1 here to always enter giveaways for that game.<br /><br />');
  562.     innerdiv.append('As you add games they will show up in the list.  You can drag and drop games to rearrange them.  Games at the top of the list will be entered first and therefore use up points first, so keep your most wanted games at the top of the list.<br /><br />');
  563.     innerdiv.append('If you select enter any wishlist giveaways the games on your wishlist will be entered first, before all other entries if points are available.  This is for ANY game in your wishlist, not just those games you\'ve added to the auto entry list.  Likewise if you select enter group giveaways, the giveaways for groups you are a member of will be entered second, unless you have excluded the game from group giveaways in your auto entry list.  Only after these entries are made will entries for the games in your auto entry list be considered.<br /><br />');
  564.     innerdiv.append('You may also choose to enter any featured giveaways that show up at the top of some pages on the site.  If you don\'t select this option, games that are featured may still be entered if they are matched in your game list, otherwise they will be skipped.<br /><br />');
  565.     innerdiv.append('You must also enter the minimum number of points that the auto entry system will leave for you.  The auto entry system will not enter a giveaway if your points available would go below this number.  This will give you a pool of unused points so you can manually enter giveaways that you want.<br /><br />');
  566.     innerdiv.append('After you have made any changes in the Settings page, you need to click the Save button to save those changes.<br /><br />');
  567.     innerdiv.append('Enable the auto entry system by clicking the Disabled link under the Auto Entry menu.  When the auto entry system is running the link will change to Enabled.  Clicking it when Enabled will disable it.<br /><br />');
  568.     innerdiv.append('When the auto entry system is enabled it will attempt to enter giveaways for games in your list every 10 minutes.  It will check for giveaways on the first '+maxpagenum+' pages of games as listed on steamgifts.com.<br /><br />');
  569.     innerdiv.append('Only enable the auto entry system in a single browser tab.  Once the system is enabled you should leave that browser tab alone and use another tab if you want to browse steamgifts.com.<br /><br />');
  570.     innerdiv.append('Bitcoin Donations Appreciated : 1SGiftfrNtDfThSykhB8yDZYTJPHF59hH');
  571.     var closebutton=$('<center><button>Close</button></center>');
  572.     outerdiv.append(closebutton);
  573.     closebutton.click(function() {
  574.         $('#autoentryhelpdiv').slideUp();
  575.     });
  576.    
  577.     return outerdiv;
  578. }
  579.  
  580. function createbackuprestorediv() {
  581.     var outerdiv=$('<div id="autoentrybackuprestorediv" style="position:absolute;width:500px;height:380px;background-color:#ffffff;display:none;border:1px solid;border-radius:4px;color:#6d7c87;font-size:11px;font-weight:bold;padding:5px 10px;"></div>');
  582.     outerdiv.append('The settings for Auto Entry are saved in your browser\'s local storage.  This might get cleared periodically by the browser or addons, or when you manually clear your browser cache.  You can manually save and restore your settings below should the need arise.<br /><br />');
  583.     outerdiv.append('Backup Settings - <i>Copy this text and save it.  You can use this text to restore your Auto Entry settings later should they become lost or to transfer them to another computer.</i>');
  584.     outerdiv.append('<textarea id="autoentrybackupjson" readonly style="height:100px;max-height:100px;"></textarea>');
  585.     outerdiv.append('<br /><br />');
  586.     outerdiv.append('Restore Settings - <i>Paste settings that you\'ve previously saved to restore them.  This will overwrite any settings you currently have.</i>');
  587.     outerdiv.append('<textarea id="autoentryrestorejson" style="height:100px;max-height:100px;"></textarea>');
  588.     var restorebutton=$('<center><button>Restore</button></center>');
  589.     outerdiv.append(restorebutton);
  590.     restorebutton.click(function() {
  591.         if($('#autoentryrestorejson').val()=='') {
  592.             alert('You must paste your settings first');
  593.         }
  594.         var settingsobj={};
  595.         try {
  596.             settingsobj=JSON.parse($('#autoentryrestorejson').val());
  597.         } catch(e) {
  598.             alert('Invalid settings to restore.  '+e.message);
  599.             return false;
  600.         }
  601.         if(settingsobj==null || typeof(settingsobj)=="undefined") {
  602.             alert('Invalid settings to restore');
  603.             return false;
  604.         }
  605.        
  606.         if(typeof(settingsobj.version)=="undefined" || typeof(settingsobj.gamelist)=="undefined" || typeof(settingsobj.minpoints)=="undefined") {
  607.             alert('The settings you are trying to restore are invalid');
  608.             return false;
  609.         } else if(settingsobj.version==2 && (typeof(settingsobj.enterwishlist)=="undefined" || typeof(settingsobj.entergroup)=="undefined")) {
  610.             alert('The settings you are trying to restore are invalid');
  611.             return false;
  612.         }
  613.        
  614.         if(settingsobj.version>=1) {
  615.             gamelist=settingsobj.gamelist;
  616.             minpoints=settingsobj.minpoints;
  617.         }
  618.         if(settingsobj.version>=2) {
  619.             enterwishlist=settingsobj.enterwishlist;
  620.             entergroup=settingsobj.entergroup;
  621.         }
  622.         if(settingsobj.version>=3) {
  623.             enterfeatured=settingsobj.enterfeatured;
  624.         }
  625.         if(settingsobj.version>=4) {
  626.             enterfree=settingsobj.enterfree;
  627.             enabledonload=settingsobj.enabledonload;
  628.             maxentries=settingsobj.maxentries;
  629.             maxpagenum=settingsobj.maxpagenum;
  630.             minpointpageincr=settingsobj.minpointpageincr;
  631.         }
  632.        
  633.         $('#autoentryrestorejson').val('');
  634.         alert('Settings restored in memory.  Save the settings to permanently store them.');
  635.     });
  636.     outerdiv.append('<br />');
  637.     var closebutton=$('<center><button>Close</button></center>');
  638.     outerdiv.append(closebutton);
  639.     closebutton.click(function() {
  640.         $('#autoentrybackuprestorediv').slideUp();
  641.     });
  642.    
  643.     return outerdiv
  644. }
  645.  
  646. function fn_addgametolist() {
  647.     var giveaways=$('.giveaway__heading > .giveaway__heading__name');
  648.     $(giveaways).each(function() {
  649.         if($(this).parent().find('.addgametolist').length==0) {
  650.             var buttonstyle='cursor:pointer;border-style:solid;border-width:1px;border-radius:4px;text-align:center;';
  651.             var addgametolist='<div class="addgametolist sidebar__button-style" style="'+buttonstyle+'"><i class="fa fa-plus-circle"></i> Add Game To List</div>&nbsp;';
  652.             $(this).parent().prepend(addgametolist);
  653.         }
  654.     });
  655.     $('.addgametolist').click(function() {
  656.         var itinerary = $(this).parent().find('.giveaway__heading__name')
  657.                 .clone(true)       /* get a clone of the element and from it */
  658.                 .find('.ga-mark')  /* retrieve the button, then */
  659.                 .remove()          /* remove it, */
  660.                 .end()             /* return to the previous selection and */
  661.                 .html() ;          /* get the html */
  662.         var gamename=itinerary.trim();
  663.         if(gamename.match(/\.\.\.$/)) {
  664.             gamename='^'+gamename.replace(/\.\.\.$/, "").trim();
  665.         } else {
  666.             gamename='^'+gamename.trim()+'$';
  667.         }
  668.         $('#autoentrysettings').click();
  669.         $('#addgamename').val(decodeEntities(gamename));
  670.         return false;
  671.     });
  672. }
  673.  
  674. function decodeEntities(encodedString) {
  675.   var textArea = document.createElement('textarea');
  676.   textArea.innerHTML = encodedString;
  677.   return textArea.value;
  678. }
  679.  
  680. $(document).ready(function() {
  681.    
  682.     if($('.nav__left-container').length>0) {
  683.         $('body').append(createsettingsdiv());
  684.         $('body').append(createhelpdiv());
  685.         $('body').append(createbackuprestorediv());
  686.  
  687.         // change to icon-green when enabled and icon-red when disabled
  688.         // fa-toggle-off - fa-toggle-on
  689.        
  690.         var cont=$('nav .nav__left-container').append('\
  691.         <div id="autoentrybuttoncontainer" class="nav__button-container">\
  692.             <div class="nav__relative-dropdown is-hidden">\
  693.                 <div class="nav__absolute-dropdown">\
  694.                     <a class="nav__row" id="autoentryenabled" style="cursor:pointer;">\
  695.                         <i class="icon-red fa fa-fw fa-toggle-off"></i>\
  696.                         <div class="nav__row__summary">\
  697.                             <p class="nav__row__summary__name">Disabled</p>\
  698.                             <p class="nav__row__summary__description">Auto Entry currently disabled</p>\
  699.                         </div>\
  700.                     </a>\
  701.                     <a class="nav__row" id="autoentrysettings" style="cursor:pointer;">\
  702.                         <i class="icon-grey fa fa-fw fa-pencil-square-o"></i>\
  703.                         <div class="nav__row__summary">\
  704.                             <p class="nav__row__summary__name">Settings</p>\
  705.                             <p class="nav__row__summary__description">Auto Entry settings</p>\
  706.                         </div>\
  707.                     </a>\
  708.                     <a class="nav__row" id="autoentrybackuprestore" style="cursor:pointer;">\
  709.                         <i class="icon-grey fa fa-fw fa-save"></i>\
  710.                         <div class="nav__row_summary">\
  711.                             <p class="nav__row__summary__name">Backup/Restore</p>\
  712.                             <p class="nav__row__summary__description">Manually backup or restore settings</p>\
  713.                         </div>\
  714.                     </a>\
  715.                     <a class="nav__row" id="autoentryhelp" style="cursor:pointer;">\
  716.                         <i class="icon-grey fa fa-fw fa-question-circle"></i>\
  717.                         <div class="nav__row_summary">\
  718.                             <p class="nav__row__summary__name">Help</p>\
  719.                             <p class="nav__row__summary__description">Auto Entry help</p>\
  720.                         </div>\
  721.                     </a>\
  722.                 </div>\
  723.             </div>\
  724.             <span class="nav__button nav__button--is-dropdown" id="autoentrymainbutton">Auto Entry <i class="icon-red fa fa-fw fa-minus"></i></span>\
  725.             <div class="nav__button nav__button--is-dropdown-arrow">\
  726.                 <i class="fa fa-angle-down"></i>\
  727.             </div>\
  728.         </div>');
  729.  
  730.         // needed for Tampermonkey - greasemonkey loads at interactive
  731.         if(document.readyState=='complete')
  732.         {
  733.             cont.find('#autoentrybuttoncontainer .nav__button--is-dropdown-arrow').click(function(e){
  734.                 var t=$(this).hasClass("is-selected");
  735.                 $("nav .nav__button").removeClass("is-selected");
  736.                 $("nav .nav__relative-dropdown").addClass("is-hidden");
  737.                 if(!t) {
  738.                     $(this).addClass("is-selected").siblings(".nav__relative-dropdown").removeClass("is-hidden");
  739.                 }
  740.                 e.stopPropagation();
  741.                 }
  742.             );
  743.         }
  744.        
  745.         $('#autoentrymenu').click(function() {
  746.             $(this).parent().siblings().removeClass('open');
  747.             $(this).parent().siblings().children('.relative-dropdown').children('.absolute-dropdown').hide();
  748.             $(this).parent().addClass('open');
  749.             $(this).siblings('.relative-dropdown').children('.absolute-dropdown').show();
  750.             return false;
  751.         });
  752.         $('#autoentryenabled, #autoentrymainbutton').click(function() {
  753.             if(enabled==false) {
  754.                 $("#autoentryenabled i").removeClass("icon-red");
  755.                 $("#autoentryenabled i").addClass("icon-green");
  756.                 $("#autoentryenabled i").removeClass("fa-toggle-off");
  757.                 $("#autoentryenabled i").addClass("fa-toggle-on");
  758.                 $('#autoentryenabled .nav__row__summary__name').text('Enabled');
  759.                 $('#autoentryenabled .nav__row__summary__description').text('Auto Entry currently enabled');
  760.                 $('#autoentrymainbutton i').removeClass("icon-red");
  761.                 $('#autoentrymainbutton i').addClass("icon-green");
  762.                 $('#autoentrymainbutton i').removeClass("fa-minus");
  763.                 $('#autoentrymainbutton i').addClass("fa-check");
  764.                 startautoentry();
  765.                 enabled=true;
  766.             }
  767.             else {
  768.                 $("#autoentryenabled i").removeClass("icon-green");
  769.                 $("#autoentryenabled i").addClass("icon-red");
  770.                 $("#autoentryenabled i").removeClass("fa-toggle-on");
  771.                 $("#autoentryenabled i").addClass("fa-toggle-off");
  772.                 $('#autoentryenabled .nav__row__summary__name').text('Disabled');
  773.                 $('#autoentryenabled .nav__row__summary__description').text('Auto Entry currently disabled');
  774.                 $('#autoentrymainbutton i').removeClass("icon-green");
  775.                 $('#autoentrymainbutton i').addClass("icon-red");
  776.                 $('#autoentrymainbutton i').removeClass("fa-check");
  777.                 $('#autoentrymainbutton i').addClass("fa-minus");
  778.                 stopautoentry();
  779.                 enabled=false;
  780.             }
  781.             return false;
  782.         });
  783.         $('#autoentrysettings').click(function() {
  784.             $("nav .nav__button").removeClass("is-selected");
  785.             $("nav .nav__relative-dropdown").addClass("is-hidden");
  786.             $('#autoentrysettingsdiv').center();
  787.             $('#autoentrysettingsdiv').css('top','50%');
  788.             $('#autoentrysettingsdiv').css('margin-top','-'+$('#autoentrysettingsdiv').height()/2+'px');
  789.             $('#autoentrysettingsdiv').slideDown();
  790.            
  791.             var ul=$('#autoentrygameul');
  792.             ul.empty();
  793.             for(var i=0; i<gamelist.length; i++) {
  794.                 ul.append(getgameli(gamelist[i]));
  795.             }
  796.             ul.sortable();
  797.             ul.disableSelection();
  798.             $('#autoentryminpoints').val(minpoints);
  799.             $('#autoentrymaxentries').val(maxentries);
  800.             $('#autoentrymaxpagenum').val(maxpagenum);
  801.             $('#autoentryminpointpageincr').val(minpointpageincr);
  802.             $('#autoentryenterwishlist').prop("checked",enterwishlist);
  803.             $('#autoentryentergroup').prop("checked",entergroup);
  804.             $('#autoentryenterfeatured').prop("checked",enterfeatured);
  805.             $('#autoentryenterfree').prop("checked",enterfree);
  806.             $('#autoentryenabledonload').prop("checked",enabledonload);
  807.             return false;
  808.         });
  809.         $('#autoentrybackuprestore').click(function() {
  810.             $("nav .nav__button").removeClass("is-selected");
  811.             $("nav .nav__relative-dropdown").addClass("is-hidden");
  812.             $('#autoentrybackuprestorediv').center();
  813.             $('#autoentrybackuprestorediv').css('top','50%');
  814.             $('#autoentrybackuprestorediv').css('margin-top','-'+$('#autoentrybackuprestorediv').height()/2+'px');
  815.             $('#autoentrybackuprestorediv').slideDown();
  816.             var savedsettings={};
  817.             savedsettings.version=5;
  818.             savedsettings.gamelist=gamelist;
  819.             savedsettings.minpoints=minpoints;
  820.             savedsettings.enterwishlist=enterwishlist;
  821.             savedsettings.entergroup=entergroup;
  822.             savedsettings.enterfeatured=enterfeatured;
  823.             savedsettings.enterfree=enterfree;
  824.             savedsettings.enabledonload=enabledonload;
  825.             savedsettings.maxentries=maxentries;
  826.             savedsettings.maxpagenum=maxpagenum;
  827.             savedsettings.minpointpageincr=minpointpageincr;
  828.             $('#autoentrybackupjson').val(JSON.stringify(savedsettings));
  829.             return false;
  830.         });
  831.         $('#autoentryhelp').click(function() {
  832.             $("nav .nav__button").removeClass("is-selected");
  833.             $("nav .nav__relative-dropdown").addClass("is-hidden");
  834.             $('#autoentryhelpdiv').center();
  835.             $('#autoentryhelpdiv').css('top','50%');
  836.             $('#autoentryhelpdiv').css('margin-top','-'+$('#autoentryhelpdiv').height()/2+'px');
  837.             $('#autoentryhelpdiv').slideDown();
  838.             return false;
  839.         });
  840.        
  841.         fn_addgametolist();
  842.         var elementsensor = $('.page__outer-wrap');
  843.         new ResizeSensor(elementsensor, function() {
  844.           //console.log('Changed to ' + elementsensor.height());
  845.             fn_addgametolist();
  846.         });
  847.     };
  848.    
  849.     if(enabledonload==true && document.location == ("https://www.steamgifts.com/")) {
  850.       $('#autoentryenabled').click();
  851.     }
  852.    
  853. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement