Greasy Fork镜像 支持简体中文。

Scratch & Win and Pull Tabs - Automatic Play

Add option to auto-play tickets on Scratch & Win and Pull Tabs on Facebook.

  1. // ==UserScript==
  2. // @name Scratch & Win and Pull Tabs - Automatic Play
  3. // @namespace http://www.mathemaniac.org
  4. // @include http://*.facebook.tld/scratchit/play.htm*
  5. // @include http://*.facebook.tld/pulltabs/play.htm*
  6. // @author Sebastian Paaske Tørholm - eckankar at gmail
  7. // @version 1.2.2
  8. // @description Add option to auto-play tickets on Scratch & Win and Pull Tabs on Facebook.
  9. // ==/UserScript==
  10.  
  11. var loc = ""+document.location;
  12. var isPullTabs = loc.match(/pulltabs/) != null;
  13. var xpath = '//a[contains(text(),"Next ' + ( isPullTabs ? 'Pull Tab' : 'Ticket' ) + '")]';
  14.  
  15. if (loc.match(/autoplay/)) {
  16. var ticketBtn = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  17. var textDiv = document.createElement('div');
  18. textDiv.setAttribute('style','border: 2px solid black; background-color: lightgrey; text-align: center; padding: 5px;');
  19. var swfScript = document.evaluate('//div[contains(@id,"js_buffer")]/script[contains(.,"comp.exec")]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  20. swfScript = swfScript.text;
  21. var curl = 'http://apps.bstage.ca/'+(isPullTabs ? 'pulltabs' : 'scratchit')+'/comp.exec?code='+swfScript.match(/%2Fcomp.exec%3Fcode%3D([^"]+)\\"\);/)[1];
  22. if (swfScript.match(/PairsTicket_.+\.swf/)) {
  23. var numPairs = swfScript.match(/\.addVariable\(\\"pairs\\", \\"(\d)\\"\);/);
  24. textDiv.appendChild(document.createTextNode('You have '+numPairs[1]+' pair'+(numPairs != 1 ? 's' : '') +' on this ticket.'));
  25. resourceText(curl,function(res) {
  26. setTimeout(function() { document.location = ticketBtn.href +"?"+Math.random()+"#autoplay";},3400);
  27. } );
  28. }
  29. else if (swfScript.match(/(MatchGameTicket|MakeADealTicket)_.+\.swf/)) {
  30. var prize = swfScript.match(/\.addVariable\(\\"wp\\", \\"(\d+)\\"\);/);
  31. textDiv.appendChild(document.createTextNode('You won '+(prize[1] = 0 ? 'no' : prize[1]) +' token'+(prize[1] != 1 ? 's' : '') +' on this ticket.'));
  32. resourceText(curl,function(res) {
  33. setTimeout(function() { document.location = ticketBtn.href +"?"+Math.random()+"#autoplay";},3400);
  34. } );
  35. }
  36. else if (swfScript.match(/PullTabs_.+\.swf/)) {
  37. var prize = swfScript.match(/\\"outcome\\", \\"([^\\]+)\\"/);
  38. var prizeType;
  39. if (prize[1].match(/l/))
  40. prizeType = "nothing";
  41. else if (prize[1].match(/t(\d+)/))
  42. prizeType = prize[1].replace(/t/,"").replace(/%7Cm/g,"×") + " tokens";
  43. else
  44. prizeType = prize[1];
  45. textDiv.appendChild(document.createTextNode('You won '+prizeType+' on this ticket.'));
  46. resourceText(curl,function(res) {
  47. setTimeout(function() { document.location = ticketBtn.href +"?"+Math.random()+"#autoplay";},3400);
  48. } );
  49. }
  50. else
  51. textDiv.appendChild(document.createTextNode("Sorry, no autoplay available for this ticket type.\nPlease tell Eckankar at gmail dot com, thanks!"));
  52.  
  53. ticketBtn.parentNode.insertBefore(textDiv,ticketBtn.nextSibling);
  54. }
  55. else {
  56. var it = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE,null);
  57. var node;
  58. var nodes = new Array();
  59. while (node = it.iterateNext()) {
  60. nodes.push(node);
  61. }
  62. while (node = nodes.pop()) {
  63. var aBtn = document.createElement('a');
  64. aBtn.className = "button main"
  65. aBtn.appendChild(document.createTextNode('AutoPlay'));
  66. aBtn.href = aBtn.href+"?"+Math.random()+"#autoplay";
  67. node.parentNode.insertBefore(aBtn,node.nextSibling);
  68. }
  69. }
  70.  
  71. // snagged from http://userscripts.org/users/55607.
  72. function resourceText(url,func,key,post)
  73. {
  74. if (!post && key && window.GM_getResourceText)
  75. {
  76. func(GM_getResourceText(key));
  77. } else {
  78. var options = {
  79. "url":url,
  80. "method": ( post ? "post" : "get" ),
  81. "headers":{
  82. "User-Agent":"Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-BR; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14",
  83. "Accept":"text/json,text/xml,text/html"
  84. },
  85. "onload":function (e) {
  86. var ok = true;
  87. if (url.match("[?&]type=json"))
  88. {
  89. var rjson = evalValue(e.responseText).response;
  90. if (rjson.errorMessage)
  91. {
  92. if (!rjson.actions) ok = false;
  93. alert(rjson.errorMessage);
  94. }
  95. else if (rjson.warningMessage)
  96. {
  97. alert(rjson.warningMessage);
  98. }
  99. if (rjson.location && (!rjson.location[0] || !GM_getValue(rjson.location[0],false)))
  100. {
  101. GM_openInTab(rjson.location[1]);
  102. if (rjson.location[0])
  103. {
  104. alert("A new tab was opened.\nUrl: " + rjson.location[1]);
  105. GM_log(rjson.location);
  106. GM_getValue(rjson.location[0],true);
  107. }
  108. }
  109.  
  110. if (ok)
  111. {
  112. func(e.responseText);
  113. }
  114. } else {
  115. if (ok)
  116. {
  117. func(e.responseText);
  118. }
  119. }
  120. },
  121. "onerror":function (e) {
  122. alert("An error has ocurred while requesting "+url);
  123. }
  124. };
  125. if (post)
  126. {
  127. var data = "";
  128. for ( n in key )
  129. {
  130. data += "&" + n + "=" + encodeURIComponent(key[n]);
  131. }
  132. data = data.substr(1);
  133.  
  134. options.headers["Content-type"] = "application/x-www-form-urlencoded";
  135. options.headers["Content-length"] = data.length;
  136. options.data = data;
  137. }
  138. GM_xmlhttpRequest(options);
  139. }
  140. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址