NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name A9 ht bettable // @namespace http://tampermonkey.net/ // @version 0.1 // @author akznuts // @license MIT // @match http://a9cp.a97766.com/transaction/transactionBettingRecord // @require http://code.jquery.com/jquery-3.4.1.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.js // @grant none // ==/UserScript== (function () { 'use strict'; // Your code here... setTimeout(function () { //sortBtn(); }, 3000); $(document).keydown(function (e) { if (e.which == 113) { sortTable(); return false; } }); })(); function sortBtn() { var dt_btn = $('<button class="el-button el-button--primary el-button--mini">Sort Table</button>'); $('.el-form-item.post-btn.el-form-item--min .el-form-item__content').prepend(dt_btn); dt_btn.click(function () { $('tr.td-background').remove(); //$('table.lottery-table').DataTable().clear().destroy(); sortTable(); }) } function sortTable2() { var cnt = 0; var table, rows, switching, i, x, y, shouldSwitch; table = $('table.lottery-table')[0]; switching = true; /* Make a loop that will continue until no switching has been done: */ while (switching) { // Start by saying: no switching is done: switching = false; rows = table.rows; /* Loop through all table rows (except the first, which contains table headers): */ for (i = 1; i < (rows.length - 1); i++) { // Start by saying there should be no switching: shouldSwitch = false; /* Get the two elements you want to compare, one from current row and one from the next: */ x = $(rows[i].getElementsByTagName("TD")[6]).innerText; y = $(rows[i + 1].getElementsByTagName("TD")[6]).innerText; // Check if the two rows should switch place: if (isNaN(y)) { shouldSwitch = true; break; } // console.log($(y).innerText); if (parseFloat(x.innerHTML) > parseFloat(y.innerHTML)) { // If so, mark as a switch and break the loop: shouldSwitch = true; break; } } if (shouldSwitch) { /* If a switch has been marked, make the switch and mark that a switch has been done: */ //rows[i].parentNode.insertBefore(rows[i + 1], rows[i]); $(rows[i]).parent().before(rows[i + 1], rows[i]); switching = true; } cnt += 1; if (cnt >= 1000) { break; } console.log(switching); } } function sortTable(order) { var asc = order === 'asc', tbody = $('table.lottery-table').find('tbody'); tbody.find('tr').sort(function (a, b) { if (asc) { return compare(parseFloat($('td:nth-child(7)', a).text()), parseFloat($('td:nth-child(7)', b).text())); } else { return compare(parseFloat($('td:nth-child(7)', b).text()), parseFloat($('td:nth-child(7)', a).text())); } // return false; }).appendTo(tbody); } function compare(a, b) { var ans = a - b; // console.log(ans); // if(ans > 0){ // return true; // } else { // return false; // } return a - b; }