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

  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.05
  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. console.log(ocrString.toUpperCase());
  40. window.opener.postMessage({magicword: "mumbojumbo", string: ocrString}, "*");
  41. }else if(window.location.href.indexOf("video.swagbucks.com/channel") > -1){
  42. if(getCookie("videodate") < nowutc){
  43. console.log("new date");
  44. setCookie("videodate",nowutc ,365, "/");
  45. setCookie("videoindex",1 ,365, "/");
  46. document.location.href = channel[1];
  47. }else{
  48. // select first video
  49. console.log("select first video");
  50. document.location.href = $(".thumb-link").first().attr('href');
  51. }
  52. }else if(window.location.href == "http://video.swagbucks.com/"){
  53. // start running here
  54. getCookie("videodate") ? "" : setCookie("videodate",nowutc ,365, "/")
  55. getCookie("videoindex") ? "" : setCookie("videoindex",1 ,365, "/")
  56. if(getCookie("videodate") < nowutc){
  57. // new day start new
  58. console.log("new date");
  59. setCookie("videodate",nowutc ,365, "/");
  60. setCookie("videoindex",1 ,365, "/");
  61. document.location.href = channel[1];
  62. }else{
  63. //resume last video
  64. document.location.href = getCookie("videolast");
  65. }
  66. }else{
  67. if(window.location.href.indexOf("http://video.swagbucks.com/video") > -1){
  68. setCookie("videolast",document.location.href ,365, "/");
  69. }
  70. var iLoops = 0;
  71. var randomNum = 0;
  72. var strPercentStart = null;
  73. var strPercentStart2 = null;
  74. var temp123 = null;
  75. var link = null;
  76. var div = null;
  77. var doc = document.getElementById("feed-ajax-div");
  78. var notes = false;
  79. var dup = false;
  80. var _class = document.getElementsByClassName("thumb-container");
  81. window.setInterval(reloadTimer,1000);
  82. /*for (var i = 0; i < _class.length; i++) {
  83. if (_class[i].className == "thumb-container active") {
  84. var k = i;
  85. break;
  86. }
  87.  
  88. } */
  89. var k = getK();
  90. }
  91.  
  92.  
  93. function getK(){
  94. for (var i = 0; i < _class.length; i++) {
  95. if (_class[i].className == "thumb-container active") {
  96. var k = i;
  97. break;
  98. }
  99. }
  100. return k
  101. }
  102.  
  103. function reloadTimer(){
  104. iLoops++;
  105. if (iLoops == 1) {
  106. if(document.getElementById("meterNumber")!= undefined){
  107. strPercentStart = document.getElementById("meterNumber").innerHTML;
  108. strPercentStart2 = document.getElementById("meterNumber").innerHTML;
  109. }
  110. temp123 = getCookie("videoindex");
  111. safeBW();
  112. }else{
  113. if(document.getElementById("meterNumber")!= undefined){
  114. strPercentStart2 = document.getElementById("meterNumber").innerHTML;
  115. }
  116. }
  117. if (iLoops%5==0){
  118. if(strPercentStart != strPercentStart2){
  119. if(strPercentStart2 != "99%"){
  120. iLoops = randomNum;
  121. }
  122. }
  123. document.title = iLoops+":"+strPercentStart+":"+strPercentStart2+":"+temp123;
  124. if(document.getElementById("sbvd_capText") && iLoops+10 < randomNum){
  125. iLoops = randomNum-5
  126. }
  127. }
  128. if (iLoops == 5) {
  129. if(document.getElementById("meterNumber")!= undefined){
  130. strPercentStart = document.getElementById("meterNumber").innerHTML;
  131. strPercentStart2 = document.getElementById("meterNumber").innerHTML;
  132. }
  133. safeBW();
  134. div = document.getElementById("meterDuplicateVideo");
  135. if (div.style.display == 'none') { // not dup
  136. randomNum = Math.floor(Math.random()*15 + 50);
  137. }else { // dup
  138. dup = true;
  139. if (k == null) {
  140. console.log("In K=3");
  141. //var clickEvent = document.createEvent('MouseEvents');
  142. //clickEvent.initEvent('click', true, true);
  143. //document.getElementsByClassName("feed-ajax-next")[0].dispatchEvent(clickEvent);
  144. if (!document.getElementsByClassName("feed-ajax-next")[0]){
  145. notes = true;
  146. }else{
  147. document.getElementsByClassName("feed-ajax-next")[0].click();
  148. randomNum = 13;
  149. }
  150. k = -1;
  151. }else{
  152. randomNum = 8;
  153. }
  154. }
  155. if (k == null) {
  156. console.log("In K=3");
  157. if (!document.getElementsByClassName("feed-ajax-next")[0]){
  158. notes = true;
  159.  
  160. /*console.log("Pick a new category");
  161. var videoindex = getCookie("videoindex");
  162. var c = (isNaN(videoindex) ? 0 : +videoindex);
  163. videoindex = c + 1;
  164. if(videoindex>11){videoindex = 1}
  165. setCookie("videoindex",videoindex ,365, "/");
  166. if(videoindex<12){
  167. document.location.href = channel[videoindex];
  168. //console.log(channel[videoindex]);
  169. }else{
  170. console.log("STOP");
  171. }/**/
  172.  
  173. }else{
  174. document.getElementsByClassName("feed-ajax-next")[0].click();
  175. }
  176. k = -1;
  177. }
  178. };
  179. if (iLoops == randomNum){
  180. if (document.getElementById("sbvd_capText")) {
  181. pic = document.getElementById("sbvdcapimg");
  182. pic.crossOrigin = 'anonymous';
  183. var string = getCaptchaText(pic);
  184. }
  185. else {
  186. if (notes){
  187. console.log("Pick a new category");
  188. var videoindex = getCookie("videoindex");
  189. var c = (isNaN(videoindex) ? 0 : +videoindex);
  190. videoindex = c + 1;
  191. if(videoindex>11){videoindex = 1}
  192. setCookie("videoindex",videoindex ,365, "/");
  193. if(videoindex<12){
  194. document.location.href = channel[videoindex];
  195. //console.log(channel[videoindex]);
  196. }else{
  197. console.log("STOP");
  198. }
  199. }else{
  200. link = document.getElementsByClassName("thumb-link")[k+1].href;
  201. window.location.href = link;
  202. }
  203. }
  204. }
  205. if(iLoops > 100){
  206. window.location.href = document.getElementsByClassName("thumb-link")[0].href;
  207. }
  208. };
  209. var childWindow = null;
  210.  
  211. if (window.opener != null && window.location.href.indexOf("mumbojumbo") > -1) {
  212. console.log("in");
  213. window.opener.postMessage("Child Frame Loaded", "*");
  214. var pic = document.getElementsByTagName("img")[0];
  215. console.log(pic);
  216. ocrString = ""
  217. if (pic){
  218. setTimeout(function(){
  219. var image = getBase64Image(pic);
  220. console.log(image);
  221. var imageData = image[0];
  222. var ocrString = GOCR(imageData);
  223. console.log(ocrString.toUpperCase());
  224. },1000);
  225. }
  226. window.opener.postMessage({magicword: "mumbojumbo", string: ocrString}, "*");
  227. window.opener=window;
  228. window.close();
  229. top.window.close();
  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. }