Advertisement
Guest User

ScriptAW

a guest
Apr 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Alienware Arena helper
  3. // @namespace    https://github.com/thomas-ashcraft
  4. // @version      0.1.0
  5. // @description  Earn daily ARP easily
  6. // @author       Thomas Ashcraft
  7. // @match        *://*.alienwarearena.com/*
  8. // @match        *://*.alienwarearena.com//*
  9. // @grant        none
  10. // @noframes
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.     var DEBUG = false;
  15.  
  16.     var url = window.location.href;
  17.     if(DEBUG) console.log("🐾 url: " + url);
  18.  
  19.     var path = window.location.pathname;
  20.     path = path.replace(/\/+/g, "/");
  21.     if(DEBUG) console.log("🐾 path: " + path);
  22.  
  23.     var referrer = document.referrer;
  24.     if(DEBUG) console.log("🐾 referrer: " + referrer);
  25.  
  26.     // Embed style
  27.     var helper_style = `
  28.         #background {}
  29.         .awah-btn-tots {background-color: #f05000;}
  30.         .awah-arp-pts {float: left; clear: both; font-size: smaller !important;}
  31.         .awah-btn-cons {color: gold;}
  32.         `;
  33.     document.head.appendChild(document.createElement('style')).innerHTML=helper_style.replace(/([\s\S]*?return;){2}([\s\S]*)}/,'$2');
  34.  
  35.     // ARP points initial readings
  36.     var pm_counter = /Vote on Content(?:.|\n)*>(\d+) of (\d+)<\/td>(?:.|\n)*Vote on This or That(?:.|\n)*>(\d+) of (\d+)<\/td>/.exec($("head").html());
  37.     votes_content_cur = parseInt(pm_counter[1], 10);
  38.     votes_content_max = parseInt(pm_counter[2], 10);
  39.     votes_tot_cur = parseInt(pm_counter[3], 10);
  40.     votes_tot_max = parseInt(pm_counter[4], 10);
  41.     votes_content_promised = 0;
  42.     votes_content_action = false;
  43.     //$("div.toast-header").append('<span class="toast-title awah-arp-pts" style="float: left; clear: both;">asdf</span>');
  44.     //$("head").html($("head").html().replace('<span data-notify="title" class="toast-title">ARP STATUS <span class="odometer" id="arp-status-total"></span></span>',
  45.     //  '<span data-notify="title" class="toast-title">ARP STATUS <span class="odometer" id="arp-status-total"></span></span> <span class="toast-title awah-arp-pts" style="float: left; clear: both;"></span>'));
  46.     //$("div.toast-header").text("CON: " + votes_content_cur + " / " + votes_content_max + " | TOT: " + votes_tot_cur  + " / " + votes_tot_max);
  47.     //$(".awah-arp-pts").html("CON: " + votes_content_cur + " / " + votes_content_max + " <br> TOT: " + votes_tot_cur  + " / " + votes_tot_max);
  48.     setTimeout(function() {
  49.         $("div.toast-header").append('<span class="toast-title awah-arp-pts">asdf</span>');
  50.         arp_pts_status_update();
  51.     }, 1);
  52.  
  53.     // ARP points watchdog
  54.     $(document).ajaxComplete(function(event, xhr, settings) {
  55.         if (settings.url.indexOf("this-or-that/vote") >=0) {
  56.             votes_tot_cur++;
  57.             arp_pts_status_update();
  58.         } else if (settings.url.indexOf("vote") >=0) {
  59.             data = JSON.parse(xhr.responseText);
  60.             if (data.votedForContent) {
  61.                 votes_content_cur++;
  62.             }
  63.             if (data.votedForContent === false) {
  64.                 votes_content_cur--;
  65.             }
  66.             arp_pts_status_update();
  67.         }
  68.     });
  69.    
  70.     function arp_pts_status_update() {
  71.         //$("div.toast-header").text("CON: " + votes_content_cur + " / " + votes_content_max + " | TOT: " + votes_tot_cur  + " / " + votes_tot_max);
  72.         $(".awah-arp-pts").html("CON: " + votes_content_cur + " / " + votes_content_max + " <br> TOT: " + votes_tot_cur  + " / " + votes_tot_max);
  73.     }
  74.  
  75.     function scrl (target) {
  76.         $('html, body').animate({scrollTop: target.offset().top-100}, 800);
  77.         //target.effect("highlight", "800");
  78.     }
  79.  
  80.     function all_feeds_functions() {
  81.         //fix_gleam_url();
  82.         fix_links();
  83.  
  84.         $(document).ajaxComplete(function(event, xhr, settings) {
  85.             if (settings.url.indexOf("twitmode=1") >=0) {
  86.                 fix_links();
  87.             }
  88.         });
  89.     }
  90.  
  91.     function this_or_that_spam() {
  92.         if (!$("a.btn-show-vote").hasClass("hidden")) {
  93.             $("a.btn-show-vote").click(); //turn page into voting mode
  94.         }
  95.         //create catch event to click again
  96.         // settings.url == /this-or-that/1516182/create-match
  97.         // where "1516182" is a topic ID
  98.         $(document).ajaxComplete(function(event, xhr, settings) {
  99.             if (settings.url.indexOf("create-match") >=0 && votes_tot_cur < votes_tot_max) {
  100.                 $("div.vote-container a.expand").filter(":first").click();
  101.             }
  102.         });
  103.         $("div.vote-container a.expand").filter(":first").click(); //click to launch spam
  104.     }
  105.  
  106.     function this_or_that_btn() {
  107.         $(".btn-show-vote").clone().removeClass("btn-show-vote").addClass("awah-btn-tots").appendTo(".btn-group-sm");
  108.         $(".awah-btn-tots span.hidden-xs").text("Spam TOT votes");
  109.         $(".awah-btn-tots").on("click", function() {
  110.             $(".awah-btn-tots").addClass("hidden");
  111.             this_or_that_spam(); //show must go on
  112.         });
  113.     }
  114.  
  115.     function votes_content_spam() {
  116.         // i.fa-arrow-up not style="color: gold;" //comment
  117.         // i.fa-chevron-up not style="color: gold;" //post
  118.         //votes_content_promised = votes_content_cur;
  119.  
  120.         $("i.fa-arrow-up:not([style='color: gold;'])").each(function( index ) {
  121.             if ((votes_content_cur + votes_content_promised) < votes_content_max) {
  122.                 votes_content_promised++;
  123.                 this.click();
  124.                 $(".awah-arp-pts").text("votes incoming: " + votes_content_promised);
  125.             } else {
  126.                 $(".awah-arp-pts").html("votes incoming: " + votes_content_promised + "<br>Enough votes");
  127.                 votes_content_action = false;
  128.                 return false;
  129.             }
  130.         });
  131.         if (votes_content_promised == 0 && votes_content_action) {
  132.             $(".awah-arp-pts").text("Getting to the next page");
  133.             votes_content_next_page();
  134.         }
  135.     }
  136.  
  137.     function votes_content_next_page() {
  138.         $("ul.pagination > li.next > a").filter(":first").click();
  139.     }
  140.  
  141.     function votes_content_algorithm() {
  142.         votes_content_action = true;
  143.  
  144.         //wait for promises complete and go to next content page
  145.         //also wait for next page load
  146.         $(document).ajaxComplete(function(event, xhr, settings) {
  147.             if (votes_content_action) {
  148.                 if (settings.url.indexOf("ucf/comments") >=0) {
  149.                     votes_content_spam();
  150.                 } else if (settings.url.indexOf("vote") >=0) {
  151.                     data = JSON.parse(xhr.responseText);
  152.                     if (typeof data.votedForContent !== 'undefined') {
  153.                         votes_content_promised--;
  154.                         if (votes_content_promised == 0) {
  155.                             votes_content_next_page();
  156.                         }
  157.                     }
  158.                 }
  159.             }
  160.         });
  161.  
  162.         votes_content_spam();
  163.     }
  164.  
  165.     function votes_content_btn() {
  166.         $('<a class="btn btn-default text-uppercase awah-btn-cons" href="javascript:void(0);">' +
  167.             '<i class="fa fa-arrow-up" style="color: gold;"></i> ' +
  168.             '<span class="hidden-xs">Spam CON votes</span></a>').appendTo(".btn-group-sm");
  169.         $(".awah-btn-cons").on("click", function() {
  170.             $(".awah-btn-cons").addClass("hidden");
  171.             votes_content_algorithm(); //show must go on
  172.         });
  173.     }
  174.  
  175.     switch (true) {
  176.         case /.*\/boards\/this-or-that\/.*/.test(path):
  177.             if(DEBUG) console.log("SWITCH: This or That");
  178.             //fix_gleam_url();
  179.             this_or_that_btn();
  180.             //break;
  181.         case /.*\/ucf\/show\/.*/.test(path):
  182.             if(DEBUG) console.log("SWITCH: content");
  183.             votes_content_btn();
  184.             break;
  185.         case /\/$/.test(url):
  186.             if(DEBUG) console.log("SWITCH: 📰 main page");
  187.             //all_feeds_functions();
  188.             break;
  189.     }
  190.  
  191.     // Embed functions to be called directly from the UI in *-monkey installations
  192.     function embedFunction(s) {
  193.         if(DEBUG) console.log('🔀 embedding: ' + s.name);
  194.         document.body.appendChild(document.createElement('script')).innerHTML=s.toString().replace(/([\s\S]*?return;){2}([\s\S]*)}/,'$2');
  195.     }
  196.  
  197. // embed other functions used by UI after loading
  198.     embedFunction(scrl);
  199.     //embedFunction(this_or_that_spam);
  200.  
  201. }(window));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement