Articles: Швидкі матчі

17.12.2014

Написаний черговий користувацький сценарій. Призначений тупо для автоклікання "Швидкі матчі" — "Середній суперник" (5-й з 9) — "Пропустити трансляцію" — знову "Швидкі матчі"... І так аж доки не скінчаться безкоштовні виклики у даному виді спорту ("Free challenges: 0/...").

http://dyingescape.0fees.net/st/autogames.user.js

 

Код:

// ==UserScript==
// @name       autogames
// @namespace  http://dyingescape.0fees.net/
// @version    0.1
// @description  Autogames
// @match      http://*.powerplaymanager.com/*
// @author     Oleksa Vyshnivsky a.k.a. ODE
// @copyright  2014+, Oleksa Vyshnivsky a.k.a. ODE
// @grant      none
// ==/UserScript==

// List of pages to upload (at least in the first version)
var userdata = []
var sport = 'hockey'

// Визначення виду спорту
function checkSport() {
    var sports = ['hockey', 'soccer', 'handball', 'basketball']
    $.each(sports, function(i, key) {
        if (window.location.href.indexOf(key) > -1) {
            sport = key
            return false
        }
    })
}

// Add buttons to the document
function addButtons() {
    // Uploading the data "After the last race" (before the start of preperation to the next race)
    var html = ''
    $('body').append(html)
    $('#btnDoAutogames').click(doAutogames)
    
    // Opacity under cursor
    $('[data-ode-button]').hover(function(e) { $(this).css('opacity', e.type === "mouseenter" ? 1 : 0.8)})
}

function doAutogames() {
   // if (!userdata || userdata == []) return false
    
    //var link = "http://" + sport + ".powerplaymanager.com/_action/action_team.php?action=instantChallenge&id_team=7666&return_page=http%3A%2F%2Fhockey.powerplaymanager.com%2Fuk%2Finstant-challenges.html%3Fdata%3Drivals"
    //var link = "http://" + sport + ".powerplaymanager.com/uk/instant-challenges.html?data=rivals"
    window.location.href = 'http://' + sport + '.powerplaymanager.com/uk/instant-challenges.html'
}

function autogames() {
    if (window.location.href === 'http://' + sport + '.powerplaymanager.com/uk/instant-challenges.html') {
        // Кількість безкоштовних викликів, які залишилися
        var match = $('.select_form').html().match(/\d+/)
        var left = parseInt(match[0], 10)
        // Вибір суперника
        if (left > 0) {
            var form = $('form[name=fr]')[4]
        	$(form).submit()
        }
    } else if (window.location.href.indexOf('broadcast.html?data=ic-') > -1) {
        // Пропуск трансляції
        var a = $('a[href*=ic-]')[0]
        window.location.href = $(a).attr('href')
    } else if (window.location.href.indexOf('summary.html?data=ic-') > -1 || window.location.href.indexOf('report.html?data=ic-') > -1) {
        // Повернення до викликів
        window.location.href = 'http://' + sport + '.powerplaymanager.com/uk/instant-challenges.html'
    }
}

// WHEN THE PAGE IS FULLY LOADED
$(function() {
    // What sport is it
    checkSport()
    
    // Check if autoupload of this page to PumaGP website is needed (and do it and automatically reload page if needed)
    if (autogames()) return false
    
    // Show "Control box"
    addButtons()
})