SwagTv script+mod

this script will automatically fetch and go to the next video after the meter goes up. [mod: next category when end, solve another captcha, restore last video, fix some bug from duplicate watch, speed up for next video after meter increase, checking new server date

当前为 2015-01-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name SwagTv script+mod
  3. // @namespace swagtv+mod
  4. // @description this script will automatically fetch and go to the next video after the meter goes up. [mod: next category when end, solve another captcha, restore last video, fix some bug from duplicate watch, speed up for next video after meter increase, checking new server date
  5. // @version 0.02
  6. // @include http://video.swagbucks.com/*
  7. // @include http://www.swagbucks.com/?cmd=cp-get-captcha-image*
  8. // @require https://greasyfork.org/scripts/1706-gocr-library/code/GOCR%20Library.js?version=4235
  9. // @grant none
  10. // ==/UserScript==
  11. // Original from https://greasyfork.org/en/scripts/1126-swagtv-script
  12. // --------------------------------------------------------------------
  13.  
  14.  
  15. var channel = [];
  16. channel[1] = "http://video.swagbucks.com/channel/the-voice/133";
  17. channel[2] = "http://video.swagbucks.com/channel/hitfix/54";
  18. channel[3] = "http://video.swagbucks.com/channel/hollyscoop/56";
  19. channel[4] = "http://video.swagbucks.com/channel/fanlala/57";
  20. channel[5] = "http://video.swagbucks.com/channel/the-tonight-show/135";
  21. channel[6] = "http://video.swagbucks.com/channel/techradar/137";
  22. channel[7] = "http://video.swagbucks.com/channel/mashable-reviews/139";
  23. channel[8] = "http://video.swagbucks.com/channel/reuters-news/98";
  24. channel[9] = "http://video.swagbucks.com/channel/bbc-worldwide/95";
  25. channel[10] = "http://video.swagbucks.com/channel/bbq/72";
  26. channel[11] = "http://video.swagbucks.com/channel/italian/74";
  27.  
  28. var now = new Date();
  29. // I'm +7 UTC, use -15 : set yours
  30. now.setHours(now.getHours()-15);
  31. var nowutc = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
  32.  
  33. if (window.opener != null && window.location.href.indexOf("mumbojumbo") > -1) {
  34. console.log("in");
  35. console.log(window.opener);
  36. window.opener.postMessage("Child Frame Loaded", "*");
  37. var pic = document.getElementsByTagName("img")[0];
  38. var image = getBase64Image(pic);
  39. var ocrString = GOCR(image);
  40. console.log(ocrString.toUpperCase());
  41. window.opener.postMessage({magicword: "mumbojumbo", string: ocrString}, "*");
  42. }else if(window.location.href.indexOf("video.swagbucks.com/channel") > -1){
  43. if(getCookie("videodate") < nowutc){
  44. console.log("new date");
  45. setCookie("videodate",nowutc ,365, "/");
  46. setCookie("videoindex",1 ,365, "/");
  47. document.location.href = channel[1];
  48. }else{
  49. // select first video
  50. console.log("select first video");
  51. document.location.href = $(".thumb-link").first().attr('href');
  52. }
  53. }else if(window.location.href == "http://video.swagbucks.com/"){
  54. // start running here
  55. getCookie("videodate") ? "" : setCookie("videodate",nowutc ,365, "/")
  56. getCookie("videoindex") ? "" : setCookie("videoindex",1 ,365, "/")
  57. if(getCookie("videodate") < nowutc){
  58. // new day start new
  59. console.log("new date");
  60. setCookie("videodate",nowutc ,365, "/");
  61. setCookie("videoindex",1 ,365, "/");
  62. document.location.href = channel[1];
  63. }else{
  64. //resume last video
  65. document.location.href = getCookie("videolast");
  66. }
  67. }else{
  68. if(window.location.href.indexOf("http://video.swagbucks.com/video") > -1){
  69. setCookie("videolast",document.location.href ,365, "/");
  70. }
  71. var iLoops = 0;
  72. var randomNum = 0;
  73. var strPercentStart = null;
  74. var strPercentStart2 = null;
  75. var temp123 = null;
  76. var link = null;
  77. var div = null;
  78. var doc = document.getElementById("feed-ajax-div");
  79. var notes = false;
  80. var dup = false;
  81. var _class = document.getElementsByClassName("thumb-container");
  82. window.setInterval(reloadTimer,1000);
  83. /*for (var i = 0; i < _class.length; i++) {
  84. if (_class[i].className == "thumb-container active") {
  85. var k = i;
  86. break;
  87. }
  88.  
  89. } */
  90. var k = getK();
  91. var video = document.getElementById("video-title");
  92. video.parentNode.removeChild(video);
  93. var comment = document.getElementById("commentsCont");
  94. comment.parentNode.removeChild(comment);
  95. var footer = document.getElementById("sbFooterWrap");
  96. footer.parentNode.removeChild(footer);
  97. var helpTab = document.getElementById("helpTab");
  98. helpTab.parentNode.removeChild(helpTab);
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105. function getK(){
  106. for (var i = 0; i < _class.length; i++) {
  107. if (_class[i].className == "thumb-container active") {
  108. var k = i;
  109. break;
  110. }
  111. }
  112. return k
  113. }
  114.  
  115. function reloadTimer(){
  116. iLoops++;
  117. if (iLoops == 1) {
  118. strPercentStart = document.getElementById("meterNumber").innerHTML;
  119. strPercentStart2 = document.getElementById("meterNumber").innerHTML;
  120. temp123 = getCookie("videoindex");
  121. }else{
  122. strPercentStart2 = document.getElementById("meterNumber").innerHTML;
  123. }
  124. document.title = iLoops+":"+strPercentStart+":"+strPercentStart2+":"+temp123;
  125. if (iLoops%5==0){
  126. console.log(iLoops);
  127. }
  128. if (iLoops == 5) {
  129. div = document.getElementById("meterDuplicateVideo");
  130. if (div.style.display == 'none') { // not dup
  131. randomNum = Math.floor(Math.random()*15 + 50);
  132. }else { // dup
  133. dup = true;
  134. if (k == null) {
  135. console.log("In K=3");
  136. //var clickEvent = document.createEvent('MouseEvents');
  137. //clickEvent.initEvent('click', true, true);
  138. //document.getElementsByClassName("feed-ajax-next")[0].dispatchEvent(clickEvent);
  139. if (!document.getElementsByClassName("feed-ajax-next")[0])
  140. notes = true;
  141. else
  142. document.getElementsByClassName("feed-ajax-next")[0].click();
  143. k = -1;
  144. }else{
  145. randomNum = 8;
  146. }
  147. }
  148. if (k == null) {
  149. console.log("In K=3");
  150. if (!document.getElementsByClassName("feed-ajax-next")[0])
  151. notes = true;
  152. else
  153. document.getElementsByClassName("feed-ajax-next")[0].click();
  154. k = -1;
  155. }
  156. };
  157. if(strPercentStart != strPercentStart2){
  158. if(strPercentStart2 != "99%"){
  159. iLoops = randomNum;
  160. }
  161. }
  162. if (iLoops == randomNum){
  163. if (document.getElementById("sbvd_capText")) {
  164. pic = document.getElementById("sbvdcapimg");
  165. pic.crossOrigin = 'anonymous';
  166. var string = getCaptchaText(pic);
  167. }
  168. else {
  169. if (notes){
  170. console.log("Pick a new category");
  171. var videoindex = getCookie("videoindex");
  172. var c = (isNaN(videoindex) ? 0 : +videoindex);
  173. videoindex = c + 1;
  174. setCookie("videoindex",videoindex ,365, "/");
  175. console.log(videoindex);
  176. if(videoindex<12){
  177. document.location.href = channel[videoindex];
  178. //console.log(channel[videoindex]);
  179. }else{
  180. console.log("STOP");
  181. }
  182. }else{
  183. link = document.getElementsByClassName("thumb-link")[k+1].href;
  184. window.location.href = link;
  185. }
  186. }
  187. }
  188. if(iLoops > 100){
  189. window.location.href = document.getElementsByClassName("thumb-link")[0].href;
  190. }
  191. };
  192. var childWindow = null;
  193.  
  194. if (window.opener != null && window.location.href.indexOf("mumbojumbo") > -1) {
  195. console.log("in");
  196. window.opener.postMessage("Child Frame Loaded", "*");
  197. var pic = document.getElementsByTagName("img")[0];
  198. console.log(pic);
  199. ocrString = ""
  200. if (pic){
  201. setTimeout(function(){
  202. var image = getBase64Image(pic);
  203. console.log(image);
  204. var imageData = image[0];
  205. var ocrString = GOCR(imageData);
  206. console.log(ocrString.toUpperCase());
  207. },1000);
  208. }
  209. window.opener.postMessage({magicword: "mumbojumbo", string: ocrString}, "*");
  210. window.opener=window;
  211. window.close();
  212. top.window.close();
  213. }
  214.  
  215. window.addEventListener("message", function(e) {
  216. if (e.data.magicword === "mumbojumbo") {
  217. console.log("Message Received");
  218. console.log(e.data);
  219. var ocrString = e.data.string.toUpperCase();
  220. console.log("string");
  221. console.log(ocrString);
  222. console.log("string");
  223. if (childWindow)
  224. childWindow.close();
  225. if (ocrString.indexOf('_') === -1){
  226. if (document.getElementById("sbvd_capText")){
  227. document.getElementById("sbvd_capText").value = ocrString;
  228. document.getElementsByClassName("btnClaim")[0].click();
  229. setTimeout(function() {
  230. if (!document.getElementById("sbvd_capText")){
  231. k=getK();
  232. if (k == null)
  233. k=-1;
  234. link = document.getElementsByClassName("thumb-link")[k+1].href;
  235. //alert("NEXT");
  236. window.location.href = link;
  237. }
  238. else{
  239. //alert("Opened 1");
  240. var pic = document.getElementById("sbvdcapimg");
  241. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  242. }
  243. }, 1000);
  244. }
  245. }
  246. else{
  247. //alert("Opened 2");
  248. var pic = document.getElementById("sbvdcapimg");
  249. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  250. }
  251. }
  252. else{
  253. //console.log("Also message received");
  254. //console.log(e.data);
  255. }
  256. }, false);
  257.  
  258. function getCaptchaText(pic){
  259. var pic = document.getElementById("sbvdcapimg");
  260. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  261. }
  262.  
  263. function getBase64Image(img) {
  264. /* // Create an empty canvas element
  265. var pic = document.createElement("img");
  266. pic.src = img;
  267. var canvas = document.createElement("canvas");
  268. canvas.width = img.width;
  269. canvas.height = img.height;
  270.  
  271. // Copy the image contents to the canvas
  272. var ctx = canvas.getContext("2d");
  273. ctx.drawImage(pic, 0, 0);
  274. var pic2 = document.createElement("img");
  275. pic2.src=canvas.toDataURL("image/png");
  276. console.log(canvas.toDataURL("image/png"));
  277. ctx.drawImage(pic2,0,0);
  278.  
  279. // Get the data-URL formatted image
  280. // Firefox supports PNG and JPEG. You could check img.src to
  281. // guess the original format, but be aware the using "image/jpg"
  282. // will re-encode the image.
  283. var dataURL = ctx.getImageData(0,0,canvas.width,canvas.height);
  284.  
  285. return dataURL;//.replace(/^data:image\/(png|jpg);base64,/, "");*/
  286. // Create an empty canvas element
  287. var canvas = document.createElement("canvas");
  288. canvas.width = img.width;
  289. canvas.height = img.height;
  290. // Copy the image contents to the canvas
  291. var ctx = canvas.getContext("2d");
  292. ctx.drawImage(img, 0, 0);
  293. // Get the data-URL formatted image
  294. // Firefox supports PNG and JPEG. You could check img.src to
  295. // guess the original format, but be aware the using "image/jpg"
  296. // will re-encode the image.
  297. var dataURL = ctx.getImageData(0,0,canvas.width,canvas.height);
  298. return dataURL;//.replace(/^data:image\/(png|jpg);base64,/, "");
  299. }
  300.  
  301. function getCookie(c_name)
  302. {
  303. var i,x,y,ARRcookies=document.cookie.split(";");
  304. for (i=0;i<ARRcookies.length;i++)
  305. {
  306. x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  307. y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  308. x=x.replace(/^\s+|\s+$/g,"");
  309. if (x==c_name)
  310. {
  311. return unescape(y);
  312. }
  313. }
  314. }
  315.  
  316. function setCookie( name, value, expires, path )
  317. {
  318. // set time, it's in milliseconds
  319. var today = new Date();
  320. today.setTime( today.getTime() );
  321. /*
  322. if the expires variable is set, make the correct
  323. expires time, the current script below will set
  324. it for x number of days, to make it for hours,
  325. delete * 24, for minutes, delete * 60 * 24
  326. */
  327. if ( expires )
  328. {
  329. expires = expires * 1000 * 60 * 60 * 24;
  330. }
  331. var expires_date = new Date( today.getTime() + (expires) );
  332. document.cookie = name + "=" +escape( value ) +
  333. ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
  334. ( ( path ) ? ";path=" + path : "" );
  335. }