Greasy Fork 支持简体中文。

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

  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.10
  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. checkLimit();
  108. getCookie("videodate") ? "" : setCookie("videodate",nowutc ,365, "/")
  109. getCookie("videoindex") ? "" : setCookie("videoindex",1 ,365, "/")
  110. if(getCookie("videodate") < nowutc){
  111. // new day start new
  112. console.log("new date");
  113. setCookie("videodate",nowutc ,365, "/");
  114. setCookie("videoindex",1 ,365, "/");
  115. document.location.href = channel[1];
  116. }else{
  117. //resume last video
  118. document.location.href = getCookie("videolast");
  119. }
  120. }else if(window.location.href.indexOf("www.swagbucks.com") > -1){
  121. }else{
  122. if(window.location.href.indexOf("http://video.swagbucks.com/video") > -1){
  123. setCookie("videolast",document.location.href ,365, "/");
  124. }
  125. var iLoops = 0;
  126. var randomNum = 0;
  127. var strPercentStart = null;
  128. var strPercentStart2 = null;
  129. var temp123 = null;
  130. var link = null;
  131. var div = null;
  132. var doc = document.getElementById("feed-ajax-div");
  133. var notes = false;
  134. var dup = false;
  135. var _class = document.getElementsByClassName("thumb-container");
  136. window.setInterval(reloadTimer,2000);
  137. /*for (var i = 0; i < _class.length; i++) {
  138. if (_class[i].className == "thumb-container active") {
  139. var k = i;
  140. break;
  141. }
  142.  
  143. } */
  144. var k = getK();
  145. $('#item_title').parent().append("<input class='newCategory' type='button' id='newcat' value='New Category'>").bind('click', function() {
  146. selectNewCat();
  147. });/**/
  148. }
  149.  
  150. function getK(){
  151. for (var i = 0; i < _class.length; i++) {
  152. if (_class[i].className == "thumb-container active") {
  153. var k = i;
  154. break;
  155. }
  156. }
  157. return k
  158. }
  159.  
  160. function reloadTimer(){
  161. iLoops++;
  162. if (iLoops == 1 || iLoops == 10) {
  163. if(document.getElementById("meterNumber")!= undefined){
  164. strPercentStart = document.getElementById("meterNumber").innerHTML;
  165. strPercentStart2 = document.getElementById("meterNumber").innerHTML;
  166. }
  167. temp123 = getCookie("videoindex");
  168. setCookie("videoindex",+temp123 ,365, "/");
  169. safeBW();
  170. }else{
  171. if(document.getElementById("meterNumber")!= undefined){
  172. strPercentStart2 = document.getElementById("meterNumber").innerHTML;
  173. }
  174. }
  175. if (iLoops%5==0){
  176. if(strPercentStart != strPercentStart2){
  177. if(strPercentStart2 != "99%"){
  178. iLoops = randomNum;
  179. }
  180. }
  181. document.title = iLoops+":"+strPercentStart+":"+strPercentStart2+":"+temp123;
  182. if(document.getElementById("sbvd_capText") && iLoops+10 < randomNum){
  183. iLoops = randomNum-5
  184. }
  185. checkLimit();
  186. }
  187. if (iLoops == 5) {
  188. div = document.getElementById("meterDuplicateVideo");
  189. if (div.style.display == 'none') { // not dup
  190. randomNum = Math.floor(Math.random()*15 + 50);
  191. }else { // dup
  192. dup = true;
  193. if (k == null) {
  194. console.log("In K=3");
  195. //var clickEvent = document.createEvent('MouseEvents');
  196. //clickEvent.initEvent('click', true, true);
  197. //document.getElementsByClassName("feed-ajax-next")[0].dispatchEvent(clickEvent);
  198. if (!document.getElementsByClassName("feed-ajax-next")[0]){
  199. notes = true;
  200. }else{
  201. document.getElementsByClassName("feed-ajax-next")[0].click();
  202. randomNum = 13;
  203. }
  204. k = -1;
  205. }else{
  206. randomNum = 8;
  207. }
  208. if(document.getElementById("tout").getElementsByTagName("h2")[0].innerHTML == "Editor's Pick"){
  209. selectNewCat();
  210. }else if(document.getElementById("tout").getElementsByTagName("h2")[0].innerHTML == "Uzoo"){
  211. selectNewCat();
  212. }
  213. }
  214. if (k == null) {
  215. console.log("In K=3");
  216. if (!document.getElementsByClassName("feed-ajax-next")[0]){
  217. notes = true;
  218. }else{
  219. document.getElementsByClassName("feed-ajax-next")[0].click();
  220. }
  221. k = -1;
  222. }
  223. if(notes && dup){
  224. selectNewCat();
  225. }
  226. };
  227. if (iLoops == randomNum){
  228. if (document.getElementById("sbvd_capText")) {
  229. pic = document.getElementById("sbvdcapimg");
  230. pic.crossOrigin = 'anonymous';
  231. var string = getCaptchaText(pic);
  232. }
  233. else {
  234. if (notes){
  235. selectNewCat();
  236. }else{
  237. link = document.getElementsByClassName("thumb-link")[k+1].href;
  238. window.location.href = link;
  239. }
  240. }
  241. }
  242. if(iLoops > 120){
  243. window.location.href = document.getElementsByClassName("thumb-link")[0].href;
  244. }
  245. if(iLoops > 500){
  246. selectNewCat();
  247. }
  248. };
  249.  
  250. var childWindow = null;
  251.  
  252. if (window.opener != null && window.location.href.indexOf("mumbojumbo") > -1) {
  253. console.log("in");
  254. window.opener.postMessage("Child Frame Loaded", "*");
  255. var pic = document.getElementsByTagName("img")[0];
  256. console.log(pic);
  257. ocrString = ""
  258. if (pic){
  259. setTimeout(function(){
  260. var image = getBase64Image(pic);
  261. console.log(image);
  262. var imageData = image[0];
  263. var ocrString = GOCR(imageData);meout
  264. ocrString = ocrString.replace(/\s+/g, '');
  265. console.log(ocrString.toUpperCase());
  266. },1500);
  267. }
  268. window.opener.postMessage({magicword: "mumbojumbo", string: ocrString}, "*");
  269. window.opener=window;
  270. window.close();
  271. top.window.close();
  272. window.setInterval(window.close,1000);
  273. }
  274.  
  275. window.addEventListener("message", function(e) {
  276. if (e.data.magicword === "mumbojumbo") {
  277. console.log("Message Received");
  278. console.log(e.data);
  279. var ocrString = e.data.string.toUpperCase();
  280. console.log("string");
  281. console.log(ocrString);
  282. console.log("string");
  283. if (childWindow)
  284. childWindow.close();
  285. if (ocrString.indexOf('_') === -1){
  286. if (document.getElementById("sbvd_capText")){
  287. document.getElementById("sbvd_capText").value = ocrString;
  288. document.getElementsByClassName("btnClaim")[0].click();
  289. setTimeout(function() {
  290. if (!document.getElementById("sbvd_capText")){
  291. k=getK();
  292. if (k == null)
  293. k=-1;
  294. link = document.getElementsByClassName("thumb-link")[k+1].href;
  295. //alert("NEXT");
  296. window.location.href = link;
  297. }
  298. else{
  299. //alert("Opened 1");
  300. var pic = document.getElementById("sbvdcapimg");
  301. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  302. }
  303. }, 1000);
  304. }
  305. }
  306. else{
  307. //alert("Opened 2");
  308. var pic = document.getElementById("sbvdcapimg");
  309. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  310. }
  311. }
  312. else{
  313. //console.log("Also message received");
  314. //console.log(e.data);
  315. }
  316. }, false);
  317.  
  318. function checkLimit(){
  319. var limited = document.getElementById("meterOverlimit");
  320. if(limited.style.display == '') { // reach limited
  321. document.title = document.title+" REACHED LIMIT";
  322. document.location.href = "http://www.swagbuck.com/";
  323. }
  324. }
  325.  
  326. function selectNewCat(){
  327. console.log("Pick a new category");
  328. var videoindex = getCookie("videoindex");
  329. var c = (isNaN(videoindex) ? 0 : +videoindex);
  330. videoindex = c + 1;
  331. if(videoindex+1>channel.length){videoindex = 1}
  332. setCookie("videoindex",videoindex ,365, "/");
  333. setTimeout(function() {
  334. document.location.href = channel[videoindex];
  335. }, 1000);
  336. }
  337.  
  338. function safeBW(){
  339. if(document.getElementById("video-title")!= undefined){
  340. var video = document.getElementById("video-title");
  341. video.parentNode.removeChild(video);
  342. }
  343. if(document.getElementById("commentsCont")!= undefined){
  344. var comment = document.getElementById("commentsCont");
  345. comment.parentNode.removeChild(comment);
  346. }
  347. if(document.getElementById("sbFooterWrap")!= undefined){
  348. var footer = document.getElementById("sbFooterWrap");
  349. footer.parentNode.removeChild(footer);
  350. }
  351. if(document.getElementById("helpTab")!= undefined){
  352. var helpTab = document.getElementById("helpTab");
  353. helpTab.parentNode.removeChild(helpTab);
  354. }
  355. if(document.getElementById("adContBottom928")!= undefined){
  356. var bottomad = document.getElementById("adContBottom928");
  357. bottomad.parentNode.removeChild(bottomad);
  358. }
  359. }
  360.  
  361. function getCaptchaText(pic){
  362. var pic = document.getElementById("sbvdcapimg");
  363. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  364. }
  365.  
  366. function getBase64Image(img) {
  367. /* // Create an empty canvas element
  368. var pic = document.createElement("img");
  369. pic.src = img;
  370. var canvas = document.createElement("canvas");
  371. canvas.width = img.width;
  372. canvas.height = img.height;
  373.  
  374. // Copy the image contents to the canvas
  375. var ctx = canvas.getContext("2d");
  376. ctx.drawImage(pic, 0, 0);
  377. var pic2 = document.createElement("img");
  378. pic2.src=canvas.toDataURL("image/png");
  379. console.log(canvas.toDataURL("image/png"));
  380. ctx.drawImage(pic2,0,0);
  381.  
  382. // Get the data-URL formatted image
  383. // Firefox supports PNG and JPEG. You could check img.src to
  384. // guess the original format, but be aware the using "image/jpg"
  385. // will re-encode the image.
  386. var dataURL = ctx.getImageData(0,0,canvas.width,canvas.height);
  387.  
  388. return dataURL;//.replace(/^data:image\/(png|jpg);base64,/, "");*/
  389. // Create an empty canvas element
  390. var canvas = document.createElement("canvas");
  391. canvas.width = img.width;
  392. canvas.height = img.height;
  393. // Copy the image contents to the canvas
  394. var ctx = canvas.getContext("2d");
  395. ctx.drawImage(img, 0, 0);
  396. // Get the data-URL formatted image
  397. // Firefox supports PNG and JPEG. You could check img.src to
  398. // guess the original format, but be aware the using "image/jpg"
  399. // will re-encode the image.
  400. var dataURL = ctx.getImageData(0,0,canvas.width,canvas.height);
  401. return dataURL;//.replace(/^data:image\/(png|jpg);base64,/, "");
  402. }
  403.  
  404. function getCookie(c_name)
  405. {
  406. var i,x,y,ARRcookies=document.cookie.split(";");
  407. for (i=0;i<ARRcookies.length;i++)
  408. {
  409. x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  410. y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  411. x=x.replace(/^\s+|\s+$/g,"");
  412. if (x==c_name)
  413. {
  414. return unescape(y);
  415. }
  416. }
  417. }
  418.  
  419. function setCookie( name, value, expires, path )
  420. {
  421. // set time, it's in milliseconds
  422. var today = new Date();
  423. today.setTime( today.getTime() );
  424. /*
  425. if the expires variable is set, make the correct
  426. expires time, the current script below will set
  427. it for x number of days, to make it for hours,
  428. delete * 24, for minutes, delete * 60 * 24
  429. */
  430. if ( expires )
  431. {
  432. expires = expires * 1000 * 60 * 60 * 24;
  433. }
  434. var expires_date = new Date( today.getTime() + (expires) );
  435. document.cookie = name + "=" +escape( value ) +
  436. ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
  437. ( ( path ) ? ";path=" + path : "" );
  438. }
  439.  
  440.  
  441. function test(){
  442. var items = document.getElementsByClassName("subnav");
  443. var itemscount = items.length;
  444. for(var i=0;i<itemscount;i++){
  445. console.log(items[i]);
  446. }
  447. }