Build a list
目前為
// ==UserScript==
// @name NewPmRoute
// @namespace https://www.conanluo.com/
// @version 0.1
// @description Build a list
// @author Conan
// @match *://*.conanluo.com/pmroute.html
// @require https://code.jquery.com/jquery-2.2.4.min.js
// @icon https://www.google.com/s2/favicons?sz=64&domain=itinerisonline.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
let drivers=[
"Bert Reid",
"Crystal Calloway",
"Mauricio Reina",
"Yingyang Chen",
"Manuel Reina",
"Jerald Alejandro",
"Walter Mejia",
"Fook Fung",
"Kang Li",
"Han Yang Zhou",
"Wilson Ochoa"
]
function sortBy(keyWord){
return function(m,n){
let a=m[keyWord].toLowerCase();
let b=n[keyWord].toLowerCase();
if (a<b) return -1;
if (b<a) return 1
return 0;
}
}
function sortByTime(){
let date="09/30/2023 "//fake date only for compare
return function(m,n){
let a=date+m.time;
let b=date+n.time;
if (a<b) return -1;
if (b<a) return 1;
return 0;
}
}
$("#show").click(function(){
let pmTable=$("#pmTable")
let trips=$("#trips").val();
let groups=[]
let prtsArr=trips.split("\n");
for(let i=1;i<prtsArr.length;i++){
let keys=prtsArr[0].split("\t");
let o='{';
for(let j=0;j<keys.length;j++){
//o={};
//o[`${keys[j].replace(" ","_")}`]=prtsArr[i][j];
//o=o+`"${keys[j].replace(" ","_")}":"${prtsArr[i][j]}"`
let key=""
let val=prtsArr[i].split("\t")
let chk=keys[j]
if(chk=="Driver Name"){
key="driver"
}else if(chk=="PassengerName"){
key="prt"
}else if(chk=="ServiceCode"){
key="wheelchair"
}else if(chk=="PickupOrdered"){
key="time"
}
if(key!=""){
o=o+`"${key}":"${val[j]}"`
}
if(key!="") o=o+","
}
o=o.substr(0, o.length-1)
o=o+"}"
let obj=JSON.parse(o)
if(drivers.indexOf(obj.driver)>=0){
groups.push(obj)
}
//groups.push((o))
}
groups.sort(sortByTime())
let tableHtml=`<table style="background:black;width:100%;board:0px">
<tr><th style="background:lightgray">Prt</th>
<th style="background:lightgray">Rt#</th>
<th style="background:lightgray">W</th>
<th style="background:lightgray;width:5px"></th>
<th style="background:lightgray">Prt</th>
<th style="background:lightgray">Rt#</th>
<th style="background:lightgray">W</th>
</tr>`
for(let i=0;i<groups.length/2;i++){
tableHtml+=`<tr>
<td style="background:white">${groups[i].prt}</td>
<td style="background:white">${groups[i].driver}</td>
<td style="background:white">${groups[i].prt}</td>
<td style="background:lightgray;width:5px"></td>
<td style="background:white">${groups[i+(groups.length-1)/2].prt}</td>
<td style="background:white">${groups[i+(groups.length-1)/2].driver}</td>
<td style="background:white">${groups[i+(groups.length-1)/2].prt}</td>
</tr>`
}
tableHtml+=`</table>`
//pmTable.html(tableHtml)
pmTable.text(JSON.stringify(groups))
//alert(groups[5].prt)
})
// Your code here...
})();