Advertisement
tacconux

Workshop Guide 1 click subscribe - popiazaza

Feb 24th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name            Dota 2 Workshop Guide 1 click subscribe
  3. // @author          popiazaza
  4. // @namespace       popiazaza
  5. // @description     Subscribe all guides from Dota 2 workshop in 1 click
  6. // @version         1.6
  7. // @include         https://steamcommunity.com/id/*/myworkshopfiles/?section=guides*
  8. // @grant           none
  9. // @require                 https://code.jquery.com/jquery-3.3.1.min.js
  10. // ==/UserScript==
  11.  
  12.  
  13. function dota2workshopsubnext(loaded = 0,subscribe = true){
  14.   if (jQuery(".pagebtn.disabled").length && jQuery(".pagebtn.disabled:first").text() == '>') {
  15.     if(subscribe){
  16.       ShowAlertDialog( 'Success!', 'You have subsribed to ' + loaded + ' guides!').done(function(){window.location = '?section=guides';});
  17.     }else{
  18.       ShowAlertDialog( 'Success!', 'You have unsubsribed to ' + loaded + ' guides!').done(function(){window.location = '?section=guides';});
  19.     }
  20.   }else{
  21.     jQuery(".pagebtn").each(function(){
  22.       if(jQuery(this).text() == '>' && jQuery(this).attr('href')){
  23.         var thislocation = jQuery(this).attr('href').replace(/&d2wg_all=(\d*)/, '');
  24.         thislocation = thislocation.replace(/&d2wg_un=(\d*)/, '');
  25.         if(subscribe){
  26.            window.location = thislocation + '&d2wg_all=' + loaded;
  27.         }else{
  28.            window.location = thislocation + '&d2wg_un=' + loaded;
  29.         }
  30.       }
  31.     });
  32.   }
  33. }
  34. function dota2workshopbackfirst(subscribe = true){
  35.   thislocation = window.location.href.replace(/&p=(\d*)/, '');
  36.   if(subscribe){
  37.     window.location = thislocation + '&d2wg_all=' + 999999;
  38.   }else{
  39.     window.location = thislocation + '&d2wg_un=' + 999999;
  40.   }
  41. }
  42. function dota2workshopsubnownuke(){
  43.   //dota2workshopsubnow(999999);
  44.   dota2workshopbackfirst();
  45. }
  46. function dota2workshopunsubnow(){
  47.   dota2workshopsubnow(0,false);
  48. }
  49. function dota2workshopunsubnownuke(){
  50.   //dota2workshopsubnow(999999,false);
  51.   dota2workshopbackfirst(false);
  52. }
  53. function dota2workshopsubnow(d2wg_all = 0,subscribe = true){
  54.     var guideList = [];
  55.     var subscribedList = [];
  56.    
  57.     jQuery("script").each(function(){
  58.         var guidematch = jQuery(this).html().match(/SharedFileBindMouseHover\( "(.*?)", true, (.*?) \);/);
  59.         if(guidematch){
  60.             var guidedetail = JSON.parse(guidematch[2].replace(/(\r\n|\n|\r)/gm,""));
  61.             guideList.push(guidedetail.id);
  62.             subscribedList[guidedetail.id] = guidedetail.user_subscribed;
  63.         }
  64.     });
  65.    
  66.     var i = 0,
  67.         loaded = 0,
  68.         package = 0,
  69.         total = guideList.length,
  70.         modal = ShowBlockingWaitDialog( 'Executing…',
  71.             'Please wait until all requests finish. Ignore all the errors, let it finish.' );
  72.    
  73.     for( ; i < total; i++ )
  74.     {
  75.         guideid = guideList[ i ];
  76.         //function below doesn't work because steam doesn't support it yet
  77.         //if( subscribedList[ guideid ] )
  78.         //{
  79.         //  loaded++;
  80.         //  continue;
  81.         //}
  82.      
  83.         if(subscribe){
  84.           var subscribeurl = '//steamcommunity.com/sharedfiles/subscribe';
  85.         }else{
  86.           var subscribeurl = '//steamcommunity.com/sharedfiles/unsubscribe';
  87.         }
  88.        
  89.         jQuery.post(subscribeurl,
  90.             {
  91.                 appid: 570,
  92.                 id: guideid,
  93.                 sessionid: g_sessionID
  94.             }
  95.         ).always( function( )
  96.             {
  97.                 loaded++;
  98.                
  99.                 modal.Dismiss();
  100.                
  101.                 if( loaded >= total )
  102.                 {
  103.                     if(d2wg_all){
  104.                       if(d2wg_all !== 999999){
  105.                         loaded = d2wg_all + loaded;
  106.                       }
  107.                       if(subscribe){
  108.                         dota2workshopsubnext(loaded);
  109.                       }else{
  110.                         dota2workshopsubnext(loaded,false);
  111.                       }
  112.                     }else{
  113.                       if(subscribe){
  114.                         ShowAlertDialog( 'Success!', 'You have subsribed to ' + loaded + ' guides!').done(function(){location.reload();});
  115.                       }else{
  116.                         ShowAlertDialog( 'Success!', 'You have unsubsribed to ' + loaded + ' guides!').done(function(){location.reload();});
  117.                       }
  118.                     }
  119.                 }
  120.                 else
  121.                 {
  122.                     modal = ShowBlockingWaitDialog( 'Executing…',
  123.                         'Loaded <b>' + loaded + '</b>/' + total + '.' );
  124.                 }
  125.             }
  126.         );
  127.     }
  128. }
  129.  
  130. (function()
  131. {
  132.   if(location.search.split('d2wg_all=')[1]){
  133.     dota2workshopsubnow(parseInt(location.search.split('d2wg_all=')[1]));
  134.   }else if(location.search.split('d2wg_un=')[1]){
  135.     dota2workshopsubnow(parseInt(location.search.split('d2wg_un=')[1]),false);
  136.   }
  137.   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>');
  138.   document.getElementById('dota2workshopsuball').addEventListener('click', dota2workshopsubnow, false);
  139.   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>');
  140.   document.getElementById('dota2workshopsuballnuke').addEventListener('click', dota2workshopsubnownuke, false);
  141.   jQuery('.followStatsBlock').append('<br><br><a href="javascript:void(0);" id="dota2workshopunsuball" class="btn_darkblue_white_innerfade btn_medium"><span>Unsubscribe all on this page</span></a>');
  142.   document.getElementById('dota2workshopunsuball').addEventListener('click', dota2workshopunsubnow, false);
  143.   jQuery('.followStatsBlock').append('<br><br><a href="javascript:void(0);" id="dota2workshopunsuballnuke" class="btn_darkblue_white_innerfade btn_medium"><span>Unsubscribe all from this person</span></a>');
  144.   document.getElementById('dota2workshopunsuballnuke').addEventListener('click', dota2workshopunsubnownuke, false);
  145. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement