maha4india / Tocner_1.5

// ==UserScript==
// @name         Tocner_1.5
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @license      MIT
// @match        https://www.totalcorner.com/match/*
// @grant        none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// ==/UserScript==
(function() {
    'use strict';
    var $ = window.jQuery;

    // Delete divs
    //HideDIV('navbar');
    HideDIV('carousel-banner-container');
    HideDIV('carousel-banner');
    HideDIV('navbar-right.btn-group.pull-right');

    var test = $('<button>Run Me</button>').click(function () {
        Main();
    });
    $(".navbar").append('<tr><td></td></tr>').find("td:last").append(test);

    return false;

    function Main()
    {
        var isDelete;
        var deletedRows = 0;

        $('.container').empty();
        var tbl = document.getElementById('inplay_match_table');
        var i;

        //('#container').append('<table width="320" border="3"><tr><td colspan="2" rowspan="1">' + " wdw" + '</td></tr><tr><td width="118">' + "sxs" + '</td><td width="186">' + "xs" + '</td></tr></table>');

        //for (i = tbl.rows.length - 1; i >= 3; i--)

        //     $('.container').load('https://www.totalcorner.com/match/corner-stats/83037923/ #place_bet_div');
        //     //$('#inplay_match_table').load('https://www.totalcorner.com/match/corner-stats/83037923/ #home_history_table');

        //     var temps = $('.container').children('table').first().empty();
        //     alert($(".container").find('table').length);
        //     temps.empty();
        //     return false;

        $('.col-xs-12.col-sm-9').empty();
        //$('.col-xs-12').empty();
        $('.col-xs-12.col-sm-9').append('<table border="3" width="100%" ID="MyTable" align="left"/>' );
        //         $('.col-xs-12.col-sm-9').append('<table border="3" width="100%" ID="MyTableOK" align="left"/>' );
        $('.col-xs-12.col-sm-9 table').append($('#inplay_match_table tr')[0]);

        for( i = 3; i < tbl.rows.length; i++ )
            //for( i = 3; i < 4; i++ )
        {
            var vntTime;
            var vntAttack;
            var vntShots;
            var vntCornerLink;
            var vntScore;
            var vntHome;
            var vntAway;
            //alert(i);
            vntTime = tbl.rows[ i ].cells[ 3 ].innerText.trim();
            vntTime = vntTime.replace( /\D+$/, '');
            //alert(vntTime);

            if (vntTime.substring(0, 2) == "Ha")
            {
                //tbl.rows[ i ].cells[ 3 ].innerText = '45';
                tbl.rows[ i ].cells[ 3 ].getElementsByClassName('match_status_minutes')[0].textContent = '45';
                vntTime = 45;
            }
            vntTime = vntTime.replace( /\D+$/, '');

            vntAttack = tbl.rows[ i ].cells[ 11 ].getElementsByClassName('match_dangerous_attacks_div')[0].textContent;
            vntShots = tbl.rows[ i ].cells[ 12 ].getElementsByClassName('match_shoot_div')[0].textContent;
            vntCornerLink = tbl.rows[ i ].cells[ 14 ]
            vntScore = tbl.rows[ i ].cells[ 5 ].innerText.trim()

            vntHome = tbl.rows[ i ].cells[ 4 ].innerText.trim()
            vntAway = tbl.rows[ i ].cells[ 6 ].innerText.trim()

            var vntMatchLink = vntCornerLink.getElementsByTagName('a')[0];

            //alert('before call');

            isDelete = "False";
            //         if (vntTime > 79)
            //         {
            //             isDelete = "True";
            //         }

            if (isDelete == "False")
            {
                try
                {
                    var fieldsAttack = vntAttack.split('-');
                    var fieldsShots= vntShots.split('-');

                    //alert(fields);
                    var HomeAttack = fieldsAttack[0].trim();
                    var AwayAttack = fieldsAttack[1].trim();
                    var HomeShots = fieldsShots[0].trim();
                    var AwayShots = fieldsShots[1].trim();

                }
                catch(ex){HomeAttack = AwayAttack = HomeShots = AwayShots = 0;}

                try
                {
                    var fieldsScore = vntScore.split('-');
                    var HomeScore = fieldsScore[0].trim();
                    var AwayScore = fieldsScore[1].trim();
                }catch(ex){HomeScore = AwayScore = 0;}

                var blnWrite = 'False';
                if (HomeAttack>0 && AwayAttack>0)
                {
                    //alert('yes');
                    var diff;
                    var diffShot;
                    var existScore;
                    diff = parseInt(HomeAttack) - parseInt(AwayAttack);
                    diffShot = parseInt(HomeShots) - parseInt(AwayShots);
                    existScore = tbl.rows[ i ].cells[ 5 ].innerText;
                    HomeScore = parseInt(HomeScore);
                    AwayScore = parseInt(AwayScore);
                    //alert(diffShot);
                    //alert(existScore);
                    tbl.rows[ i ].cells[ 2 ].innerText = existScore + '   (  ' + diff + ' ) ( ' + diffShot + ' )';
                    tbl.rows[ i ].cells[ 2 ].style.fontWeight = "900";

                    diff = parseInt(diff);

                    var vntColor;
                    if (diff > 7)
                    {
                        if (HomeScore > AwayScore)
                        {
                            vntColor = "Black"
                            tbl.rows[ i ].cells[ 2 ].innerText = "H Adv  = " + tbl.rows[ i ].cells[ 2 ].innerText;
                        }
                        if (HomeScore == AwayScore)
                        {
                            vntColor = "MediumSeaGreen"
                            tbl.rows[ i ].cells[ 2 ].innerText = "H EQ  = " + tbl.rows[ i ].cells[ 2 ].innerText;
                            blnWrite = 'True';
                        }
                        if (HomeScore < AwayScore)
                        {
                            vntColor = "Orange"
                            tbl.rows[ i ].cells[ 2 ].innerText = "H Beh  = " + tbl.rows[ i ].cells[ 2 ].innerText;
                            blnWrite = 'True';
                        }
                        tbl.rows[ i ].cells[ 2 ].style.color = vntColor;

                        if (diff > 12)
                        {
                            tbl.rows[ i ].cells[ 2 ].innerText = "SS " + tbl.rows[ i ].cells[ 2 ].innerText;
                        }
                    }
                    else if (diff < -7)
                    {
                        if (HomeScore > AwayScore)
                        {
                            vntColor = "Orange"
                            tbl.rows[ i ].cells[ 2 ].innerText = "A Beh  = " + tbl.rows[ i ].cells[ 2 ].innerText;
                            blnWrite = 'True';
                        }
                        if (HomeScore == AwayScore)
                        {
                            vntColor = "MediumSeaGreen"
                            tbl.rows[ i ].cells[ 2 ].innerText = "A EQ  = " + tbl.rows[ i ].cells[ 2 ].innerText;
                            blnWrite = 'True';
                        }
                        if (HomeScore < AwayScore)
                        {
                            vntColor = "Black"
                            tbl.rows[ i ].cells[ 2 ].innerText = "A Adv  = " + tbl.rows[ i ].cells[ 2 ].innerText;
                        }
                        tbl.rows[ i ].cells[ 2 ].style.color = vntColor;

                        if (diff < -12)
                        {
                            tbl.rows[ i ].cells[ 2 ].innerText = "SS " + tbl.rows[ i ].cells[ 2 ].innerText;
                        }
                    }
                    else {
                    }
                }
            }


            var firstLink = document.getElementsByClassName('text-center th_start_time')[0];
            firstLink.style.width = "300px";
            firstLink.style.fontWeight = "900";

            firstLink = document.getElementsByClassName('text-center td_league')[0];
            firstLink.style.width = "300px";

            // Read individual odds
            if (HomeAttack == 0 && AwayAttack == 0)
            {
                var div = $('<div/>');
                //             div.load(vntMatchLink + ' #place_bet_div', function(){handle(div);});
                var currentRow = $('#inplay_match_table tr')[i];
                var cellu = $(currentRow).find('td')[1];
                var $celll = $(cellu);

                $($(currentRow).find('td')[4]).css("font-size", "20px");
                $($(currentRow).find('td')[3]).css("font-size", "15px");
                $($(currentRow).find('td')[2]).css("font-size", "15px");
                $($(currentRow).find('td')[1]).css("font-size", "15px");

                //                 $($(currentRow).find('.btn.btn-default.btn-sm.btn-favrite.star_btn')).trigger("click");

                $($(currentRow).find('td')[2]).css("width", "200px");
                var LiveScor = 'https://www.totalcorner.com' + $(vntMatchLink).attr('href').replace("corner-stats", "odds-handicap");
                try
                {
                    GetValue($celll,vntMatchLink ,".table-bordered.table-condensed-2:first-child tr:nth-child(2)");
                    GetValue($celll,LiveScor ,"#odds_full tbody tr:nth-child(2)");
                    GetValueHistory($celll,vntMatchLink ,"#content_container", "Home", vntHome, vntAway);
                }catch(ex){}

                //if (blnWrite == 'True' && vntTime < 80)
                //{
                //$('.col-xs-12.col-sm-9 table').append($('#inplay_match_table tr')[i]);
                //}
            }
        }

        function GetValue(strWheretoWrite, strReadLink, strReadAttribute)
        {
            var $ = window.jQuery;
            var temp;
            var strConcat;
            //         alert('inside getvalue');

            strConcat = strReadLink + "  " + strReadAttribute;

            var div = $('<Table width="60%" border="1" cellpadding="4"/>');
            div.load(strReadLink + ' ' + strReadAttribute, function(){handle(div);});
            //        alert(strWheretoWrite.find('table').length);

            function handle(element)
            {
                try
                {
                    $(element).find("td:eq(6)").remove()
                    $(element).find("td:eq(5)").remove()
                    if (($(element).find("td:eq(1)").html().indexOf('-') <1))
                    {
                        $(element).find("td:eq(0)").html('Full');
                        //   alert($(element).find("td:eq(0)").html());
                    }
                }catch(ex){}
                $(element).css('border', '1px solid black');
                element.appendTo(strWheretoWrite);
            }
        }

        function GetValueHistory(strWheretoWrite, strReadLink, strReadAttribute, strAppendText, strHome, strAway)
        {
            var $ = window.jQuery;
            var temp;
            var strConcat;
            //         alert('inside getvalue');

            strConcat = strReadLink + "  " + strReadAttribute;

            var div = $('<Body/>');
            try
            {
                //div.load(strReadLink + ' ' + strReadAttribute, function(){handle(div);});
                //        alert(strWheretoWrite.find('table').length);
                div.load(strReadLink + ' ' + strReadAttribute, function(){handle(div);});
            }catch(ex){}

            var tbl;
            var tblH2H;

            tbl = '<Table width="100%" border="3"><tr><td></td><td>Total</td><td>O1</td><td>O2</td><td>BTTS</td><td>1.5%</td></tr>';
            function handle(element)
            {
                var html;
                var incrementor, Over1, Over2, BTTS, incrementorH2H;
                var Over1H2H, Over2H2H, BTTSH2H;
                incrementor = Over1 = Over2 = BTTS = 0;
                incrementorH2H = Over1H2H = Over2H2H = BTTSH2H = 0;
                var finalVal = "";

                var blnIsH2H;
                var H2HString= "";
                var HString= "";
                var AString= "";
                html = $.parseHTML($(element).html());
                //                 alert($(element).html());
                //                 console.log($(element).html());

                var table1 = $(html).find('#head_to_head_history_table').html();
                var table2 = $(html).find('#home_history_table').html();
                var table3 = $(html).find('#away_history_table').html();

                // call generic sub
                // H
                var o1;
                try
                {
                    Generic(table2);
                    table2 = ""
                    o1=0;
                    try{o1 = ((parseInt(Over1H2H)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    HString = "<TR><td>Home</td><td style='font-weight: bold'>" + incrementorH2H + "</td><td>" + Over1H2H + "</td><td>" + Over2H2H + "</td><td>" + BTTSH2H + "</td><td>" + o1 + "</td></TR>";
                }catch(ex){}
                // A
                try
                {
                    Generic(table3);
                    table3 = "";
                    o1=0;
                    try{o1 = ((parseInt(Over1H2H)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    AString = "<TR><td>Away</td><td style='font-weight: bold'>" + incrementorH2H + "</td><td>" + Over1H2H + "</td><td>" + Over2H2H + "</td><td>" + BTTSH2H + "</td><td>" + o1 + "</td></TR>";
                }catch(ex){}
                // H2H

                try
                {
                    Generic(table1);
                    table1 = "";
                    o1=0;
                    try{o1 = ((parseInt(Over1H2H)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    //                 alert(incrementorH2H + " " + Over1H2H + " " + Over2H2H + " " + BTTSH2H);
                    H2HString = "<TR><td>H2H</td><td style='font-weight: bold'>" + incrementorH2H + "</td><td>" + Over1H2H + "</td><td>" + Over2H2H + "</td><td>" + BTTSH2H + "</td><td>" + o1 + "</td></TR>";
                }catch(ex){}

                html = ""
                $($(currentRow).find('td')[4]).css("font-size", "20px");
                finalVal = finalVal + HString + AString + H2HString ;
                finalVal = finalVal.replace(" - ", "-");
                finalVal = tbl + finalVal + '</table>';
                //                alert(finalVal);
                $(finalVal).css('border', '1px solid black');
                $(strWheretoWrite).css('border', '1px solid black');
                //                 alert('olo');
                //                 alert($(finalVal).html());

                $(finalVal).appendTo(strWheretoWrite);

                function Generic(vnttable)
                {
                    incrementorH2H = Over1H2H = Over2H2H = BTTSH2H = 0;
                    for(i = 2; i < $(vnttable).children('tr').length -2; i++ )
                    {
                        var time;
                        var htmltbl = "";
                        //                     alert('insideloop');
                        htmltbl = (vnttable);
                        //                     console.log(htmltbl);
                        //                     console.log(htmltbl.html());
                        var currentRow = $(htmltbl).find('tr')[i];
                        //alert($($(html).find('tr')[1]).html());
                        var cellu = $(currentRow).find('td')[3];
                        //                      alert($(cellu).html());
                        var HomeTeam, AwayTeam;

                        HomeTeam = $($(currentRow).find('td')[2]).text().trim();
                        AwayTeam = $($(currentRow).find('td')[4]).text().trim();
                        HomeTeam = HomeTeam.replace(/[^A-Za-z]+/g, '').trim();
                        AwayTeam = AwayTeam.replace(/[^A-Za-z]+/g, '').trim();
                        strHome = strHome.replace(/[^A-Za-z]+/g, '').trim();
                        strAway = strAway.replace(/[^A-Za-z]+/g, '').trim();

                        var score = "";
                        score = $(cellu).text().replace(/(\r\n|\n|\r)/gm, "/").trim();
                        score = score.substr(score.length - 7);
                        score = score.split("/").join("").trim();

                        // H2H
                        if (incrementorH2H < 5)
                        {
                            var fieldScoreH2H = score.split('-');
                            var HomeScoreH2H = fieldScoreH2H[0].trim();
                            var AwayScoreH2H = fieldScoreH2H[1].trim();

                            HomeScoreH2H = parseInt(HomeScoreH2H);
                            AwayScoreH2H = parseInt(AwayScoreH2H)
                            incrementorH2H = parseInt(incrementorH2H) +1;

                            //                             alert(i);
                            //                             alert(HomeScoreH2H + ' ' + AwayScoreH2H + ' ' + incrementorH2H);

                            // check 1.5
                            if ((parseInt(HomeScoreH2H) + parseInt(AwayScoreH2H)) > 1)
                            {
                                Over1H2H = parseInt(Over1H2H) + 1; //+ '( ' + HomeScoreH2H + '-' + AwayScoreH2H;
                            }

                            // check 2.5
                            if ((parseInt(HomeScoreH2H) + parseInt(AwayScoreH2H)) > 2)
                            {
                                Over2H2H = parseInt(Over2H2H) + 1; //+ '( ' + HomeScoreH2H + '-' + AwayScoreH2H;
                            }

                            // check BTTS
                            if ((parseInt(HomeScoreH2H) >0) && (parseInt(AwayScoreH2H)>0))
                            {
                                BTTSH2H = parseInt(BTTSH2H) + 1; //+ '( ' + HomeScoreH2H + '-' + AwayScoreH2H;
                            }
                        }
                    }
                }
            }
        }

        // remove unwanted cols
        $('.col-xs-12.col-sm-9 table tr').each(function(){

            //$(this).children('td').eq(14).remove();
            $(this).children('td').eq(13).remove();
            $(this).children('td').eq(10).remove();
            $(this).children('td').eq(9).remove();
            $(this).children('td').eq(7).remove();
            $(this).children('td').eq(0).remove();

            $(this).children('th').eq(13).remove();
            $(this).children('th').eq(10).remove();
            $(this).children('th').eq(9).remove();
            $(this).children('th').eq(7).remove();
            $(this).children('th').eq(0).remove();

        });

        $('#inplay_match_table tr').each(function(){

            //$(this).children('td').eq(14).remove();
            $(this).children('td').eq(13).remove();
            $(this).children('td').eq(10).remove();
            $(this).children('td').eq(9).remove();
            $(this).children('td').eq(7).remove();
            $(this).children('td').eq(0).remove();

            //$(this).children('th').eq(14).remove();
            $(this).children('th').eq(13).remove();
            $(this).children('th').eq(10).remove();
            $(this).children('th').eq(9).remove();
            $(this).children('th').eq(7).remove();
            $(this).children('th').eq(0).remove();
        });

        //     $("th").click(function(){
        //       var theLink = $(this).text();
        // //       alert(theLink);
        // //         sortTable(1);
        // });

    }

    function HideDIV(strName)
    {
        var adSidebar = document.getElementById(strName);
        if (adSidebar) {
            adSidebar.parentNode.removeChild(adSidebar);
        }
    }


})();