/* SGE addon - This a user-script that provides extra functionallity on top of steamgifts.com Copyright (C) 2012 Rossen Georgiev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ (function($) { // chrome/opera hack; var unsafeWindow = this['unsafeWindow'] || window; // check if already loaded if(unsafeWindow.gafIsLoaded) return false; unsafeWindow.gafIsLoaded = true; // doesnt load on search page if(window.location.href.indexOf("search/") > -1 ) return false; // make sure we only load the code on supported pages // -------- // This was functionality was moved from the init script. // Adding support for certain parts of the site will no longer require an action on the user side if(!window.location.href.match(/^https?\:\/\/www\.steamgifts\.com\/?(#|(open|new|forum).*)?$/)) if(typeof unsafeWindow.gafDev === 'undefined') return false; // load DLC database $('body').append(''); // fades background and shows+centre the popup unsafeWindow.gafPopupShow = function() { $("#gafPopup").css({ "top": document.documentElement.clientHeight / 2 - 150, "left": document.documentElement.clientWidth / 2 - 200 }); $('#gafPopup').fadeIn('slow'); $('#gafPopupBackground').fadeIn('normal'); } // hide popup and background unsafeWindow.gafPopupHide = function() { $('#gafOverlay').remove(); $('#gafPopup').fadeOut('normal'); $('#gafPopupBackground').fadeOut('slow'); $('.ajax_gifts>div.post.quickview').removeClass('quickview'); } // function is called everytime there is a change to textarea for the filter // and contents mirrored in the cookie unsafeWindow.gafFormUpdate = function() { unsafeWindow.localStorage.gafFilter = $('#gafFilterInput').val(); unsafeWindow.gafFilter = $('#gafFilterInput').val().split(','); } // called then ignore button is pressed // * adds name of the game to the filter and updates the cookie // * hides all giveaways for the same game // * slide up animantion unsafeWindow.gafIgnore = function(elm) { var node = elm.parentNode.parentNode.parentNode.parentNode; $(elm).hide(); $('#gafFilterInput').append(',' + $(node).find('.title').find('a').html()); unsafeWindow.gafFormUpdate(); unsafeWindow.gafApplyFilter($('.ajax_gifts>div.post')); unsafeWindow.gafLoadingCheck(); } // removes giveaway matching the filter unsafeWindow.gafApplyFilter = function(gafs) { // quick search if($.trim($('input[name=gafSearch]').val()) != "") { var match_pat = new RegExp($.trim($('input[name=gafSearch]').val()).replace(/[-[\]{}()+?.,\\^$|#\s]/g, '\\$&'),'i'); $(gafs).find('.title a').each(function(k,e) { if($(e).text().match(match_pat)) { $(e).parent().parent().parent().stop(true,true).slideDown(); } else { $(e).parent().parent().parent().stop(true,true).slideUp(); } }); setTimeout(unsafeWindow.gafLoadingCheck, 1000); return false; } var fall = $('#sg_fid0').is(':checked'); var fftr = $('#sg_fid1').is(':checked'); var fwish = $('#sg_fid2').is(':checked'); var ffade = $('#sg_fid3').is(':checked'); var fpts = $('#sg_fid4').is(':checked'); var fdlc = $('#sg_fid5').is(':checked'); var freg = $('#sg_fid6').is(':checked'); var fgrp = $('#sg_fid7').is(':checked'); var fgreen = $('#sg_fid8').is(':checked'); var fred = $('#sg_fid9').is(':checked'); var fcont_min = parseFloat($('#gafViewLinks .price.min').text().replace('$','')); var fcont_max = parseFloat($('#gafViewLinks .price.max').text().replace('$','')); // show all giveaways if(fall) { gafs = $(gafs).filter(':hidden'); gafs.find('.description').attr('style',''); gafs.slice(0,5).slideDown(function() { gafs.slice(5).show(); }); return true; } var finalset = []; // final set of giveways that will be displayed var fgafs = [] // filtered set of giveaways, source for other filters // filter already owned or ignored giveaways if(fftr || fwish) { var gaflist = $.unique(unsafeWindow.gafFilter.concat(unsafeWindow.gafSyncFilter).sort()); var gafstr; // when the list is empty, additional filtering like for contributor giveaways doenst work // this this is because, the code block for the second block doesnt execture gaflist.push('_______'); // quick fix fake entry // remove all DLC for games we dont own if(fdlc) $.merge(gaflist, unsafeWindow.gafDLCSyncd); fgafs = $(gafs).map(function(i,giveaway) { var elm = $(giveaway).find('a')[0]; $(giveaway).find('.description').attr('style',''); match = false; for(j = 0; j < gaflist.length; j++) { gafstr = $.trim(gaflist[j]).toLowerCase().replace(/&/g,'&'); if(gafstr == "") continue; // check if we are parsing a highlight entry var highlight = false; if(gafstr.match(/^\d+\. /)) { highlight = true; gafstr = gafstr.replace(/^\d+\. /,''); } var pat = new RegExp('^'+gafstr.replace(/[\_\-\[\]{}()+?.,\\^$|#\s]/g, '\\$&').replace(/\*/g,'.*')+'$'); if(highlight) { // if element doenst match continue with next one if(!elm.innerHTML.toLowerCase().match(pat)) continue; // else highlight the element and make it visible $(giveaway).find('.description').css({background: '#aaFFa8'}); if(fwish) return giveaway; // append fgafs with highlighted giveway, if highlighted is enabled (fwish) } else if(elm.innerHTML.toLowerCase().match(pat)) { match = true; break; } } if(!match && fftr) return giveaway; // append giveaway if not in filter list }).get(); } else { fgafs = $(gafs).find('.description').attr('style','').parent().parent().get(); } // filter finalset by number of points if(fpts) { // need to get current number of points, if logged in var p = $('#navigation li a.arrow').slice(1,2).text().match(/\-?(\d+)P/); if(!p) return false; else p = parseInt(p[1]); if(p < 0) return false; fgafs = $(fgafs).find('.title span').map(function(i,e) { var s = e.innerHTML.match(/(\d+)P/); if(s) { if(s && parseInt(s[1]) <= p) return $(e).parent().parent().parent().get(); } }).get(); } // include contributor giveaways if(ffade) { fgafs = $(fgafs).filter(':not(.fade)').get(); } // include group giveaways if(fgrp) { // subset of group giveaways var tmp = $(fgafs).find('.group_only').parent().parent().parent(); // susbet of tmp of red contributor giveways var subset = tmp.find('.contributor_only:not(.green)').parent().parent().parent(); // subtract sets $.merge(finalset, $.grep(tmp, function(e) { return $.inArray(e, subset) == -1 })); } // include contributor giveaways if(fgreen) { $.merge(finalset, $(fgafs).find('.contributor_only.green').parent().parent().parent().get()); } if(fred) { $.merge(finalset, $(fgafs).find('.contributor_only:not(.green)').parent().parent().parent().get()); } // contributor range finalset = $.grep(finalset, function(e) { e = $(e); if(e.find('.contributor_only').length > 0) { var amount = parseFloat(e.find('.contributor_only').text().match(/[0-9\.,]+/)[0]); return (amount >= fcont_min) && (amount <= fcont_max); // apply contributor range } return true; }, false); // include regular giveaways if(freg) { $.merge(finalset, $(fgafs).map(function(i,e) { if($(e).find('.group_only,.contributor_only').length == 0) { return e; } }).get()); } // allways show developer giveaways on top $.merge(finalset, $(".content>.post .new:contains('Developer')").parent().parent().parent().get()); //--------------------- // Filters end //--------------------- // finalize finalset // if no filters are selected simply output the whole list if(!fgreen && !fred && !fgrp && !freg) finalset = fgafs; else finalset = $.unique(finalset); // excludeset consists of only giveaways that should be hidden var excludeset = $(gafs).map(function() { if( $.inArray(this,finalset) < 0) { return this; } }).get(); // display results :) excludeset = $(excludeset).filter(':visible'); finalset = $(finalset).filter(':hidden'); excludeset.slice(0,5).stop(true,true).slideUp(function() { excludeset.slice(5).stop(true,true).hide(); }); finalset.slice(0,5).stop(true,true).slideDown(function() { finalset.slice(5).stop(true,true).show(); }); } // add ignore buttons to all giveaways :) unsafeWindow.gafAddIgnoreButton = function(elms) { var gafs = $(elms).find('a'); for(i = 0; i < gafs.length; i++) { if(gafs[i].href.match(/\/giveaway.*?entries$/)) { $(gafs[i].parentNode.parentNode).append("Ignore") } } } // function is called by iframe onLoad // filters new giveaways and adds them to the current page for endless scroll unsafeWindow.gafPageLoaded = function(data) { if(data == '') { return; } else { var loadedContent = $(data); } if(window.location.href.match(/forum/)) { if(unsafeWindow.gafHrefPart.length > 5) { unsafeWindow.gafAddHC(loadedContent); if(unsafeWindow.gafReverse) { loadedContent.find('.parent_container').reverse().insertAfter($('.parent_container').last()); } else { loadedContent.find('.parent_container').insertAfter($('.parent_container').last()); } // restore click functionallity // code taken from SG, credit: CG $('.delete_comment').click(function(){ $("input[name='delete_comment_id']").val($(this).parent().attr("rel")); $('#delete_comment').submit(); return false; }); $('.comment_reply .edit_comment').click(function(){ $(this).parent().parent().parent().children('.user_body').hide(); $(this).parent().parent().parent().children('.user_edit').show(); return false; }); $('.comment_reply .reply_link a').click(function(){ id=$(this).attr('rel'); depth=parseInt($(this).attr('class'))+1; $("#comment_form #parent_id").val(id); $("span.title").html("Add a reply"); $("span.cancel").show(); $("#comment_form").insertAfter('.comment#' + id); $("#comment_form").addClass('border_container'); return false; }); $('#comment_form span.cancel a').click(function(){ $("#comment_form #parent_id").val(0); $("span.title").html("Add a comment"); $("span.cancel").hide(); $("#comment_form").insertAfter('#comment_location'); $("#comment_form").removeClass('border_container'); return false; }); $('.cancel_edit_comment').click(function(){ $(this).parent().parent().parent().parent().children('.user_body').show(); $(this).parent().parent().parent().parent().children('.user_edit').hide(); return false; }); } else { loadedContent.find('.row a').each(function(key,obj) { if($(obj).attr('href').match(/^\/forum/)) { var newURL = $(obj).attr('href') + "/page/31337"; $(obj).attr('href',newURL); } }); loadedContent.find('.row').appendTo('.discussions'); $('.row').css({padding: $('#gafSlider').slider("value") + "px 0"}); } } else { // remove Contributor links from loaded elements // get all giveaways var elms = loadedContent.find('.ajax_gifts>div.post'); // update points from endless scroll page load var p = loadedContent.find('#navigation li a.arrow').slice(1,2).text().match(/(\d+)P/); if(p && parseInt(p[1]) != NaN) { unsafeWindow.gafSetPoints(p[1]); } // new page refresh if(unsafeWindow.gafLoadingNew) { var codebase = {}; var celms = $('.ajax_gifts>div.post').slice(0,15); var code = celms.first().find('.title a').attr('href').match(/way\/([a-z0-9]{4,6})\//i)[1]; var i = 0; for(; i < 10; i++) { if($(elms[i]).find('.title a').attr('href').match(/way\/([a-z0-9]{4,6})\//i)[1] == code) break; } if(i > 0) { $('div.pagination:first').after(elms.slice(0,i).hide().css({padding:unsafeWindow.gafPadding+'px 0'})); unsafeWindow.gafAddIgnoreButton(elms.slice(0,i)); unsafeWindow.gafApplyFilter(elms.slice(0,i)); } celms.each(function(k,v) { codebase[ $(v).find('.title a').attr('href').match(/way\/([a-z0-9]{4,6})\//i)[1] ] = k; }); elms.slice(i,20).each(function(k,v) { var test = codebase[ $(v).find('.title a').attr('href').match(/way\/([a-z0-9]{4,6})\//i)[1] ]; if(test != undefined) { $(celms[test]).find('.time_remaining').html('').append($(v).find('.time_remaining').html()); $(celms[test]).find('.entries span').slice(0,2).remove(); $(celms[test]).find('.entries').prepend($(v).find('.entries span').slice(0,2)); } }); unsafeWindow.gafLoadingNew = false; } else { unsafeWindow.gafAddIgnoreButton(elms); if(elms.length > 0) { if($('div.post').length > 0) { $('div.post').last().after(elms); } else { $('div.pagination:first').after(elms); } } $('div.post').css({padding: $('#gafSlider').slider("value") + "px 0"}); unsafeWindow.gafApplyFilter(elms.hide()); } unsafeWindow.gafAddOverlay(); } if( (!unsafeWindow.gafReverse && unsafeWindow.gafPage == unsafeWindow.gafMaxPage) || (unsafeWindow.gafReverse && unsafeWindow.gafPage == 1) ) { $('#gafLoading').html("

You've reached the end.

"); if(unsafeWindow.gafShowSettings && $('.post').length == 0) { $('#gafLoading').html("

There seem to be no giveaways matching your settings.

"); } } unsafeWindow.gafLoading = false; unsafeWindow.gafLoadingCheck(); } // function runs when gafLoading is in veiw unsafeWindow.gafLoadNextPage = function() { if(!unsafeWindow.gafLoading && ( (!unsafeWindow.gafReverse && unsafeWindow.gafPage < unsafeWindow.gafMaxPage) || (unsafeWindow.gafReverse && unsafeWindow.gafPage > 1) )){ unsafeWindow.gafLoading = true; unsafeWindow.gafPage += (unsafeWindow.gafReverse) ? -1 : 1; var url = ''; if(window.location.href.match(/forum/)) { if(unsafeWindow.gafHrefPart.length > 5) { if(unsafeWindow.gafReverse) { url = window.location.href.replace(/\d+$/,unsafeWindow.gafPage); } else { url = window.location.href + '/page/' + unsafeWindow.gafPage; } } else { url = 'http://www.steamgifts.com/forum/page/' + unsafeWindow.gafPage; } } else if(window.location.href.match(/new$/)) { url = 'http://www.steamgifts.com/new/page/' + unsafeWindow.gafPage; } else { url = 'http://www.steamgifts.com/open/page/' + unsafeWindow.gafPage; } $.get(url, function(data) { unsafeWindow.gafPageLoaded(data); }); } } // credit for code goes to creators to the reddit enchancement suit // check if obj in the view unsafeWindow.gafElementInSight = function(obj) { var top = obj.offsetTop; var left = obj.offsetLeft; var width = obj.offsetWidth / 4; var height = obj.offsetHeight / 4; while(obj.offsetParent) { obj = obj.offsetParent; top += obj.offsetTop; left += obj.offsetLeft; } return top >= window.pageYOffset && left >= window.pageXOffset && (top + height) <= (window.pageYOffset + window.innerHeight) && (left + width) <= (window.pageXOffset + window.innerWidth); } // creates a filter array using the sync games unsafeWindow.gafSync = function() { // get list from the sync page $.get('http://www.steamgifts.com/sync', function(data) { // update the syncfilter array $(data.match(/\"code\">(.*?)<\//g)).each(function(k,v) { unsafeWindow.gafSyncFilter.push(v.replace(/\"code\">/g,'').replace(/<\//g,'')); }); unsafeWindow.gafSyncFilter = $.grep(unsafeWindow.gafSyncFilter, function(a) { return !a.match(/^.post')); // check if we got the loading element in sight unsafeWindow.gafLoadingCheck(); }); } // check if gafLoading is in sight unsafeWindow.gafLoadingCheck = function() { if(unsafeWindow.gafElementInSight( document.getElementById('gafLoading') ) ) { // || unsafeWindow.gafPage < 3) { setTimeout(unsafeWindow.gafLoadNextPage, 1); } } // refresh if on /new page unsafeWindow.gafRefreshCheck = function() { if(!unsafeWindow.gafLoading) { unsafeWindow.gafLoading = true; unsafeWindow.gafLoadingNew = true; $.get('http://www.steamgifts.com/new/page/1', function(data) { unsafeWindow.gafPageLoaded(data); }); } setTimeout(unsafeWindow.gafRefreshCheck, 1000 * 90); } // toggle endless scroll on various pages unsafeWindow.gafToggleScroll = function(obj) { if(obj.innerHTML == "on") { obj.innerHTML = 'off'; if(window.location.href.match(/\/forum/)) { if(unsafeWindow.gafHrefPart.length > 5) { unsafeWindow.gafOptions = unsafeWindow.gafOptions.replace(/D/g,''); } else { unsafeWindow.gafOptions = unsafeWindow.gafOptions.replace(/F/g,''); } } else { unsafeWindow.gafOptions = unsafeWindow.gafOptions.replace(/G/g,''); } } else { obj.innerHTML = 'on'; if(window.location.href.match(/\/forum/)) { if(unsafeWindow.gafHrefPart.length > 5) { unsafeWindow.gafOptions += 'D'; } else { unsafeWindow.gafOptions += 'F'; } } else { unsafeWindow.gafOptions += 'G'; } } document.cookie = "gafOptions=" + unsafeWindow.gafOptions + "; expires=Fri, 27 Jul 2030 02:47:11 UTC; path=/"; if(!window.location.href.match(/page\/31337$/) && window.location.href.match(/page\/\d+$/) && !unsafeWindow.gafReverse ) { window.location.href = window.location.href.replace(/\/page\/\d+/,''); } else { if(obj.innerHTML == 'on' && unsafeWindow.gafReverse) { window.location.href = window.location.href.replace(/\/page\/\d+/,'') + '/page/31337'; } else { window.location.href = window.location.href; } } } // toggle reverse order unsafeWindow.gafToggleRev = function(obj) { if(obj.innerHTML.match(/newest/)) { obj.innerHTML = 'oldest first'; unsafeWindow.gafOptions = unsafeWindow.gafOptions.replace(/R/g,''); unsafeWindow.gafReverse = false; } else { obj.innerHTML = 'newest first'; unsafeWindow.gafOptions += 'R'; unsafeWindow.gafReverse = true; } document.cookie = "gafOptions=" + unsafeWindow.gafOptions + "; expires=Fri, 27 Jul 2030 02:47:11 UTC; path=/"; if(unsafeWindow.gafScrollOn && unsafeWindow.gafReverse) { window.location.href = window.location.href.replace(/\/page\/\d+/,''); } else if(unsafeWindow.gafScrollOn) { window.location.href = window.location.href + '/page/31337'; } else { $('.parent_container').reverse().appendTo('.comment_container'); } } unsafeWindow.gafHideFeatured = function(obj) { if(unsafeWindow.gafFeaturedHidden) { unsafeWindow.gafOptions = unsafeWindow.gafOptions.replace(/Z/g,''); $(this).attr('checked',false); unsafeWindow.gafFeaturedHidden = false; $('.featured').slideDown(); } else { unsafeWindow.gafOptions += "Z"; $(this).attr('checked',true); unsafeWindow.gafFeaturedHidden = true; $('.featured').slideUp(); } document.cookie = "gafOptions=" + unsafeWindow.gafOptions + "; expires=Fri, 27 Jul 2030 02:47:11 UTC; path=/"; } unsafeWindow.gafSyncToggle = function(obj) { if(unsafeWindow.gafSyncState) { unsafeWindow.gafOptions = unsafeWindow.gafOptions.replace(/S/g,''); $(this).attr('checked',false); unsafeWindow.gafSyncState = false; } else { unsafeWindow.gafOptions += "S"; $(this).attr('checked',true); unsafeWindow.gafSyncState = true; if(unsafeWindow.gafSyncFilter.length < 1) unsafeWindow.gafSync(); } document.cookie = "gafOptions=" + unsafeWindow.gafOptions + "; expires=Fri, 27 Jul 2030 02:47:11 UTC; path=/"; } // rearrange page to fit in 500px window unsafeWindow.gafOverlayLoaded = function(obj) { $('#gafPopupBackground').fadeIn('slow'); var e = $(obj).contents(); // update points from the overlay page var p = e.find('#navigation li a.arrow').slice(1,2).text().match(/(\d+)P/); if(p && parseInt(p[1]) != NaN) { unsafeWindow.gafSetPoints(p[1]); } if( e.find('#form_enter_giveaway a.entered').length > 0 ) { $('.ajax_gifts>div.post.quickview').addClass('fade'); } else { $('.ajax_gifts>div.post.quickview').removeClass('fade'); } e.find('.footer,.featured .left').remove(); e.find('.bg_gradient .content').first().remove(); e.find('.content').css({width:'500px'}); e.find('.bg_gradient').css({'background-position':'center center'}); e.find('.body_container').css({width:'400px'}); e.find('.parent_container').css({padding:0}).find('.comment.parent').css({padding:'5px'}); e.find('.featured').css({padding:0}).find('.right').css({'padding-top':'5px'}); e.find('body').css({'min-width':0,width:'510px'}); e.find('#comment_form').prependTo(e.find('.wrapper').css({padding:0})).find('.body_container').attr('style','') var env = $('#gafOverlay iframe').contents().find('#comment_form'); $('') .appendTo(env.find('.comment_reply')).click(function() { $.post($('#gafOverlay iframe').attr('src'), $('#gafOverlay iframe').contents().find('#form_enter_giveaway').serialize(), function(data) { env.find('form') .append('').submit(); }); return false; }); env.find('.comment_reply input:first').attr("value","Submit"); if(!$(obj).hasClass('gafMoved')) { $(obj).addClass('gafMoved'); var x = $(obj).parent().css('left').match(/(\d+)/)[1]; var y = $(obj).parent().css('top').match(/(\d+)/)[1]; $(obj).parent().css({left: (x - 530) + "px",top:y - 100}); $(obj).css({width:'530px',height:'400px'}).parent().find('img').hide(); } } unsafeWindow.gafAddOverlay = function() { $('.post .right').each(function(k,v) { v = $(v); if(v.find('div').length > 0) return; v.find('img').css({float:'right'}) $('
Quick View
').css({opacity:0,'font-size':'20px',color:"#000",'font-size':'25px','background-color':'#ccc',float:'left',position:'absolute',width:'144',height:'29px','padding':'20px','font-weight':'bold',cursor:'pointer','text-align':'center'}) .mouseleave(function() { $(this).stop(true,true).animate({opacity:'0'},1000); }) .mouseover(function() { $(this).stop(true,true).animate({opacity:'0.75'},100); }) .appendTo(v) .click(function() { if($('#gafOverlay').length > 0) return false; $(this).parent().parent().addClass("quickview"); $('body').append("
"); var elm = $(this)[0]; $('#gafOverlay').css({ top: (elm.offsetTop + 15) + 'px', left: (elm.offsetLeft - 20) + 'px' }); return false; }); }); } unsafeWindow.gafPutLoading = function() { $('.pagination:last').html("

Gremlins are fetching more stuff. Please standby...

"); } unsafeWindow.gafSetPoints = function(pts) { var e = $('#navigation li a.arrow:contains("Account")'); var a = e.text().match(/(\d+)P/); if(a.length) { var p = a[1]; var y = Math.round(Math.random()*60)-50; var x = Math.round(Math.random()*40)-20; var total = pts - p; $('#nav,#navigation').each(function(k,v) { v = $(v).find('li a.arrow:contains("Account")').text('Account ('+pts+'P)'); }); if(total == 0) return; $('
'+((total >= 0)?'+'+String(total):total)+'
') .appendTo('body') .css({position:'fixed', top:'0px', left: ($('#navigation li a.arrow:contains("Account")')[0].offsetLeft + 50) + "px", 'font-size':'20px', 'font-weight':'bold', 'text-shadow':'#666 0px 0px 6px', color:(total >= 0) ? '#77FF73' : 'red', 'z-index':55 }) .show().animate({top:60+x,left:'+='+y},350) .delay(300).animate({fontSize:'60px',top:'-=10',left:'-=20'},100) .delay(100).fadeOut(300,function(){ $(this).remove(); }); } } unsafeWindow.gafDLCSyncd = []; unsafeWindow.gafLoadDLC = function() { // make sure DLC database is loaded if(typeof unsafeWindow.gafDLC === 'undefined') { setTimeout(unsafeWindow.gafLoadDLC, 100); return; } // add all for(var item in unsafeWindow.gafDLC) { if($.inArray(item, unsafeWindow.gafSyncFilter) == -1) $.merge(unsafeWindow.gafDLCSyncd, unsafeWindow.gafDLC[item]); }; } unsafeWindow.gafUpdateViews = function() { var v = ['All', 'Filtered', 'Wishlist','Entered', 'Limit by points','DLC','Regular','Group','C.Green','C.Red']; // load filter layout var s = ''; for(var i = 0; i < v.length; i++) s += (unsafeWindow.gafFilOpts >> i) % 2; // place container if($('#gafViewLinks').length == 0) { $('body').prepend(""); $('.pagination:first').prepend('
  1. Modify filter
'); } $("#gafFNav, #gafFNav .absolute-dropdown.open").mouseout(function() { var e = $(this); unsafeWindow.gafFNav_n = setTimeout(function() { e.find('.open').removeClass('open').find('.absolute-dropdown').hide(); }, 1000); }); $("#gafFNav, #gafFNav .absolute-dropdown.open").mouseover(function() { if(typeof unsafeWindow.gafFNav_n !== 'undefined') clearTimeout(unsafeWindow.gafFNav_n); }); var elm = $('#gafViewLinks'); elm.html('

  • Contributor range
  • 0$
    4000$
  • '); elm = elm.find('li:first'); // fill the container with the options for(var i = 0; i < v.length; i++) { if(i > 4) elm = elm.parent().find('li').slice(1,2); elm.append(" " + ((i>=6)?"":'') + v[i] + ((i>=5)?"":'') + '  '); } // if all is checked, disable the rest of the options if(s[0]==1) $('#gafViewLinks input[type="checkbox"]').slice(1,99).attr('disabled','disabled'); $('#sg_fdlc_range').slider({ range:true,values:[0,1000],min:0,step:1,max:200,animate:true, slide: function(event, ui) { var e = $('#sg_fdlc_range').parent().find('.price'); e.first().text(Math.floor(ui.values[0]*(ui.values[0]/10)) + '$'); e.last().text(Math.floor(ui.values[1]*(ui.values[1]/10)) + '$'); }, stop: function(event, ui) { unsafeWindow.gafApplyFilter($('.ajax_gifts>div.post')); setTimeout(unsafeWindow.gafLoadingCheck, 1000); } }); } $("#gafLivePreview h1:first").live("click", function() { var e = $("#gafLivePreview .markdown"); if(e.is(':visible')) e.hide(); else e.show(); }); $("#create_form textarea#body, #comment_form textarea#body, .user_edit textarea").live('keyup', function() { var e = $(this); if($("#gafLivePreview").length > 0 && e.parent().parent().find("#gafLivePreview").length == 0) $("#gafLivePreview").remove(); if(e.val() != "" && $("#gafLivePreview").length == 0) { var insertAfterElement; if(window.location.href.match(/forum\/(new|edit)$/)) insertAfterElement = e.parent().find('.clear_both'); else { insertAfterElement = e.parent().parent().find('.clear_both'); if(insertAfterElement.length == 0) insertAfterElement = e.parent().parent().parent().parent().find('.clear_both'); if(insertAfterElement.length == 0) insertAfterElement = e.parent().parent().parent().parent().find('.user_edit'); } insertAfterElement.after('

    Live Preview

    '); } else if(e.val() == "") { $('#gafLivePreview').remove(); return; } var tmp = e.val(); // emulate markdown // remove long vertical spaces tmp = tmp.replace(/\n{3,}/g,"\n\n"); // add horizontal spaces tmp = tmp.replace(/\-{3,}/gi,"
    "); // headings tmp = tmp.replace(/(<\/?p>|\n|^)(\#{1,3}) (.*?)\n/gi, function(a,b,c,d) { var str = (b == "

    ") ? "" : "

    "; var n = c.length; return str + "" + d + "

    "; }); tmp = tmp.replace(/\n?(.*?)\n\={4,}/gi,"

    $1

    "); tmp = tmp.replace(/\n?(.*?)\n\-{4,}/gi,"

    $1

    "); // break line and paragraph tmp = tmp.replace(/( \n)/gi,"
    "); tmp = tmp.replace(/(\n\n)/gi,"

    "); // handle urls tmp = tmp.replace(/\[(.*?)\]\((((http)s?\:\/\/)?.*?)\)/gi, function(a,b,c,d,e) { return ''+b+'' }); // bullets points, very basic tmp = tmp.replace(/\n\* /gi,"
       ●  "); tmp = tmp.replace(/>\* /gi,">   ●  "); // italics and bold tmp = tmp.replace(/(\*\*|__)(.*?)\1/gi,"$2"); tmp = tmp.replace(/\*(.*?)\*/gi,"$1"); // code tag tmp = tmp.replace(/`(.*?)`/gi,"$1"); // fix paragraphs tmp = "

    "+tmp+"

    "; tmp = tmp.replace(/

    <\/p>/g,""); $("#gafLivePreview .markdown").html(tmp); }); // move the comment box at the top for less frustration if(window.location.href.match(/\/forum\//)) $('.discussions').after($('#comment_form')); else $('.sub_navigation').before($('#comment_form')); $("span.cancel a").live('mousedown', function() { $("#gafLivePreview").remove(); setTimeout(function() { if(window.location.href.match(/\/forum\//)) $('.discussions').after($('#comment_form')); else $('.sub_navigation').before($('#comment_form')); }, 120); }); $("a.cancel_edit_comment").live('mousedown', function() { $("#gafLivePreview").remove(); }); unsafeWindow.gafAddHC = function(elm) { $(elm).find(".comment_container .parent_container .border_container").parent().find(".parent .reply_link").parent().append(' or Hide child comments'); } unsafeWindow.gafAddHC('body'); $(".gafHideChild").live("click", function() { var e = $(this); if(e.hasClass("show")) { e.removeClass("show"); e.text("Show child comments"); e.parent().parent().parent().parent().parent().find(".border_container").stop(true,true).slideUp('fast'); } else { e.addClass("show"); e.text("Hide child comments"); e.parent().parent().parent().parent().parent().find(".border_container").stop(true,true).slideDown('fast'); } return false; }); // main code if(window.location.href.match(/forum\/edit$/)) return; // rest of the code is not applicable on this page unsafeWindow.gafFilter = []; unsafeWindow.gafSyncFilter = []; // flags for options // G - giveaway endless scroll turned on // F - forum endless scroll turned on // D - dicussion endless scroll // R - reverse order of comments // S - ignore sync games unsafeWindow.gafOptions = "GFDR"; unsafeWindow.gafPadding = 25; unsafeWindow.gafFilOpts = 230; var $ = unsafeWindow.jQuery; $.fn.reverse = [].reverse; // add popup elements $('body').append("

    "); // read cookie var i,j,val='',c=document.cookie.split(";"); for (i=0;i 5) { if( unsafeWindow.gafOptions.match('R') && !window.location.href.match(/page\/31337$/)) { window.location.href = window.location.href.split('/').slice(0,6).join('/') + '/page/31337'; } if( unsafeWindow.gafOptions.match('R') || window.location.href.match(/page\/31337$/)) { unsafeWindow.gafReverse = true; } if( !unsafeWindow.gafOptions.match('D') ) { unsafeWindow.gafScrollOn = false; } unsafeWindow.gafPerPage = 40; unsafeWindow.gafShowReverse = true; } else { if( !unsafeWindow.gafOptions.match('F') ) { unsafeWindow.gafScrollOn = false; } if( unsafeWindow.gafOptions.match('R') ) { unsafeWindow.gafRepReverse = true; } unsafeWindow.gafPerPage = 50; } unsafeWindow.gafShowSettings = false; break; case "new": setTimeout(unsafeWindow.gafRefreshCheck, 1000 * 60); case "": case "open": if( !unsafeWindow.gafOptions.match('G') ) { unsafeWindow.gafScrollOn = false; } unsafeWindow.gafReverse = false; if( unsafeWindow.gafOptions.match('S') ) { unsafeWindow.gafSync(); } break; } if( unsafeWindow.gafOptions.match('S') ) { unsafeWindow.gafSyncState = true; $('#gafSyncCBox').attr('checked',true); } if( unsafeWindow.gafOptions.match('Z') ) { unsafeWindow.gafFeaturedHidden = true; $('#gafHideFeatCBox').attr('checked',true); } // remove giveaways and add ignore buttons if(unsafeWindow.gafShowSettings) { unsafeWindow.gafUpdateViews(); val = $('.ajax_gifts>div.post'); unsafeWindow.gafApplyFilter(val); unsafeWindow.gafAddIgnoreButton(val); unsafeWindow.gafAddOverlay(); } // get rows per page, total rows, and calculate max page unsafeWindow.gafMaxPage = Math.ceil($('.results').first().text().replace(',','').match(/(\d+) result/)[1] / unsafeWindow.gafPerPage); unsafeWindow.gafPage = (unsafeWindow.gafReverse) ? unsafeWindow.gafMaxPage : 1; // endless scroll settings on page if(unsafeWindow.gafShowESS) $('.results:first').html("Endless scrolling is "+((unsafeWindow.gafScrollOn)?'on':'off')+""); if(unsafeWindow.gafShowSettings) { $('#gafViewLinks a').live('click', function() { var id = $(this).attr('id').match(/\d+/); $('#gafViewLinks input').slice(5,15).attr('checked','').slice(id-5,id-4).attr('checked','checked'); // save filter layout var dopts = 0; $('#gafViewLinks input').each(function(i,e){ dopts += (($(this).attr('checked')!='')/1) << i; }); document.cookie = "gafFopts=" + dopts + "; expires=Fri, 27 Jul 2030 02:47:11 UTC; path=/"; unsafeWindow.gafApplyFilter($('.ajax_gifts>div.post')); return false; }); $('#gafViewLinks input').live('change', function() { if($('#sg_fid0').is(':checked')) { $('#gafViewLinks input').slice(1,99).attr('disabled','disabled'); } else { $('#gafViewLinks input:disabled').removeAttr('disabled'); } // save filter layout var dopts = 0; $('#gafViewLinks input').each(function(i,e){ dopts += (($(this).attr('checked')!='')*1) << i; }); document.cookie = "gafFopts=" + dopts + "; expires=Fri, 27 Jul 2030 02:47:11 UTC; path=/"; unsafeWindow.gafApplyFilter($('.ajax_gifts>div.post')); setTimeout(unsafeWindow.gafLoadingCheck, 1000); return false; } ); $('.sub_navigation h1').html('

    Dear User, the SGE addon will be discontinued. Consider using SG+. Happy holidays! -Zo

    '); $('input[name=gafSearchClear]').click(function() { $('input[name=gafSearch]').val(''); unsafeWindow.gafApplyFilter($('.ajax_gifts>div.post')); }); $('input[name=gafSearch]').keyup(function() { clearTimeout(unsafeWindow.gafssssssss); unsafeWindow.gafssssssss = setTimeout("gafApplyFilter($('.ajax_gifts>div.post'));",400); }); } // reverse order settings on page if(unsafeWindow.gafShowReverse && unsafeWindow.gafShowESS) { $('.results:first').append(" and order "+((unsafeWindow.gafReverse)?'newest first':'oldest first')+""); } else if(unsafeWindow.gafShowESS) { $('.results:first').append("
    "); $('#gafSlider').slider({ min:0,max:25,animate:true,value: unsafeWindow.gafPadding, slide: function(event, ui) { $('.post,.row').css({padding:ui.value+'px 0'}); }, stop: function(event, ui) { unsafeWindow.gafPadding = ui.value; document.cookie = "gafPadding=" + ui.value + "; expires=Fri, 27 Jul 2030 02:47:11 UTC; path=/"; } }); $('.ajax_gifts>div.post,.row').css({padding: unsafeWindow.gafPadding +'px 0'}); } if(unsafeWindow.gafScrollOn) { // endless scrolling elements and adjustments $('.numbers').remove() // turn off scrolling if there is only one page if(unsafeWindow.gafMaxPage == 1) { unsafeWindow.gafScrollOn = false; $('.pagination:last').html("

    You've reached the end.

    "); } else { unsafeWindow.gafPutLoading(); } } // reverse order if(unsafeWindow.gafReverse) { $('.parent_container').reverse().appendTo('.comment_container'); } // fix urls for discussions in the forum page for reverse order if(unsafeWindow.gafRepReverse) { $('.row a').each(function(key,obj) { if($(obj).attr('href').match(/^\/forum/)) { var newURL = $(obj).attr('href') + "/page/31337"; $(obj).attr('href',newURL); } }); } // replicate nagivation bar to use as float menu $('body').prepend('