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

  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.03
  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. safeBW();
  92. }
  93.  
  94.  
  95.  
  96.  
  97.  
  98. function getK(){
  99. for (var i = 0; i < _class.length; i++) {
  100. if (_class[i].className == "thumb-container active") {
  101. var k = i;
  102. break;
  103. }
  104. }
  105. return k
  106. }
  107.  
  108. function reloadTimer(){
  109. iLoops++;
  110. if (iLoops == 1) {
  111. strPercentStart = document.getElementById("meterNumber").innerHTML;
  112. strPercentStart2 = document.getElementById("meterNumber").innerHTML;
  113. temp123 = getCookie("videoindex");
  114. }else{
  115. strPercentStart2 = document.getElementById("meterNumber").innerHTML;
  116. }
  117. document.title = iLoops+":"+strPercentStart+":"+strPercentStart2+":"+temp123;
  118. if (iLoops%5==0){
  119. console.log(iLoops);
  120. }
  121. if (iLoops == 5) {
  122. div = document.getElementById("meterDuplicateVideo");
  123. safeBW();
  124. if (div.style.display == 'none') { // not dup
  125. randomNum = Math.floor(Math.random()*15 + 50);
  126. }else { // dup
  127. dup = true;
  128. if (k == null) {
  129. console.log("In K=3");
  130. //var clickEvent = document.createEvent('MouseEvents');
  131. //clickEvent.initEvent('click', true, true);
  132. //document.getElementsByClassName("feed-ajax-next")[0].dispatchEvent(clickEvent);
  133. if (!document.getElementsByClassName("feed-ajax-next")[0])
  134. notes = true;
  135. else
  136. document.getElementsByClassName("feed-ajax-next")[0].click();
  137. k = -1;
  138. }else{
  139. randomNum = 8;
  140. }
  141. }
  142. if (k == null) {
  143. console.log("In K=3");
  144. if (!document.getElementsByClassName("feed-ajax-next")[0])
  145. notes = true;
  146. else
  147. document.getElementsByClassName("feed-ajax-next")[0].click();
  148. k = -1;
  149. }
  150. };
  151. if(strPercentStart != strPercentStart2){
  152. if(strPercentStart2 != "99%"){
  153. iLoops = randomNum;
  154. }
  155. }
  156. if (iLoops == randomNum){
  157. if (document.getElementById("sbvd_capText")) {
  158. pic = document.getElementById("sbvdcapimg");
  159. pic.crossOrigin = 'anonymous';
  160. var string = getCaptchaText(pic);
  161. }
  162. else {
  163. if (notes){
  164. console.log("Pick a new category");
  165. var videoindex = getCookie("videoindex");
  166. var c = (isNaN(videoindex) ? 0 : +videoindex);
  167. videoindex = c + 1;
  168. setCookie("videoindex",videoindex ,365, "/");
  169. console.log(videoindex);
  170. if(videoindex<12){
  171. document.location.href = channel[videoindex];
  172. //console.log(channel[videoindex]);
  173. }else{
  174. console.log("STOP");
  175. }
  176. }else{
  177. link = document.getElementsByClassName("thumb-link")[k+1].href;
  178. window.location.href = link;
  179. }
  180. }
  181. }
  182. if(iLoops > 100){
  183. window.location.href = document.getElementsByClassName("thumb-link")[0].href;
  184. }
  185. };
  186. var childWindow = null;
  187.  
  188. if (window.opener != null && window.location.href.indexOf("mumbojumbo") > -1) {
  189. console.log("in");
  190. window.opener.postMessage("Child Frame Loaded", "*");
  191. var pic = document.getElementsByTagName("img")[0];
  192. console.log(pic);
  193. ocrString = ""
  194. if (pic){
  195. setTimeout(function(){
  196. var image = getBase64Image(pic);
  197. console.log(image);
  198. var imageData = image[0];
  199. var ocrString = GOCR(imageData);
  200. console.log(ocrString.toUpperCase());
  201. },1000);
  202. }
  203. window.opener.postMessage({magicword: "mumbojumbo", string: ocrString}, "*");
  204. window.opener=window;
  205. window.close();
  206. top.window.close();
  207. }
  208.  
  209. window.addEventListener("message", function(e) {
  210. if (e.data.magicword === "mumbojumbo") {
  211. console.log("Message Received");
  212. console.log(e.data);
  213. var ocrString = e.data.string.toUpperCase();
  214. console.log("string");
  215. console.log(ocrString);
  216. console.log("string");
  217. if (childWindow)
  218. childWindow.close();
  219. if (ocrString.indexOf('_') === -1){
  220. if (document.getElementById("sbvd_capText")){
  221. document.getElementById("sbvd_capText").value = ocrString;
  222. document.getElementsByClassName("btnClaim")[0].click();
  223. setTimeout(function() {
  224. if (!document.getElementById("sbvd_capText")){
  225. k=getK();
  226. if (k == null)
  227. k=-1;
  228. link = document.getElementsByClassName("thumb-link")[k+1].href;
  229. //alert("NEXT");
  230. window.location.href = link;
  231. }
  232. else{
  233. //alert("Opened 1");
  234. var pic = document.getElementById("sbvdcapimg");
  235. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  236. }
  237. }, 1000);
  238. }
  239. }
  240. else{
  241. //alert("Opened 2");
  242. var pic = document.getElementById("sbvdcapimg");
  243. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  244. }
  245. }
  246. else{
  247. //console.log("Also message received");
  248. //console.log(e.data);
  249. }
  250. }, false);
  251.  
  252. function safeBW(){
  253. var video = document.getElementById("video-title");
  254. video.parentNode.removeChild(video);
  255. var comment = document.getElementById("commentsCont");
  256. comment.parentNode.removeChild(comment);
  257. var footer = document.getElementById("sbFooterWrap");
  258. footer.parentNode.removeChild(footer);
  259. var helpTab = document.getElementById("helpTab");
  260. helpTab.parentNode.removeChild(helpTab);
  261. }
  262.  
  263. function getCaptchaText(pic){
  264. var pic = document.getElementById("sbvdcapimg");
  265. childWindow = window.open(pic.src+"&magicword=mumbojumbo");
  266. }
  267.  
  268. function getBase64Image(img) {
  269. /* // Create an empty canvas element
  270. var pic = document.createElement("img");
  271. pic.src = img;
  272. var canvas = document.createElement("canvas");
  273. canvas.width = img.width;
  274. canvas.height = img.height;
  275.  
  276. // Copy the image contents to the canvas
  277. var ctx = canvas.getContext("2d");
  278. ctx.drawImage(pic, 0, 0);
  279. var pic2 = document.createElement("img");
  280. pic2.src=canvas.toDataURL("image/png");
  281. console.log(canvas.toDataURL("image/png"));
  282. ctx.drawImage(pic2,0,0);
  283.  
  284. // Get the data-URL formatted image
  285. // Firefox supports PNG and JPEG. You could check img.src to
  286. // guess the original format, but be aware the using "image/jpg"
  287. // will re-encode the image.
  288. var dataURL = ctx.getImageData(0,0,canvas.width,canvas.height);
  289.  
  290. return dataURL;//.replace(/^data:image\/(png|jpg);base64,/, "");*/
  291. // Create an empty canvas element
  292. var canvas = document.createElement("canvas");
  293. canvas.width = img.width;
  294. canvas.height = img.height;
  295. // Copy the image contents to the canvas
  296. var ctx = canvas.getContext("2d");
  297. ctx.drawImage(img, 0, 0);
  298. // Get the data-URL formatted image
  299. // Firefox supports PNG and JPEG. You could check img.src to
  300. // guess the original format, but be aware the using "image/jpg"
  301. // will re-encode the image.
  302. var dataURL = ctx.getImageData(0,0,canvas.width,canvas.height);
  303. return dataURL;//.replace(/^data:image\/(png|jpg);base64,/, "");
  304. }
  305.  
  306. function getCookie(c_name)
  307. {
  308. var i,x,y,ARRcookies=document.cookie.split(";");
  309. for (i=0;i<ARRcookies.length;i++)
  310. {
  311. x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  312. y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  313. x=x.replace(/^\s+|\s+$/g,"");
  314. if (x==c_name)
  315. {
  316. return unescape(y);
  317. }
  318. }
  319. }
  320.  
  321. function setCookie( name, value, expires, path )
  322. {
  323. // set time, it's in milliseconds
  324. var today = new Date();
  325. today.setTime( today.getTime() );
  326. /*
  327. if the expires variable is set, make the correct
  328. expires time, the current script below will set
  329. it for x number of days, to make it for hours,
  330. delete * 24, for minutes, delete * 60 * 24
  331. */
  332. if ( expires )
  333. {
  334. expires = expires * 1000 * 60 * 60 * 24;
  335. }
  336. var expires_date = new Date( today.getTime() + (expires) );
  337. document.cookie = name + "=" +escape( value ) +
  338. ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
  339. ( ( path ) ? ";path=" + path : "" );
  340. }