Swagbucks App Completion

A script to add a new tab to the users acount page to show how much you have progressed for each swagbuck app.

目前为 2014-09-09 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Swagbucks App Completion
  3. // @namespace https://github.com/Omegaice/SwagBucksAppMonitor
  4. // @version 1.3
  5. // @description A script to add a new tab to the users acount page to show how much you have progressed for each swagbuck app.
  6. // @match http://www.swagbucks.com/account/summary
  7. // @copyright 2014+, Omegaice
  8. // ==/UserScript==
  9.  
  10. // App Maximums
  11. var sbtvpc_max = 150;
  12. var sbtv_max = 36;
  13. var indymusic_max = 80;
  14. var sportly_max = 80;
  15. var movieclips_max = 80;
  16. var entertainow_max = 90;
  17.  
  18. function CreateAppRows(name, current, maximum, reward, video_duration, videos_per_reward) {
  19. var result = "<p>"+ name + ":</br>";
  20. if( current >= maximum ){
  21. result += "&nbsp&nbsp&nbsp&nbspComplete [" + current + "/" + maximum + "]";
  22. }else{
  23. result += "&nbsp&nbsp&nbsp&nbspIncomplete [" + current + "/" + maximum + "]";
  24. }
  25. result += "</br>&nbsp&nbsp&nbsp&nbspVideos Remaining: " + videos_per_reward * (Math.max(maximum-current, 0)/reward);
  26. if( video_duration > 0) result += "</br>&nbsp&nbsp&nbsp&nbspEstimated Time Remaining: " + CalculateDuration(video_duration, current, maximum, videos_per_reward, reward);
  27. return result + "</p>";
  28. }
  29.  
  30. // Time Variables
  31. var advert_time = 30;
  32. var nextup_time = 10;
  33. var video_load_time = 5;
  34.  
  35. function CalculateDuration(minimum_time, current_points, maximum_points, videos_per_reward, reward_value){
  36. var remaining_points = Math.max(maximum_points - current_points, 0);
  37. var remaining_videos = remaining_points * (videos_per_reward / reward_value);
  38. var remaining_adverts = Math.floor(remaining_points / reward_value);
  39.  
  40. var time = remaining_videos * (video_load_time + minimum_time + nextup_time) + remaining_adverts * advert_time;
  41.  
  42. var hours = Math.floor(time / 3600) % 24;
  43. var minutes = Math.floor(time / 60) % 60;
  44. var seconds = time % 60;
  45.  
  46. return (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
  47. }
  48.  
  49. $("#ledgerInnerCont").append('<div id="appContent" style="position: relative; display: none;"></div>');
  50.  
  51. $.get("http://www.swagbucks.com/?cmd=sb-acct-ledger&allTime=false",function(data,status){
  52. var values = data.split("|")[2].substr(1);
  53. values = values.substring(0, values.length - 1);
  54.  
  55. var rewards = new Array();
  56. rewards["SBTV"] = 0;
  57. rewards["SBTVPC"] = 0;
  58. rewards["Sportly"] = 0;
  59. rewards["Indymusic"] = 0;
  60. rewards["EntertaiNow"] = 0;
  61. rewards["MovieCli.ps"] = 0;
  62.  
  63. var lines = values.split("],");
  64. for( var i = 0; i < lines.length; i++ ){
  65. var lData = lines[i].replace("[", "").replace("]", "").split(",");
  66.  
  67. var desc = lData[5].replace("'", "").replace("'", "").trim();
  68. var value = parseInt(lData[3]);
  69.  
  70. if( desc == "" ) desc = ( value == 2 ? "SBTV" : "SBTVPC" )
  71.  
  72. if( rewards[desc] == null ){
  73. rewards[desc] = value;
  74. }else{
  75. rewards[desc] = rewards[desc] + parseInt(lData[3]);
  76. }
  77. }
  78.  
  79. $("#appContent").append(CreateAppRows("SBTV - PC", rewards["SBTVPC"], sbtvpc_max, 3, 0, 10) + "</br>");
  80. $("#appContent").append(CreateAppRows("SBTV - Mobile", rewards["SBTV"], sbtv_max, 2, 9, 5) + "</br>");
  81. $("#appContent").append(CreateAppRows("Indymusic.tv", rewards["Indymusic"], indymusic_max, 2, 30, 15) + "</br>");
  82. $("#appContent").append(CreateAppRows("Sportly.tv", rewards["Sportly"], sportly_max, 2, 25, 15) + "</br>");
  83. $("#appContent").append(CreateAppRows("EntertaiNow", rewards["EntertaiNow"], entertainow_max, 2, 11, 15) + "</br>");
  84. $("#appContent").append(CreateAppRows("MovieCli.ps", rewards["MovieCli.ps"], movieclips_max, 2, 23, 15) + "</br>");
  85. });
  86.  
  87. $("#accountTab1").parent().append("<li id=\"accountTab2\">Applications</li>");
  88.  
  89. $("#accountTab2").click(function(){
  90. $("#accountTab1").removeClass("selected");
  91. $("#ledgerContL").css({position: "relative", display: "none"});
  92.  
  93. $("#accountTab2").addClass("selected");
  94. $("#appContent").removeAttr( 'style' );
  95.  
  96. $("#accountTab3").removeClass("selected");
  97. $("#collectorBills").css({position: "relative", display: "none"});
  98. })
  99.  
  100. // Helpers for old tabs
  101. $("#accountTab1").click(function(){
  102. $("#accountTab2").removeClass("selected");
  103. $("#appContent").css({position: "relative", display: "none"});
  104. })
  105. $("#accountTab3").click(function(){
  106. $("#accountTab2").removeClass("selected");
  107. $("#appContent").css({position: "relative", display: "none"});
  108. })