Dota 2 Workshop Guide Auto Subscribe

Subscribe all guides from Dota 2 workshop in 1 click

As of 15/09/2018. See the latest version.

// ==UserScript==
// @name            Dota 2 Workshop Guide Auto Subscribe
// @author          popiazaza
// @namespace       popiazaza
// @description     Subscribe all guides from Dota 2 workshop in 1 click
// @version         1.2
// @include         https://steamcommunity.com/id/*/myworkshopfiles/?section=guides*
// @grant           none
// ==/UserScript==
function dota2workshopsubnext(loaded = 0){
  if (jQuery(".pagebtn.disabled").length) {
    ShowConfirmDialog( 'Success!', 'You have subsribed to ' + loaded + ' guides!');
  }else{
    jQuery(".pagebtn").each(function(){
      if(jQuery(this).text() == '>' && jQuery(this).attr('href')){
        window.location = jQuery(this).attr('href') + '&d2wg_all=' + loaded;
      }
    });
  }
}

function dota2workshopsubnownuke(){
  dota2workshopsubnow(999999);
}
function dota2workshopsubnow(d2wg_all = 0){
	var guideList = [];
	var subscribedList = [];
	
	jQuery("script").each(function(){
		var guidematch = jQuery(this).html().match(/SharedFileBindMouseHover\( "(.*?)", true, (.*?) \);/);
		if(guidematch){
			var guidedetail = JSON.parse(guidematch[2].replace(/(\r\n|\n|\r)/gm,""));
			guideList.push(guidedetail.id);
			subscribedList[guidedetail.id] = guidedetail.user_subscribed;
		}
	});
	
	var i = 0,
	    loaded = 0,
	    package = 0,
	    total = guideList.length,
	    modal = ShowBlockingWaitDialog( 'Executing…',
	    	'Please wait until all requests finish. Ignore all the errors, let it finish.' );
	
	for( ; i < total; i++ )
	{
		guideid = guideList[ i ];
		
		if( subscribedList[ guideid ] )
		{
			loaded++;
			continue;
		}
		
		jQuery.post(
			'//steamcommunity.com/sharedfiles/subscribe',
			{
				appid: 570,
				id: guideid,
				sessionid: g_sessionID
			}
		).always( function( )
			{
				loaded++;
				
				modal.Dismiss();
				
				if( loaded >= total )
				{
					if(d2wg_all){
                      if(d2wg_all !== 999999){
                        loaded = d2wg_all + loaded;
                      }
                      dota2workshopsubnext(loaded);
                    }else{
                      location.reload();
                    }
				}
				else
				{
					modal = ShowBlockingWaitDialog( 'Executing…',
						'Loaded <b>' + loaded + '</b>/' + total + '.' );
				}
			}
		);
	}
}

(function()
{
  if(location.search.split('d2wg_all=')[1]){
    dota2workshopsubnow(parseInt(location.search.split('d2wg_all=')[1]));
  }
  jQuery('.followStatsBlock').append('<a href="javascript:void(0);" id="dota2workshopsuball" class="btn_darkblue_white_innerfade btn_medium"><span>Subscribe all on this page</span></a>');
  document.getElementById('dota2workshopsuball').addEventListener('click', dota2workshopsubnow, false);
  jQuery('.followStatsBlock').append('<br><br><a href="javascript:void(0);" id="dota2workshopsuballnuke" class="btn_darkblue_white_innerfade btn_medium"><span>Subscribe all from this person</span></a>');
  document.getElementById('dota2workshopsuballnuke').addEventListener('click', dota2workshopsubnownuke, false);
}());