Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name profoot_coeff
- // @namespace http://pfpf
- // @version 0.1
- // @description Show team coeff for profoot
- // @author karma
- // @match http://109.234.156.5/*
- // @match https://game.pfm.su/*
- // @require http://code.jquery.com/jquery-latest.js
- // http://keith-wood.name/js/jquery.plugin.js
- // http://keith-wood.name/js/jquery.countdown.js
- // @require http://rendro.github.io/countdown/javascripts/jquery.countdown.js
- // @grant GM_setValue
- // @grant GM_getValue
- // ==/UserScript==
- (function(){
- console.log("pf-coeff started");
- if (window.top === window.self) {
- console.log("dropping " + document.location.href);
- return;
- }
- function get_str_num (o) {
- var t = o.text();
- var tt = o.attr("title");
- if (!isNaN(t)) {
- return +t;
- }
- tt = tt.replace(/[^0-9]/g, "")
- if (!isNaN(tt)) {
- return +tt;
- }
- console.log("ERROR: t = " + t + " tt = " + tt);
- return 0;
- }
- $(window).bind('load', function() {
- if (!$(".nt-title").length) {
- console.log("pf-coeff: dropping");
- return;
- }
- var link_ref= $("center .itext2").first();
- var link = link_ref.val();
- var tmp = link.split("=");
- var id = parseInt(tmp[1],10)
- var html;
- var dom;
- var res;
- var min_tdate = 0;
- var num_train = 0;
- $(document).find("div.pb-stat").find("img").each(function() {
- var t = $(this).attr("title");
- var re = /тренировка до (.*)/;
- var a = t.match(re);
- if (a != null) {
- num_train++;
- console.log(a[1]);
- var tmp1 = a[1].split(" ");
- var tmp2 = tmp1[0].split(".");
- var tmp3 = tmp1[1].split(":");
- //console.log(tmp2);
- var d = new Date(tmp2[2],parseInt(tmp2[1])-1,tmp2[0], tmp3[0], tmp3[1]);
- //console.log(d);
- // console.log(d);
- if (min_tdate == 0 || d < min_tdate) {
- min_tdate = d;
- }
- } else {
- console.log('not matched');
- }
- });
- //$(".nt-title").append("<b> TEST </b>");
- if (min_tdate != 0) {
- console.log(min_tdate);
- }
- if (isNaN(id)) {
- console.log("failed to get team id");
- }
- console.log(id);
- $.post("ajax/profile.php",{ "id":id },
- function(data) {
- var gk_min = 0, gk_max = 0, fr_min = 0, fr_max = 0, mid_min = 0, mid_max = 0, def_min = 0, def_max = 0;
- var pa = {};
- var tdate = 0;
- var balance = 1;
- res = data.split('|');
- html = res[1];
- dom = $(html);
- //console.log(html);
- //console.log(dom);
- //dom.find("#pb");
- var dft = dom.find('#df_table').children().first();
- var mdt = dom.find('#md_table').children().first();
- var frt = dom.find('#fr_table').children().first();
- var ft = dom.find('#formation_table').text().trim();
- dft = get_str_num(dft);
- mdt = get_str_num(mdt);
- frt = get_str_num(frt);
- var sch = ft.split("-");
- var dfn = parseInt(sch[0]);
- var mdn = parseInt(sch[1]);
- var frn = parseInt(sch[2]);
- var dfr = dft/dfn;
- var mdr = mdt/mdn;
- var frr = frt/frn;
- var balmsg = "";
- /*
- console.log(dft);
- console.log(dfn);
- console.log(dfr);
- console.log(mdr);
- console.log(frr);
- */
- $(".nt-head-title").append(dfr + "-" + mdr + "-" + frr);
- if (dfr >= 2*mdr) {
- balance = 0;
- balmsg += 'ЗП ';
- }
- if (dfr >= 2*frr) {
- balance = 0;
- balmsg += 'ЗН ';
- }
- if (frr >= 2*dfr) {
- balance = 0;
- balmsg += 'НЗ ';
- }
- if (frr >= 2*mdr) {
- balance = 0;
- balmsg += 'НП ';
- }
- if (mdr >= 2*dfr) {
- balance = 0;
- balmsg += 'ПЗ ';
- }
- if (mdr >= 2*frr) {
- balance = 0;
- balmsg += 'ПН ';
- }
- if (balance) {
- $("#special-offer").append("<font color='green' style='background-color:black;font-size:30px;'><b>Баланс</b></font")
- } else {
- $("#special-offer").append("<font color='red' style='background-color:black;font-size:30px;'><b>Дисбаланс (" + balmsg + ")</b></font")
- }
- dom.find(".pb-cont").each(function() {
- //console.log($(this));
- var t = $(this).find(".pb-t").first().text();
- var rate = $(this).find(".pb-r").first().text();
- var name = $(this).find(".pb-n").first().text();
- pa[name] = rate;
- //console.log(rate);
- //console.log(t);
- var r = parseInt(rate, 10);
- if (isNaN(r)) {
- console.log("can't parse rate");
- }
- if (t === "Г") {
- if (gk_min == 0) {
- gk_min = r;
- }
- if (gk_max == 0) {
- gk_max = r;
- }
- if (r < gk_min) {
- gk_min = r;
- }
- if (r > gk_max) {
- gk_max = r;
- }
- } else if (t === "З") {
- if (def_min == 0) {
- def_min = r;
- }
- if (def_max == 0) {
- def_max = r;
- }
- if (r < def_min) {
- def_min = r;
- }
- if (r > gk_max) {
- gk_ax = r;
- }
- } else if (t === "П") {
- if (mid_min == 0) {
- mid_min = r;
- }
- if (mid_max == 0) {
- mid_max = r;
- }
- if (r < mid_min) {
- mid_min = r;
- }
- if (r > mid_max) {
- mid_max = r;
- }
- } else if (t === "Н") {
- if (fr_min == 0) {
- fr_min = r;
- }
- if (fr_max == 0) {
- fr_max = r;
- }
- if (r < fr_min) {
- fr_min = r;
- }
- if (r > fr_max) {
- fr_max = r;
- }
- }
- //console.log(t + ' ' + r);
- //console.log(pa);
- });
- var gk_rate = gk_max/gk_min;
- var fr_rate = fr_max/fr_min;
- var mid_rate = mid_max/mid_min;
- var def_rate = def_max/def_min;
- /*
- console.log(gk_rate);
- console.log(def_rate);
- console.log(mid_rate);
- console.log(fr_rate);
- console.log(pa);
- */
- $(".pb-cont").each(function() {
- var e = $(this) .find(".pb-n").first();
- var n = e.text();
- //console.log(n);
- e.append("<div id='pb-rate' style='border: 1px solid black'>"+pa[n]+"</div>");
- //console.log(pa[n]);
- });
- $(".nt-title").append("<font color='gray'> <b>" + gk_rate.toFixed(2) + "</font>/<font color='green'>" + def_rate.toFixed(2) + "</font>/<font color='orange'>" + mid_rate.toFixed(2) + "</font>/<font color='red'>" + fr_rate.toFixed(2) + "</b> </font>");
- //var pbs = dom.jQuery("#pb");
- //console.log(pbs);
- // html = $.parseHTML(res[1]);
- // console.log(html);
- $(".head-right").prepend("<div id='tmsg' style='color:red'></div><div id='countdown'> </div>");
- if (num_train == 0) {
- $("#tmsg").html("Требуем зарплату!");
- console.log("HERE!");
- } else if (num_train < 4) {
- $("#tmsg").html("Хотим аванс!");
- }
- if (min_tdate != 0) {
- console.log(min_tdate);
- $("#countdown").countdown({date:min_tdate, render: function(data) {
- $(this.el).html("<b>" + data.days + " <span> дней </span>" + data.hours + " <span> часов </span>" + data.min + " <span> минут </span>" + data.sec + " <span> секунд</span></b>");
- }});
- }
- });
- });
- /*
- var observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- console.log(mutation);
- });
- });
- var target = document.querySelector('#popup');
- observer.observe(target, { attributes: true, attributeOldValue:true, subtree: true, characterData: true, childList: true });
- $("#popup").on("appear")
- */
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement