Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.11 KB | None | 0 0
  1. t.
  2. // ==UserScript==
  3. // @name R1 - YS API Plus
  4. // @version 2.0.3
  5. // @description Add several enhancements to YS API on R1
  6. // @author Limit
  7. // @match *://*.rewards1.com/*
  8. // @grant none
  9. // @namespace https://greasyfork.org/users/141657
  10. // ==/UserScript==
  11.  
  12. var surveys = [
  13. {
  14. payout: 1000,
  15. id: 9629824
  16. },
  17. {
  18. payout: 875,
  19. id: 9199581
  20. },
  21. {
  22. payout: 750,
  23. id: 9199582
  24. },
  25. {
  26. payout: 625,
  27. id: 9128884
  28. },
  29. {
  30. payout: 600,
  31. id: 11168891
  32. },
  33. {
  34. payout: 500,
  35. id: 9141040
  36. },
  37. {
  38. payout: 450,
  39. id: 9152765
  40. },
  41. {
  42. payout: 400,
  43. id: 9186978
  44. },
  45. {
  46. payout: 350,
  47. id: 9168340
  48. },
  49. {
  50. payout: 300,
  51. id: 11339079
  52. },
  53. {
  54. payout: 225,
  55. id: 9144310
  56. },
  57. {
  58. payout: 200,
  59. id: 9141239
  60. },
  61. {
  62. payout: 150,
  63. id: 11650340
  64. },
  65. {
  66. payout: 120,
  67. id: 11584420
  68. },
  69. {
  70. payout: 100,
  71. id: 12012613
  72. },
  73. {
  74. payout: 85,
  75. id: 11997560
  76. },
  77. ];
  78.  
  79. function init() {
  80. clearTimeout(readyTimer);
  81. spRemoveListener('ready', init);
  82.  
  83. //spAlert('(ysapi+) sp detected!');
  84.  
  85. spListen('ysLoaded', onYsLoad);
  86. spListen('ysUnloaded', onYsUnload);
  87. }
  88.  
  89. function onYsLoad() {
  90. //spAlert('(ysapi+) ys loaded!');
  91.  
  92. // ==================================
  93. // === ADD SURVEY ID & STRIP LINK ===
  94. // ==================================
  95. // Element array with max length 21 (1 router + 20 api's)
  96. var surveyList = document.getElementsByClassName('ys-api')[0].children[0].children[0].children;
  97. // Starting at 1 instead of 0 to skip the router entry
  98. for (var i = 1, l = surveyList.length; i < l; i++) {
  99. var surveyId = parseInt(surveyList[i].children[0].children[0].children[0].id.split('-')[2], 10);
  100. var titles = surveyList[i].getElementsByTagName('h3');
  101. for (var j = 0, tl = titles.length; j < tl; j++) {
  102. titles[j].innerHTML = '<span onclick="return false;" style="user-select: all; cursor: text; background: #728e8e;color: #fff;text-shadow: 1px 1px #222;padding: 2px 5px;font-size: 14px;border-radius: 3px;margin-right: 5px;display: inline-block;">' + surveyId + '</span>' + titles[j].innerHTML.trim();
  103. }
  104. var links = surveyList[i].getElementsByTagName('a');
  105. for (var k = 0, ll = links.length; k < ll; k++) {
  106. links[k].href = 'https://www.your-surveys.com/?si=157&ssi=' + spGet('userId') + '&offer_id=' + surveyId;
  107. }
  108. }
  109. // ==================================
  110. // ======= ADD CUSTOM ENTRIES =======
  111. // ==================================
  112.  
  113. //
  114. // --- LARGE SCREEN / DESKTOP ENTRY ---
  115. //
  116. var customEntry = surveyList[1].cloneNode(true);
  117. customEntry.children[0].children[0].style.transition = 'opacity ease-in 0.25s';
  118. surveyList[1].parentNode.insertBefore(customEntry, surveyList[1]);
  119. setTimeout(() => { customEntry.children[0].children[0].style.opacity = 1; }, 0);
  120.  
  121. customEntry.getElementsByTagName('a')[0].id = 'ys_custom_link_desktop';
  122.  
  123. var customTitles = customEntry.getElementsByClassName('title');
  124. customTitles[0].onclick = () => { return false; };
  125. customTitles[0].innerHTML = '<input id="ys_custom_input_desktop" maxlength="8" style="width:140px;margin:0 auto;display:block;cursor:text;font-family:Lato;font-size:28px;box-sizing:content-box;padding:5px 15px;outline:0;border:none;user-select:all;text-align:center;background:#728e8e;color:#fff;text-shadow:2px 2px #222;border-radius:3px">';
  126.  
  127. var customMetaData = customEntry.getElementsByClassName('meta-data-list')[0];
  128. customMetaData.children[0].title = '';
  129. customMetaData.children[0].innerHTML = 'YS-API+&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;By Limit';
  130. customMetaData.removeChild(customMetaData.children[1]);
  131. customMetaData.removeChild(customMetaData.children[1]);
  132.  
  133. customEntry.getElementsByClassName('payout')[0].children[0].outerHTML = '<select id="ys_custom_select_desktop" class="points" style="height:20px;outline:0;border:none;background:0 0;font-family:\'Roboto Mono\',sans-serif;font-size: 16px;cursor:pointer;margin-right: 3px;color: #fff;"></select>';
  134.  
  135. customEntry.getElementsByClassName('payout-holder')[0].style.background = 'url("data:image/svg+xml,%3Csvg xmlns:dc=\'http://purl.org/dc/elements/1.1/\' xmlns:cc=\'http://creativecommons.org/ns%23\' xmlns:rdf=\'http://www.w3.org/1999/02/22-rdf-syntax-ns%23\' xmlns:svg=\'http://www.w3.org/2000/svg\' xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\' xmlns:sodipodi=\'http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\' xmlns:inkscape=\'http://www.inkscape.org/namespaces/inkscape\' width=\'200\' height=\'50\' viewBox=\'0 0 52.916666 13.229167\' version=\'1.1\' id=\'svg5002\' inkscape:version=\'0.92.2 (5c3e80d, 2017-08-06)\' sodipodi:docname=\'out4.svg\'%3E%3Cdefs id=\'defs4996\'%3E%3ClinearGradient inkscape:collect=\'always\' id=\'linearGradient5012\'%3E%3Cstop style=\'stop-color:%23001717;stop-opacity:1;\' offset=\'0\' id=\'stop5008\'/%3E%3Cstop style=\'stop-color:%23007070;stop-opacity:1\' offset=\'1\' id=\'stop5010\'/%3E%3C/linearGradient%3E%3ClinearGradient inkscape:collect=\'always\' xlink:href=\'%23linearGradient5012\' id=\'linearGradient5014\' x1=\'217.00558\' y1=\'286.51117\' x2=\'206.89645\' y2=\'286.29794\' gradientUnits=\'userSpaceOnUse\'/%3E%3ClinearGradient inkscape:collect=\'always\' xlink:href=\'%23linearGradient5012\' id=\'linearGradient5595\' gradientUnits=\'userSpaceOnUse\' x1=\'217.00558\' y1=\'286.51117\' x2=\'204.29391\' y2=\'286.47543\'/%3E%3C/defs%3E%3Csodipodi:namedview id=\'base\' pagecolor=\'%23ffffff\' bordercolor=\'%23666666\' borderopacity=\'1.0\' inkscape:pageopacity=\'0.0\' inkscape:pageshadow=\'2\' inkscape:zoom=\'11.2\' inkscape:cx=\'131.86532\' inkscape:cy=\'45.500371\' inkscape:document-units=\'mm\' inkscape:current-layer=\'g5593\' showgrid=\'true\' showborder=\'true\' inkscape:snap-grids=\'false\' inkscape:window-width=\'2560\' inkscape:window-height=\'1377\' inkscape:window-x=\'2552\' inkscape:window-y=\'-8\' inkscape:window-maximized=\'1\' inkscape:pagecheckerboard=\'false\' units=\'px\'%3E%3Cinkscape:grid type=\'xygrid\' id=\'grid5004\'/%3E%3C/sodipodi:namedview%3E%3Cmetadata id=\'metadata4999\'%3E%3Crdf:RDF%3E%3Ccc:Work rdf:about=\'\'%3E%3Cdc:format%3Eimage/svg+xml%3C/dc:format%3E%3Cdc:type rdf:resource=\'http://purl.org/dc/dcmitype/StillImage\'/%3E%3Cdc:title/%3E%3C/cc:Work%3E%3C/rdf:RDF%3E%3C/metadata%3E%3Cg inkscape:label=\'Layer 1\' inkscape:groupmode=\'layer\' id=\'layer1\' transform=\'translate(0,-283.77083)\'/%3E%3Cg id=\'g5593\' inkscape:groupmode=\'layer\' inkscape:label=\'Layer 1 copy\' transform=\'translate(0,-283.77083)\'%3E%3Cg id=\'g5631\' transform=\'matrix(0.07261701,0,0,0.06654827,22.47618,266.39705)\'%3E%3Cg transform=\'translate(53.483632,14.363096)\' id=\'g5563\'%3E%3Cg id=\'g5583\'%3E%3Cpath sodipodi:nodetypes=\'ccscc\' inkscape:connector-curvature=\'0\' id=\'path5006\' d=\'M 0,296.73272 200.18487,297 c 0,0 20.17525,0.18899 19.98626,-10.20535 -0.18899,-10.39437 -20.22173,-9.82739 -20.22173,-9.82739 V 297\' style=\'fill:url(%23linearGradient5014);fill-opacity:1;stroke:%23000000;stroke-width:5.88349977;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1\'/%3E%3Cpath inkscape:connector-curvature=\'0\' id=\'path5559\' d=\'m 0,396.95879 200.05124,0.13364 c 0,0 19.91158,0.13364 19.91158,-10.0226 0,-10.15624 0.11382,-100.13344 0.11382,-100.13344\' style=\'fill:none;stroke:%23000000;stroke-width:5.88349977;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1\'/%3E%3C/g%3E%3C/g%3E%3Cg id=\'g5591\' transform=\'matrix(-1,0,0,1,53.483631,14.363095)\'%3E%3Cg id=\'g5589\'%3E%3Cpath sodipodi:nodetypes=\'ccscc\' style=\'fill:url(%23linearGradient5595);fill-opacity:1;stroke:%23000000;stroke-width:5.88349977;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1\' d=\'M 0,296.73272 200.18487,297 c 0,0 20.17525,0.18899 19.98626,-10.20535 -0.18899,-10.39437 -20.22173,-9.82739 -20.22173,-9.82739 V 297\' id=\'path5585\' inkscape:connector-curvature=\'0\'/%3E%3Cpath style=\'fill:none;stroke:%23000000;stroke-width:5.88349977;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1\' d=\'m 0,396.95879 200.05124,0.13364 c 0,0 19.91158,0.13364 19.91158,-10.0226 0,-10.15624 0.11382,-100.13344 0.11382,-100.13344\' id=\'path5587\' inkscape:connector-curvature=\'0\'/%3E%3C/g%3E%3C/g%3E%3C/g%3E%3Cpath style=\'opacity:1;fill:%23009090;fill-opacity:1;stroke-width:1.92377955;stroke-miterlimit:4;stroke-dasharray:none\' d=\'m 42.067209,37.227156 c -1.159816,-0.282393 -2.061416,-0.8078 -2.343848,-1.365875 -0.168942,-0.333825 -0.221602,-3.242222 -0.223614,-12.350274 l -0.0026,-11.913621 0.580357,0.342052 c 1.631208,0.961406 -2.048908,0.90521 59.423933,0.907411 41.696823,0.0015 56.959473,-0.05174 57.678573,-0.201167 0.53781,-0.111759 1.31937,-0.390398 1.73678,-0.619199 l 0.75893,-0.416 v 12.105936 12.105935 l -0.45791,0.457903 c -0.25184,0.251847 -0.83443,0.604322 -1.29464,0.783279 -0.80269,0.312134 -3.15868,0.326604 -57.89031,0.35553 -44.961181,0.02376 -57.246877,-0.01691 -57.965618,-0.19191 z\' id=\'path5633\' inkscape:connector-curvature=\'0\' transform=\'matrix(0.26458333,0,0,0.26458333,0,283.77083)\'/%3E%3C/g%3E%3C/svg%3E") center 40%/cover no-repeat';
  136.  
  137. var customInput = document.getElementById('ys_custom_input_desktop');
  138. var customSelect = document.getElementById('ys_custom_select_desktop');
  139.  
  140. var option = document.createElement('option');
  141. option.style.background = '#1f1f1f';
  142. option.style.color = '#ccc';
  143. option.innerHTML = '????';
  144. option.value = '';
  145. option.default = true;
  146. option.hidden = true;
  147. customSelect.appendChild(option);
  148.  
  149. for (let i = 0, l = surveys.length; i < l; i++) {
  150. let opt = option.cloneNode();
  151. opt.default = false;
  152. opt.hidden = false;
  153. opt.innerHTML = surveys[i].payout;
  154. opt.value = surveys[i].id;
  155. customSelect.appendChild(opt);
  156. }
  157.  
  158. customInput.addEventListener('input', updateDesktopSelect);
  159. customSelect.addEventListener('change', updateDesktopInput);
  160.  
  161. customInput.value = customSelect.value = surveys[0].id;
  162. updateDesktopLink(surveys[0].id);
  163.  
  164. //
  165. // --- SMALL SCREEN / MOBILE ENTRY ---
  166. //
  167. customTitles[1].innerHTML = '<span onclick="return false;" style="user-select: all; cursor: text; background: #728e8e;color: #fff;text-shadow: 1px 1px #222;padding: 2px 5px;font-size: 14px;border-radius: 3px;margin-right: 5px;display: inline-block;">12345678</span>Custom entry not yet supported on screen size.';
  168. }
  169.  
  170. function onYsUnload() {
  171. //spAlert('(ysapi+) ys unloaded!');
  172. }
  173.  
  174. function updateDesktopInput() {
  175. var customInput = document.getElementById('ys_custom_input_desktop');
  176. var customSelect = document.getElementById('ys_custom_select_desktop');
  177.  
  178. customInput.value = customSelect.value;
  179.  
  180. updateDesktopLink(customInput.value);
  181. }
  182.  
  183. function updateDesktopSelect() {
  184. var customInput = document.getElementById('ys_custom_input_desktop');
  185. var customSelect = document.getElementById('ys_custom_select_desktop');
  186.  
  187. customInput.value = customInput.value.replace(/[^\d]+/g, '');
  188.  
  189. if (surveys.find(s => s.id === parseInt(customInput.value, 10))) {
  190. customSelect.value = customInput.value;
  191. } else {
  192. customSelect.value = '';
  193. }
  194.  
  195. updateDesktopLink(customInput.value);
  196. }
  197.  
  198. function updateDesktopLink(surveyId) {
  199. var customLink = document.getElementById('ys_custom_link_desktop');
  200. customLink.href = 'https://www.your-surveys.com/?si=157&ssi=' + spGet('userId') + '&offer_id=' + surveyId;
  201. }
  202.  
  203. // Getter method, cause why not
  204. function spGet(k) {
  205. return window.sp[k];
  206. }
  207.  
  208. // Setter method, cause why not
  209. function spSet(k, v) {
  210. return (window.sp[k] = v);
  211. }
  212.  
  213. // Shorter calls to window.sp.alert
  214. function spAlert(msg) {
  215. return window.sp.alert(msg);
  216. }
  217.  
  218. // Shorter calls to window.sp.alertHTML
  219. function spAlertHTML(msg) {
  220. return window.sp.alertHTML(msg);
  221. }
  222.  
  223. // Wrapper for sp event listeners
  224. function spListen(e, c) {
  225. window.addEventListener('sp' + e[0].toUpperCase() + e.substr(1), c);
  226. }
  227.  
  228. // Wrapper to delete sp event listeners
  229. function spRemoveListener(e, c) {
  230. window.removeEventListener('sp' + e[0].toUpperCase() + e.substr(1), c);
  231. }
  232.  
  233. // Start a 10 second timer, which should later be cancelled by the init event
  234. // If it doesn't get cancelled, sp hasn't dispatched the ready event for over 10 secs, and so likely isn't present
  235. var readyTimer = setTimeout(() => {
  236. alert('[YS-API+] Script engine doesn\'t seem to be present (or took longer than 10 seconds to initialize). Make sure it\'s installed and contact Limit if you still have problems.');
  237. }, 10000);
  238.  
  239. // If sp is already ready, run init, else add a listener for the 'spReady' event
  240. (window.sp && window.sp.ready) ? init() : spListen('ready', init);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement