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

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