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-16 提交的版本,查看 最新版本

  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.08
  6. // @include http://video.swagbucks.com/*
  7. // @include http://www.swagbucks.com/?cmd=cp-get-captcha-image*
  8. // @exclude http://video.swagbucks.com/ad*
  9. // @require https://greasyfork.org/scripts/1706-gocr-library/code/GOCR%20Library.js?version=4235
  10. // @grant none
  11. // ==/UserScript==
  12. // Original from https://greasyfork.org/en/scripts/1126-swagtv-script
  13. // --------------------------------------------------------------------
  14.  
  15. var channel = [];
  16. channel[1] = "http://video.swagbucks.com/channel/comedy-time/58";
  17. channel[2] = "http://video.swagbucks.com/channel/web-originals/184";
  18. channel[3] = "http://video.swagbucks.com/channel/movie-trailers/51";
  19. channel[4] = "http://video.swagbucks.com/channel/moviefone/53";
  20. channel[5] = "http://video.swagbucks.com/channel/hitfix/54";
  21. channel[6] = "http://video.swagbucks.com/channel/hollyscoop/56";
  22. channel[7] = "http://video.swagbucks.com/channel/fanlala/57";
  23. channel[8] = "http://video.swagbucks.com/channel/the-tonight-show/135";
  24. channel[9] = "http://video.swagbucks.com/channel/the-voice/133";
  25. channel[10] = "http://video.swagbucks.com/channel/modamob/78";
  26. channel[11] = "http://video.swagbucks.com/channel/style-etc/79";
  27. channel[12] = "http://video.swagbucks.com/channel/chic-tv-fashion/80";
  28. channel[13] = "http://video.swagbucks.com/channel/chic-tv-beauty/81";
  29. channel[14] = "http://video.swagbucks.com/channel/cambio-style/83";
  30. channel[15] = "http://video.swagbucks.com/channel/aerosmith/61";
  31. channel[16] = "http://video.swagbucks.com/channel/adele/62";
  32. channel[17] = "http://video.swagbucks.com/channel/madonna/65";
  33. channel[18] = "http://video.swagbucks.com/channel/the-rolling-stones/67";
  34. channel[19] = "http://video.swagbucks.com/channel/whitney-houston/68";
  35. channel[20] = "http://video.swagbucks.com/channel/empowher/86";
  36. channel[21] = "http://video.swagbucks.com/channel/the-goto-mom/88";
  37. channel[22] = "http://video.swagbucks.com/channel/insider-medicine/89";
  38. channel[23] = "http://video.swagbucks.com/channel/ivanhoe/90";
  39. channel[24] = "http://video.swagbucks.com/channel/bbq/72";
  40. channel[25] = "http://video.swagbucks.com/channel/italian/74";
  41. channel[26] = "http://video.swagbucks.com/channel/healthy-recipes/75";
  42. channel[27] = "http://video.swagbucks.com/channel/vegan/76";
  43. channel[28] = "http://video.swagbucks.com/channel/soups/120";
  44. channel[29] = "http://video.swagbucks.com/channel/drinks/121";
  45. channel[30] = "http://video.swagbucks.com/channel/salads/122";
  46. channel[31] = "http://video.swagbucks.com/channel/latin/123";
  47. channel[32] = "http://video.swagbucks.com/channel/desserts/124";
  48. channel[33] = "http://video.swagbucks.com/channel/newsy/173";
  49. channel[34] = "http://video.swagbucks.com/channel/ny-daily-news/93";
  50. channel[35] = "http://video.swagbucks.com/channel/wsjlive/94";
  51. channel[36] = "http://video.swagbucks.com/channel/bbc-worldwide/95";
  52. channel[37] = "http://video.swagbucks.com/channel/global-post/96";
  53. channel[38] = "http://video.swagbucks.com/channel/reuters-news/98";
  54. channel[39] = "http://video.swagbucks.com/channel/ny-financial-press/99";
  55. channel[40] = "http://video.swagbucks.com/channel/ktla/183";
  56. channel[41] = "http://video.swagbucks.com/channel/dad-labs/101";
  57. channel[42] = "http://video.swagbucks.com/channel/better-tv/102";
  58. channel[43] = "http://video.swagbucks.com/channel/ask-the-builder/103";
  59. channel[44] = "http://video.swagbucks.com/channel/geobeats/104";
  60. channel[45] = "http://video.swagbucks.com/channel/monkeysee-home/105";
  61. channel[46] = "http://video.swagbucks.com/channel/KVIE/107";
  62. channel[47] = "http://video.swagbucks.com/channel/soma-tv/108";
  63. channel[48] = "http://video.swagbucks.com/channel/earth-report/109";
  64. channel[49] = "http://video.swagbucks.com/channel/vetvid/111";
  65. channel[50] = "http://video.swagbucks.com/channel/trailer-life-tv/112";
  66. channel[51] = "http://video.swagbucks.com/channel/Uzoo/147";
  67. channel[52] = "http://video.swagbucks.com/channel/mashable-reviews/139";
  68. channel[53] = "http://video.swagbucks.com/channel/hdnation/140";
  69. channel[54] = "http://video.swagbucks.com/channel/get-connected-media/141";
  70. channel[55] = "http://video.swagbucks.com/channel/butterscotch/143";
  71. channel[56] = "http://video.swagbucks.com/channel/appvee/144";
  72. channel[57] = "http://video.swagbucks.com/channel/top-ten-reviews/145";
  73. channel[58] = "http://video.swagbucks.com/channel/techradar/137";
  74. channel[59] = "http://video.swagbucks.com/channel/get-to-know-team-swagbucks/115";
  75. channel[60] = "http://video.swagbucks.com/channel/all-about-swagbucks/117";
  76. channel[61] = "http://video.swagbucks.com/channel/man-on-the-street/118";
  77. channel[62] = "http://video.swagbucks.com/channel/office-wars/119";
  78. var now = new Date();
  79. // I'm +7 UTC, use -15 : set yours
  80. now.setHours(now.getHours()-15);
  81. var nowutc = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
  82.  
  83. if (window.opener != null && window.location.href.indexOf("mumbojumbo") > -1) {
  84. console.log("in");
  85. console.log(window.opener);
  86. window.opener.postMessage("Child Frame Loaded", "*");
  87. var pic = document.getElementsByTagName("img")[0];
  88. var image = getBase64Image(pic);
  89. var ocrString = GOCR(image);
  90. ocrString = ocrString.replace(/\s+/g, '');
  91. console.log(ocrString.toUpperCase());
  92. window.opener.postMessage({magicword: "mumbojumbo", string: ocrString}, "*");
  93. window.setInterval(window.close,1000);
  94. }else if(window.location.href.indexOf("video.swagbucks.com/channel") > -1){
  95. if(getCookie("videodate") < nowutc){
  96. console.log("new date");
  97. setCookie("videodate",nowutc ,365, "/");
  98. setCookie("videoindex",1 ,365, "/");
  99. document.location.href = channel[1];
  100. }else{
  101. // select first video
  102. console.log("select first video");
  103. document.location.href = $(".thumb-link").first().attr('href');
  104. }
  105. }else if(window.location.href == "http://video.swagbucks.com/"){
  106. // start running here
  107. getCookie("videodate") ? "" : setCookie("videodate",nowutc ,365, "/")
  108. getCookie("videoindex") ? "" : setCookie("videoindex",1 ,365, "/")
  109. if(getCookie("videodate") < nowutc){
  110. // new day start new
  111. console.log("new date");
  112. setCookie("videodate",nowutc ,365, "/");
  113. setCookie("videoindex",1 ,365, "/");
  114. document.location.href = channel[1];
  115. }else{
  116. //resume last video
  117. document.location.href = getCookie("videolast");
  118. }
  119. }else if(window.location.href.indexOf("www.swagbucks.com") > -1){
  120. }else{
  121. if(window.location.href.indexOf("http://video.swagbucks.com/video") > -1){
  122. setCookie("videolast",document.location.href ,365, "/");
  123. }
  124. // if found editor pick : new cat
  125. // document.getElementById("tout").getElementsByTagName("h2")[0].innerHTML
  126. // NEED MORE CODE XXX
  127. var iLoops = 0;
  128. var randomNum = 0;
  129. var strPercentStart = null;
  130. var strPercentStart2 = null;
  131. var temp123 = null;
  132. var link = null;
  133. var div = null;
  134. var doc = document.getElementById("feed-ajax-div");
  135. var notes = false;
  136. var dup = false;
  137. var _class = document.getElementsByClassName("thumb-container");
  138. window.setInterval(reloadTimer,2000);
  139. /*for (var i = 0; i < _class.length; i++) {
  140. if (_class[i].className == "thumb-container active") {
  141. var k = i;
  142. break;
  143. }
  144.  
  145. } */
  146. var k = getK();
  147. $('#item_title').parent().append("<input class='newCategory' type='button' id='newcat' value='New Category'>").bind('click', function() {
  148. selectNewCat();
  149. });/**/
  150. }
  151.  
  152. function getK(){
  153. for (var i = 0; i < _class.length; i++) {
  154. if (_class[i].className == "thumb-container active") {
  155. var k = i;
  156. break;
  157. }
  158. }
  159. return k
  160. }
  161.  
  162. function reloadTimer(){
  163. iLoops++;
  164. if (iLoops == 1 || iLoops == 10) {
  165. if(document.getElementById("meterNumber")!= undefined){
  166. strPercentStart = document.getElementById("meterNumber").innerHTML;
  167. strPercentStart2 = document.getElementById("meterNumber").innerHTML;
  168. }
  169. temp123 = getCookie("videoindex");
  170. setCookie("videoindex",+temp123 ,365, "/");
  171. safeBW();
  172. }else{
  173. if(document.getElementById("meterNumber")!= undefined){
  174. strPercentStart2 = document.getElementById("meterNumber").innerHTML;
  175. }
  176. }
  177. if (iLoops%5==0){
  178. if(strPercentStart != strPercentStart2){
  179. if(strPercentStart2 != "99%"){
  180. iLoops = randomNum;
  181. }
  182. }
  183. document.title = iLoops+":"+strPercentStart+":"+strPercentStart2+":"+temp123;
  184. if(document.getElementById("sbvd_capText") && iLoops+10 < randomNum){
  185. iLoops = randomNum-5
  186. }
  187. checkLimit();
  188. }
  189. if (iLoops == 5) {
  190. div = document.getElementById("meterDuplicateVideo");
  191. if (div.style.display == 'none') { // not dup
  192. randomNum = Math.floor(Math.random()*15 + 50);
  193. }else { // dup
  194. dup = true;
  195. if (k == null) {
  196. console.log("In K=3");
  197. //var clickEvent = document.createEvent('MouseEvents');
  198. //clickEvent.initEvent('click', true, true);
  199. //document.getElementsByClassName("feed-ajax-next")[0].dispatchEvent(clickEvent);
  200. if (!document.getElementsByClassName("feed-ajax-next")[0]){
  201. notes = true;
  202. }else{
  203. document.getElementsByClassName("feed-ajax-next")[0].click();
  204. randomNum = 13;
  205. }
  206. k = -1;
  207. }else{
  208. randomNum = 8;
  209. }
  210. }
  211. if (k == null) {
  212. console.log("In K=3");
  213. if (!document.getElementsByClassName("feed-ajax-next")[0]){
  214. notes = true;
  215. }else{
  216. document.getElementsByClassName("feed-ajax-next")[0].click();
  217. }
  218. k = -1;
  219. }
  220. if(notes && dup){
  221. selectNewCat();
  222. }
  223. };
  224. if (iLoops == randomNum){
  225. if (document.getElementById("sbvd_capText")) {
  226. pic = document.getElementById("sbvdcapimg");
  227. pic.crossOrigin = 'anonymous';
  228. var string = getCaptchaText(pic);
  229. }
  230. else {
  231. if (notes){
  232. selectNewCat();
  233. }else{
  234. link = document.getElementsByClassName("thumb-link")[k+1].href;
  235. window.location.href = link;
  236. }
  237. }
  238. }
  239. if(iLoops > 120){
  240. window.location.href = document.getElementsByClassName("thumb-link")[0].href;
  241. }
  242. };
  243.  
  244. var childWindow = null;
  245.  
  246. if (window.opener != null && window.location.href.indexOf("mumbojumbo") > -1) {
  247. console.log("in");
  248. window.opener.postMessage("Child Frame Loaded", "*");
  249. var pic = document.getElementsByTagName("img")[0];
  250. console.log(pic);
  251. ocrString = ""
  252. if (pic){
  253. setTimeout(function(){
  254. var image = getBase64Image(pic);
  255. console.log(image);
  256. var imageData = image[0];
  257. var ocrString = GOCR(imageData);meout
  258. ocrString = ocrString.replace(/\s+/g, '');
  259. console.log(ocrString.toUpperCase());
  260. },1500);
  261. }
  262. window.opener.postMessage({magicword: "mumbojumbo", string: ocrString}, "*");
  263. window.opener=window;
  264. window.close();
  265. top.window.close();
  266. window.setInterval(window.close,1000);
  267. }
  268.  
  269. window.addEventListener("message", function(e) {
  270. if (e.data.magicword === "mumbojumbo") {
  271. console.log("Message Received");
  272. console.log(e.data);
  273. var ocrString = e.data.string.toUpperCase();
  274. console.log("string");
  275. console.log(ocrString);
  276. console.log("string");
  277. if (childWindow)
  278. childWindow.close();
  279. if (ocrString.indexOf('_') === -1){
  280. if (document.getElementById("sbvd_capText")){
  281. document.getElementById("sbvd_capText").value = ocrString;
  282. document.getElementsByClassName("btnClaim")[0].click();
  283. setTimeout(function() {
  284. if (!document.getElementById("sbvd_capText")){
  285. k=getK();
  286. if (k == null)
  287. k=-1;
  288. link = document.getElementsByClassName("thumb-link")[k+1].href;
  289. //alert("NEXT");
  290. window.location.href = link;
  291. }
  292. else{
  293. //alert("Opened 1");
  294. var pic = document.getElementById("sbvdcapimg");
  295. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  296. }
  297. }, 1000);
  298. }
  299. }
  300. else{
  301. //alert("Opened 2");
  302. var pic = document.getElementById("sbvdcapimg");
  303. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  304. }
  305. }
  306. else{
  307. //console.log("Also message received");
  308. //console.log(e.data);
  309. }
  310. }, false);
  311.  
  312. function checkLimit(){
  313. var limited = document.getElementById("meterOverlimit");
  314. if(limited.style.display == '') { // reach limited
  315. document.title = document.title+" REACHED LIMIT";
  316. document.location.href = "http://www.swagbuck.com/";
  317. }
  318. }
  319.  
  320. function selectNewCat(){
  321. console.log("Pick a new category");
  322. var videoindex = getCookie("videoindex");
  323. var c = (isNaN(videoindex) ? 0 : +videoindex);
  324. videoindex = c + 1;
  325. if(videoindex+1>channel.length){videoindex = 1}
  326. setCookie("videoindex",videoindex ,365, "/");
  327. setTimeout(function() {
  328. document.location.href = channel[videoindex];
  329. }, 1000);
  330. }
  331.  
  332. function safeBW(){
  333. if(document.getElementById("video-title")!= undefined){
  334. var video = document.getElementById("video-title");
  335. video.parentNode.removeChild(video);
  336. }
  337. if(document.getElementById("commentsCont")!= undefined){
  338. var comment = document.getElementById("commentsCont");
  339. comment.parentNode.removeChild(comment);
  340. }
  341. if(document.getElementById("sbFooterWrap")!= undefined){
  342. var footer = document.getElementById("sbFooterWrap");
  343. footer.parentNode.removeChild(footer);
  344. }
  345. if(document.getElementById("helpTab")!= undefined){
  346. var helpTab = document.getElementById("helpTab");
  347. helpTab.parentNode.removeChild(helpTab);
  348. }
  349. if(document.getElementById("adContBottom928")!= undefined){
  350. var bottomad = document.getElementById("adContBottom928");
  351. bottomad.parentNode.removeChild(bottomad);
  352. }
  353. }
  354.  
  355. function getCaptchaText(pic){
  356. var pic = document.getElementById("sbvdcapimg");
  357. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  358. }
  359.  
  360. function getBase64Image(img) {
  361. /* // Create an empty canvas element
  362. var pic = document.createElement("img");
  363. pic.src = img;
  364. var canvas = document.createElement("canvas");
  365. canvas.width = img.width;
  366. canvas.height = img.height;
  367.  
  368. // Copy the image contents to the canvas
  369. var ctx = canvas.getContext("2d");
  370. ctx.drawImage(pic, 0, 0);
  371. var pic2 = document.createElement("img");
  372. pic2.src=canvas.toDataURL("image/png");
  373. console.log(canvas.toDataURL("image/png"));
  374. ctx.drawImage(pic2,0,0);
  375.  
  376. // Get the data-URL formatted image
  377. // Firefox supports PNG and JPEG. You could check img.src to
  378. // guess the original format, but be aware the using "image/jpg"
  379. // will re-encode the image.
  380. var dataURL = ctx.getImageData(0,0,canvas.width,canvas.height);
  381.  
  382. return dataURL;//.replace(/^data:image\/(png|jpg);base64,/, "");*/
  383. // Create an empty canvas element
  384. var canvas = document.createElement("canvas");
  385. canvas.width = img.width;
  386. canvas.height = img.height;
  387. // Copy the image contents to the canvas
  388. var ctx = canvas.getContext("2d");
  389. ctx.drawImage(img, 0, 0);
  390. // Get the data-URL formatted image
  391. // Firefox supports PNG and JPEG. You could check img.src to
  392. // guess the original format, but be aware the using "image/jpg"
  393. // will re-encode the image.
  394. var dataURL = ctx.getImageData(0,0,canvas.width,canvas.height);
  395. return dataURL;//.replace(/^data:image\/(png|jpg);base64,/, "");
  396. }
  397.  
  398. function getCookie(c_name)
  399. {
  400. var i,x,y,ARRcookies=document.cookie.split(";");
  401. for (i=0;i<ARRcookies.length;i++)
  402. {
  403. x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  404. y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  405. x=x.replace(/^\s+|\s+$/g,"");
  406. if (x==c_name)
  407. {
  408. return unescape(y);
  409. }
  410. }
  411. }
  412.  
  413. function setCookie( name, value, expires, path )
  414. {
  415. // set time, it's in milliseconds
  416. var today = new Date();
  417. today.setTime( today.getTime() );
  418. /*
  419. if the expires variable is set, make the correct
  420. expires time, the current script below will set
  421. it for x number of days, to make it for hours,
  422. delete * 24, for minutes, delete * 60 * 24
  423. */
  424. if ( expires )
  425. {
  426. expires = expires * 1000 * 60 * 60 * 24;
  427. }
  428. var expires_date = new Date( today.getTime() + (expires) );
  429. document.cookie = name + "=" +escape( value ) +
  430. ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
  431. ( ( path ) ? ";path=" + path : "" );
  432. }
  433.  
  434.  
  435. function test(){
  436. var items = document.getElementsByClassName("subnav");
  437. var itemscount = items.length;
  438. for(var i=0;i<itemscount;i++){
  439. console.log(items[i]);
  440. }
  441. }