update chrome extension scripts
parent
b07089d998
commit
7108f4179c
|
@ -41,7 +41,7 @@ try:
|
|||
except Exception as exc:
|
||||
pass
|
||||
|
||||
CONST_APP_VERSION = "MaxBot (2024.01.15)"
|
||||
CONST_APP_VERSION = "MaxBot (2024.01.16)"
|
||||
|
||||
CONST_MAXBOT_ANSWER_ONLINE_FILE = "MAXBOT_ONLINE_ANSWER.txt"
|
||||
CONST_MAXBOT_CONFIG_FILE = "settings.json"
|
||||
|
|
|
@ -22,7 +22,7 @@ import sys
|
|||
import threading
|
||||
import webbrowser
|
||||
|
||||
CONST_APP_VERSION = "MaxBot (2024.01.15)"
|
||||
CONST_APP_VERSION = "MaxBot (2024.01.16)"
|
||||
|
||||
CONST_MAXBOT_LAUNCHER_FILE = "config_launcher.json"
|
||||
CONST_MAXBOT_CONFIG_FILE = "settings.json"
|
||||
|
|
|
@ -40,7 +40,7 @@ try:
|
|||
except Exception as exc:
|
||||
pass
|
||||
|
||||
CONST_APP_VERSION = "MaxBot (2024.01.15)"
|
||||
CONST_APP_VERSION = "MaxBot (2024.01.16)"
|
||||
|
||||
CONST_MAXBOT_ANSWER_ONLINE_FILE = "MAXBOT_ONLINE_ANSWER.txt"
|
||||
CONST_MAXBOT_CONFIG_FILE = "settings.json"
|
||||
|
|
|
@ -12,6 +12,12 @@ chrome.runtime.onInstalled.addListener(function(){
|
|||
text: default_status
|
||||
});
|
||||
|
||||
chrome.storage.local.set(
|
||||
{
|
||||
status: default_status
|
||||
}
|
||||
);
|
||||
|
||||
const default_webserver_runing=false;
|
||||
|
||||
fetch("data/settings.json")
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
const storage = chrome.storage.local;
|
||||
var settings = null;
|
||||
|
||||
$("footer").remove();
|
||||
|
||||
function ticket_assign_adjacent_seat(flag) {
|
||||
//console.log("disable_adjacent_seat flag:"+flag);
|
||||
if(flag) {
|
||||
$('input[type=checkbox]').each(function() {
|
||||
$(this).prop('checked', true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function ticket_focus_on_captcha()
|
||||
{
|
||||
$("div.login-form input[autocomplete='off']").focus();
|
||||
}
|
||||
|
||||
var myInterval = null;
|
||||
|
||||
function ticket_get_ocr_image()
|
||||
{
|
||||
//console.log("get_ocr_image");
|
||||
let image_data = "";
|
||||
|
||||
// PS: tixcraft have different domain to use the same content script.
|
||||
const currentUrl = window.location.href;
|
||||
const domain = currentUrl.split('/')[2];
|
||||
|
||||
let image_id = 'chk_pic';
|
||||
let img = document.getElementById(image_id);
|
||||
if(img!=null) {
|
||||
let canvas = document.createElement('canvas');
|
||||
let context = canvas.getContext('2d');
|
||||
canvas.height = img.naturalHeight;
|
||||
canvas.width = img.naturalWidth;
|
||||
context.drawImage(img, 0, 0);
|
||||
let img_data = canvas.toDataURL();
|
||||
if(img_data) {
|
||||
image_data = img_data.split(",")[1];
|
||||
//console.log(image_data);
|
||||
}
|
||||
}
|
||||
return image_data;
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener((message) => {
|
||||
//console.log('sent from background', message);
|
||||
ticket_set_ocr_answer(message.answer);
|
||||
});
|
||||
|
||||
function ticket_set_ocr_answer(answer)
|
||||
{
|
||||
//console.log("answer:"+answer);
|
||||
if(answer.length > 0) {
|
||||
const currentUrl = window.location.href;
|
||||
const domain = currentUrl.split('/')[2];
|
||||
const scrip_page = currentUrl.split('/')[5];
|
||||
|
||||
answer = answer.toUpperCase();
|
||||
let query_string = "div.form-group input[autocomplete='off']";
|
||||
if(domain.indexOf('kham') > -1) {
|
||||
query_string = ".step2Login input[maxlength='4']";
|
||||
}
|
||||
$(query_string).val(answer);
|
||||
//console.log($(query_string).length);
|
||||
//$("div#ticket-wrap a[onclick]").click();
|
||||
//$("#aspnetForm").submit();
|
||||
let done_div="<div style='display:none' id='done'></div>";
|
||||
$("body").append(done_div);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async function ticket_get_ocr_answer(api_url, image_data)
|
||||
{
|
||||
let bundle = {
|
||||
action: 'ocr',
|
||||
data: {
|
||||
'url': api_url + 'ocr',
|
||||
'image_data':image_data,
|
||||
}
|
||||
};
|
||||
|
||||
let bundle_string = JSON.stringify(bundle);
|
||||
const return_answer = await chrome.runtime.sendMessage(bundle);
|
||||
//console.log(return_answer);
|
||||
}
|
||||
|
||||
function ticket_orc_image_ready(api_url)
|
||||
{
|
||||
let ret=false;
|
||||
let image_data = ticket_get_ocr_image();
|
||||
if(image_data.length>0) {
|
||||
ret=true;
|
||||
if(myInterval) clearInterval(myInterval);
|
||||
ticket_get_ocr_answer(api_url, image_data);
|
||||
}
|
||||
//console.log("ticket_orc_image_ready:"+ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
storage.get('settings', function (items)
|
||||
{
|
||||
if (items.settings)
|
||||
{
|
||||
settings = items.settings;
|
||||
} else {
|
||||
console.log('no settings found');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
storage.get('settings', function (items)
|
||||
{
|
||||
if (items.settings)
|
||||
{
|
||||
settings = items.settings;
|
||||
}
|
||||
});
|
||||
|
||||
storage.get('status', function (items)
|
||||
{
|
||||
if (items.status && items.status=='ON')
|
||||
{
|
||||
//console.log("ticket_number:"+ settings.ticket_number);
|
||||
//ticket_assign_adjacent_seat(settings.advanced.disable_adjacent_seat);
|
||||
|
||||
// ocr
|
||||
if(settings.ocr_captcha.enable) {
|
||||
let remote_url_string = "";
|
||||
let remote_url_array = [];
|
||||
if(settings.advanced.remote_url.length > 0) {
|
||||
remote_url_array = JSON.parse('[' + settings.advanced.remote_url +']');
|
||||
}
|
||||
if(remote_url_array.length) {
|
||||
remote_url_string = remote_url_array[0];
|
||||
}
|
||||
if(!ticket_orc_image_ready(remote_url_string)) {
|
||||
myInterval = setInterval(() => {
|
||||
ticket_orc_image_ready(remote_url_string);
|
||||
}, 100);
|
||||
}
|
||||
} else {
|
||||
// no orc, just focus;
|
||||
ticket_focus_on_captcha();
|
||||
}
|
||||
} else {
|
||||
console.log('no status found');
|
||||
}
|
||||
});
|
|
@ -163,6 +163,20 @@
|
|||
"js/ticket_area.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"matches": [
|
||||
"https://ticket.com.tw/application/UTK02/UTK0205_.aspx?*",
|
||||
"https://ticket.com.tw/application/UTK02/UTK0202_.aspx?*",
|
||||
"https://kham.com.tw/application/UTK02/UTK0205_.aspx?*",
|
||||
"https://kham.com.tw/application/UTK02/UTK0202_.aspx?*"
|
||||
],
|
||||
"run_at": "document_end",
|
||||
"js": [
|
||||
"jquery.min.js",
|
||||
"js/common.js",
|
||||
"js/ticket_ticket.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"matches": [
|
||||
"https://kham.com.tw/application/utk01/UTK0101_03.aspx"
|
||||
|
@ -366,5 +380,5 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"version": "1.0.6"
|
||||
"version": "1.0.7"
|
||||
}
|
Loading…
Reference in New Issue