League Talk Unfollower

This script searches for the league you have followed and help you to Unfollow them.

  1. // ==UserScript==
  2. // @name League Talk Unfollower
  3. // @namespace Jefreesujit
  4. // @version 2.0
  5. // @description This script searches for the league you have followed and help you to Unfollow them.
  6. // @author Jefreesujit
  7. // @match http://hitwicket.com/discussionForum/112387/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. $(".thread_content").html("");
  12. $(".thread_content").append('<meta property="article:tag" content="apps" />'+
  13. '<meta property="article:tag" content="games" />'+
  14. '<meta property="article:tag" content="sports" />'+
  15. '<meta name="keywords" content="cricket , u20 , hitwicket , league, unfollower, unfollower script, league unfollow , league talk, league talk unfollower, u20 player, hitwicket jefreesujit, jefreesujit " />'+
  16.  
  17. '<div style="padding-left:0em;"><b>LEAGUE TALK UNFOLLOWER SCRIPT</b></div></br>'+
  18. "<div>Searching the Followed leagues in lower divisions (5, 6 and 7) takes more time, so please be patient. <br>"+
  19. " Please wait till the complete list of folllowed leagues is loaded, before clicking Unfollow All button.</div><div><br><br></div>" +
  20.  
  21. "<div id='jefree' style=' float: center; text-align: center;' >" +
  22. "<div style=' float: left; display: inline-block; text-align: center;'> <select id='divisionid' >" +
  23. "<option value='1'>Division 1</option>" +
  24. "<option value='2'>Division 2</option>" +
  25. "<option value='3'>Division 3</option>" +
  26. "<option value='4'>Division 4</option>" +
  27. "<option value='5'>Division 5</option>" +
  28. "<option value='6'>Division 6</option>" +
  29. "<option value='7'>Division 7</option>" +
  30. "</select> </div>" +
  31.  
  32. "<div style=' display: inline-block; float: left; text-align: center; padding-left:5em;'><button id='searchLeague'>Search Leagues</button></div>" +
  33. '<div style=" display: inline-block; float: right; padding-right:15em; " >'+
  34. '<input type="button" id="subscription" name=" " value="Unfollow All" class="btn btn-default btn-sm pull-right" "></div><br><br>'+
  35. "<div class='loader' style='display: none;text-align:center;' align='center'><img src='/images/ajax-loader.gif'></div>" + "<br><br>" +
  36. "<br><div id='leagueInfo' style='font-size:18px; color:orange; ; '> </div>" + "</div><br><br>");
  37.  
  38. var divisions = ["I","II","III","IV","V","VI","VII"];
  39. var division;
  40. var totalLeagues;
  41. var arr=[];
  42.  
  43. $('#subscription').hide();
  44.  
  45. function caldiv(division)
  46. {
  47. var i,a=0;
  48. for (i=2; i < division+1 ; i++)
  49. {
  50. a=a+ Math.pow(4, division-i);
  51. }
  52. if (division == 1)
  53. return 0;
  54. else
  55. return a-(1/3);
  56. }
  57.  
  58. function startSearch() {
  59. $('#searchLeague').attr('disabled','disabled');
  60. var currentLeague = 1;
  61. $("div#leagueInfo").html("");
  62. division = $("#divisionid").val();
  63. totalLeagues = Math.pow(4,division-1);
  64. console.debug($("#divisionid").val());
  65. searchLeague(currentLeague);
  66. }
  67. function searchLeague(currentLeague) {
  68. console.debug("inside searchLeague");
  69. $(".loader").show();
  70. var url = "http://hitwicket.com/league/show/" ;
  71. var currentLeagueName = divisions[division-1] + "-" + currentLeague;
  72. var leagueUrl = url + currentLeagueName;
  73. console.debug("before request");
  74. $.ajax({
  75. url: leagueUrl,
  76. cache: false,
  77. beforeSend: function( xhr ) {
  78. $(".loader").show();
  79. }
  80. })
  81. .done(function( html ) {
  82. console.debug(currentLeagueName + ":" + $(html).find("#subscription").val());
  83. var val = $(html).find("#subscription").val();
  84. //var val= $("#subscription").val();
  85. //window.alert(val);
  86. var appd = " and unfollow" ;
  87. var disp = "<a href='" + leagueUrl + "'>Visit " + currentLeagueName + " </a> " + appd + "<br>" ;
  88. if(val == "Unfollow" ) {
  89. $('#subscription').show();
  90. var ax=caldiv(division);
  91. //alert(ax);
  92. var abc = ax + currentLeague;
  93. if ( $.inArray( abc, arr) == -1 ) {
  94. arr.push(abc); }
  95. var ele = "<div >" + disp + "</div>";
  96. $("div#leagueInfo").append(ele );
  97. //$('#subscription').attr('name', abc );
  98. }
  99.  
  100. currentLeague++;
  101. if(currentLeague > totalLeagues) {
  102. $(".loader").hide();
  103. $('#searchLeague').removeAttr('disabled');
  104. return;
  105. }
  106. else {
  107. searchLeague(currentLeague);
  108. }
  109. });
  110. }
  111.  
  112. $(document).on('click', '#searchLeague', function(){
  113. startSearch();
  114. }
  115. );
  116.  
  117. $('#subscription').live('click',function(){
  118. //var xyz=$('#subscription').attr('name');
  119. var bs=confirm("Are you sure to Unfollow All leagues in this division?");
  120. //alert(arr.length);
  121. if (bs === true ) {
  122. var i;
  123. for(i=0; i < arr.length ; i++)
  124. {
  125. //alert(arr[i]);
  126. $.ajax({
  127. 'type':'post',
  128. 'url':"/league/changeSubscription?league_id="+arr[i] ,
  129. 'cache':false,
  130. 'success':function(data){
  131. var label = $('#subscription').attr('value');
  132. if(label == 'Unfollow')
  133. $('#subscription').attr('value','Follow');
  134. }
  135. });
  136. }
  137. $('#subscription').hide();
  138. alert("Successfully Unfollowed All leagues!");
  139. return false;
  140. }
  141. });