automatic add host_permissions to extension

master
CHUN YU YAO 2024-01-14 22:50:13 +08:00
parent 4b3f743f33
commit a24c30fb86
4 changed files with 386 additions and 243 deletions

View File

@ -557,6 +557,51 @@ def clean_uc_exe_cache():
return is_cache_exist return is_cache_exist
def dump_settins_to_maxbot_plus_extension(ext, config_dict):
target_path = ext
target_path = os.path.join(target_path, "data")
target_path = os.path.join(target_path, CONST_MAXBOT_CONFIG_FILE)
#print("save as to:", target_path)
try:
os.unlink(target_path)
except Exception as exc:
pass
with open(target_path, 'w') as outfile:
json.dump(config_dict, outfile)
target_path = ext
target_path = os.path.join(target_path, "manifest.json")
manifest_dict = None
if os.path.isfile(target_path):
with open(target_path) as json_data:
manifest_dict = json.load(json_data)
local_remote_url_array = []
local_remote_url = config_dict["advanced"]["remote_url"]
if len(local_remote_url) > 0:
try:
temp_remote_url_array = json.loads("["+ local_remote_url +"]")
for remote_url in temp_remote_url_array:
remote_url_final = remote_url + "*"
local_remote_url_array.append(remote_url_final)
except Exception as exc:
pass
if len(local_remote_url_array) > 0:
is_manifest_changed = False
for remote_url_final in local_remote_url_array:
if not remote_url_final in manifest_dict["host_permissions"]:
#print("local remote_url not in manifest:", remote_url_final)
manifest_dict["host_permissions"].append(remote_url_final)
is_manifest_changed = True
if is_manifest_changed:
json_str = json.dumps(manifest_dict, indent=4)
with open(target_path, 'w') as outfile:
outfile.write(json_str)
def get_uc_options(uc, config_dict, webdriver_path): def get_uc_options(uc, config_dict, webdriver_path):
options = uc.ChromeOptions() options = uc.ChromeOptions()
options.page_load_strategy = 'eager' options.page_load_strategy = 'eager'
@ -581,16 +626,7 @@ def get_uc_options(uc, config_dict, webdriver_path):
if os.path.exists(ext): if os.path.exists(ext):
# sync config. # sync config.
if CONST_MAXBOT_EXTENSION_NAME in ext: if CONST_MAXBOT_EXTENSION_NAME in ext:
target_path = ext dump_settins_to_maxbot_plus_extension(ext, config_dict)
target_path = os.path.join(target_path, "data")
target_path = os.path.join(target_path, CONST_MAXBOT_CONFIG_FILE)
#print("save as to:", target_path)
try:
os.unlink(target_path)
except Exception as exc:
pass
with open(target_path, 'w') as outfile:
json.dump(config_dict, outfile)
load_extension_path += ("," + os.path.abspath(ext)) load_extension_path += ("," + os.path.abspath(ext))
if len(load_extension_path) > 0: if len(load_extension_path) > 0:

View File

@ -2849,7 +2849,6 @@ class VersionHandler(tornado.web.RequestHandler):
def get(self): def get(self):
self.write({"version":self.application.version}) self.write({"version":self.application.version})
class OcrHandler(tornado.web.RequestHandler): class OcrHandler(tornado.web.RequestHandler):
def get(self): def get(self):
self.write({"answer": "1234"}) self.write({"answer": "1234"})

View File

@ -29,13 +29,19 @@
"declarativeNetRequestFeedback" "declarativeNetRequestFeedback"
], ],
"host_permissions": [ "host_permissions": [
"http://127.0.0.1:16888/*" "http://maxbot.dropboxlike.com:16888/*"
], ],
"web_accessible_resources": [ "web_accessible_resources": [
{ {
"resources": [ "data/*.json" ], "resources": [
"extension_ids": ["*"], "data/*.json"
"matches": [ "*://*/*" ] ],
"extension_ids": [
"*"
],
"matches": [
"*://*/*"
]
} }
], ],
"options_page": "options.html", "options_page": "options.html",
@ -52,7 +58,10 @@
"https://ticketmaster.sg/" "https://ticketmaster.sg/"
], ],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/tixcraft_home.js" ] "js": [
"jquery.min.js",
"js/tixcraft_home.js"
]
}, },
{ {
"matches": [ "matches": [
@ -62,7 +71,10 @@
"https://ticketmaster.sg/activity/detail/*" "https://ticketmaster.sg/activity/detail/*"
], ],
"run_at": "document_start", "run_at": "document_start",
"js" : [ "jquery.min.js", "js/tixcraft_detail.js" ] "js": [
"jquery.min.js",
"js/tixcraft_detail.js"
]
}, },
{ {
"matches": [ "matches": [
@ -72,7 +84,11 @@
"https://ticketmaster.sg/activity/game/*" "https://ticketmaster.sg/activity/game/*"
], ],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/common.js", "js/tixcraft_game.js" ] "js": [
"jquery.min.js",
"js/common.js",
"js/tixcraft_game.js"
]
}, },
{ {
"matches": [ "matches": [
@ -81,7 +97,11 @@
"https://indievox.com/ticket/area/*" "https://indievox.com/ticket/area/*"
], ],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/common.js", "js/tixcraft_area.js" ] "js": [
"jquery.min.js",
"js/common.js",
"js/tixcraft_area.js"
]
}, },
{ {
"matches": [ "matches": [
@ -91,40 +111,75 @@
"https://ticketmaster.sg/ticket/ticket/*" "https://ticketmaster.sg/ticket/ticket/*"
], ],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/common.js", "js/tixcraft_ticket.js" ] "js": [
"jquery.min.js",
"js/common.js",
"js/tixcraft_ticket.js"
]
}, },
{ {
"matches" : [ "https://ticket.com.tw/application/utk01/utk0101_.aspx" ], "matches": [
"https://ticket.com.tw/application/utk01/utk0101_.aspx"
],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/ticket_home.js" ] "js": [
"jquery.min.js",
"js/ticket_home.js"
]
}, },
{ {
"matches" : [ "https://ticket.com.tw/application/UTK02/UTK0201_.aspx?PRODUCT_ID=*" ], "matches": [
"https://ticket.com.tw/application/UTK02/UTK0201_.aspx?PRODUCT_ID=*"
],
"run_at": "document_end", "run_at": "document_end",
"world": "MAIN", "world": "MAIN",
"js" : [ "jquery.min.js", "js/ticket_event_home.js" ] "js": [
"jquery.min.js",
"js/ticket_event_home.js"
]
}, },
{ {
"matches" : [ "https://ticket.com.tw/application/UTK02/UTK0201_00.aspx?PRODUCT_ID=*" ], "matches": [
"https://ticket.com.tw/application/UTK02/UTK0201_00.aspx?PRODUCT_ID=*"
],
"run_at": "document_end", "run_at": "document_end",
"world": "MAIN", "world": "MAIN",
"js" : [ "jquery.min.js", "js/ticket_date.js" ] "js": [
"jquery.min.js",
"js/ticket_date.js"
]
}, },
{ {
"matches" : [ "https://ticket.com.tw/application/UTK02/UTK0204_.aspx?*" ], "matches": [
"https://ticket.com.tw/application/UTK02/UTK0204_.aspx?*"
],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/common.js", "js/ticket_area.js" ] "js": [
"jquery.min.js",
"js/common.js",
"js/ticket_area.js"
]
}, },
{ {
"matches" : [ "https://kham.com.tw/application/utk01/UTK0101_03.aspx" ], "matches": [
"https://kham.com.tw/application/utk01/UTK0101_03.aspx"
],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/kham_home.js" ] "js": [
"jquery.min.js",
"js/kham_home.js"
]
}, },
{ {
"matches" : [ "https://kham.com.tw/application/UTK02/UTK0201_.aspx?PRODUCT_ID=*" ], "matches": [
"https://kham.com.tw/application/UTK02/UTK0201_.aspx?PRODUCT_ID=*"
],
"run_at": "document_end", "run_at": "document_end",
"world": "MAIN", "world": "MAIN",
"js" : [ "jquery.min.js", "js/kham_event_home.js" ] "js": [
"jquery.min.js",
"js/kham_event_home.js"
]
}, },
{ {
"matches": [ "matches": [
@ -132,22 +187,40 @@
], ],
"run_at": "document_end", "run_at": "document_end",
"world": "MAIN", "world": "MAIN",
"js" : [ "jquery.min.js", "js/kham_date.js" ] "js": [
"jquery.min.js",
"js/kham_date.js"
]
}, },
{ {
"matches" : [ "https://kham.com.tw/application/UTK02/UTK0204_.aspx?*" ], "matches": [
"https://kham.com.tw/application/UTK02/UTK0204_.aspx?*"
],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/kham_area.js" ] "js": [
"jquery.min.js",
"js/kham_area.js"
]
}, },
{ {
"matches" : [ "https://ticket.ibon.com.tw/ActivityInfo/Details/*" ], "matches": [
"https://ticket.ibon.com.tw/ActivityInfo/Details/*"
],
"run_at": "document_start", "run_at": "document_start",
"js" : [ "jquery.min.js", "js/ibon_detail.js" ] "js": [
"jquery.min.js",
"js/ibon_detail.js"
]
}, },
{ {
"matches" : [ "https://orders.ibon.com.tw/application/UTK02/UTK0201_000.aspx?*" ], "matches": [
"https://orders.ibon.com.tw/application/UTK02/UTK0201_000.aspx?*"
],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/ibon_area.js" ] "js": [
"jquery.min.js",
"js/ibon_area.js"
]
}, },
{ {
"matches": [ "matches": [
@ -155,7 +228,10 @@
"https://orders.ibon.com.tw/application/UTK02/UTK0202_.aspx?PERFORMANCE_ID=*PERFORMANCE_PRICE_AREA_ID=*" "https://orders.ibon.com.tw/application/UTK02/UTK0202_.aspx?PERFORMANCE_ID=*PERFORMANCE_PRICE_AREA_ID=*"
], ],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/ibon_ticket.js" ] "js": [
"jquery.min.js",
"js/ibon_ticket.js"
]
}, },
{ {
"matches": [ "matches": [
@ -164,14 +240,20 @@
], ],
"run_at": "document_end", "run_at": "document_end",
"world": "MAIN", "world": "MAIN",
"js" : [ "jquery.min.js", "js/ibon_ticket_next.js" ] "js": [
"jquery.min.js",
"js/ibon_ticket_next.js"
]
}, },
{ {
"matches": [ "matches": [
"https://msg.cityline.com/*.html*" "https://msg.cityline.com/*.html*"
], ],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/cityline_msg_background.js"] "js": [
"jquery.min.js",
"js/cityline_msg_background.js"
]
}, },
{ {
"matches": [ "matches": [
@ -179,7 +261,10 @@
], ],
"run_at": "document_end", "run_at": "document_end",
"world": "MAIN", "world": "MAIN",
"js" : [ "jquery.min.js", "js/cityline_msg_front.js"] "js": [
"jquery.min.js",
"js/cityline_msg_front.js"
]
}, },
{ {
"matches": [ "matches": [
@ -187,35 +272,50 @@
"https://*.cityline.com/utsvlnternet/*/login?lang=TW" "https://*.cityline.com/utsvlnternet/*/login?lang=TW"
], ],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/cityline_event_common.js"] "js": [
"jquery.min.js",
"js/cityline_event_common.js"
]
}, },
{ {
"matches": [ "matches": [
"https://ticketplus.com.tw/activity/*" "https://ticketplus.com.tw/activity/*"
], ],
"run_at": "document_end", "run_at": "document_end",
"js" : ["jquery.min.js", "js/ticketplus_activity.js"] "js": [
"jquery.min.js",
"js/ticketplus_activity.js"
]
}, },
{ {
"matches": [ "matches": [
"https://ticketplus.com.tw/order/*" "https://ticketplus.com.tw/order/*"
], ],
"run_at": "document_start", "run_at": "document_start",
"js" : [ "jquery.min.js", "js/ticketplus_order.js"] "js": [
"jquery.min.js",
"js/ticketplus_order.js"
]
}, },
{ {
"matches": [ "matches": [
"https://kktix.com/" "https://kktix.com/"
], ],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/kktix_home.js" ] "js": [
"jquery.min.js",
"js/kktix_home.js"
]
}, },
{ {
"matches": [ "matches": [
"https://*.kktix.cc/events/*" "https://*.kktix.cc/events/*"
], ],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/kktix_events.js" ] "js": [
"jquery.min.js",
"js/kktix_events.js"
]
}, },
{ {
"matches": [ "matches": [
@ -223,15 +323,23 @@
], ],
"world": "MAIN", "world": "MAIN",
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/common.js", "js/kktix_registrations_assign.js" ] "js": [
"jquery.min.js",
"js/common.js",
"js/kktix_registrations_assign.js"
]
}, },
{ {
"matches": [ "matches": [
"https://kktix.com/events/*/registrations/new" "https://kktix.com/events/*/registrations/new"
], ],
"run_at": "document_start", "run_at": "document_start",
"js" : [ "jquery.min.js", "js/common.js", "js/kktix_registrations_reload.js" ] "js": [
"jquery.min.js",
"js/common.js",
"js/kktix_registrations_reload.js"
]
} }
], ],
"version": "1.0.4" "version": "1.0.5"
} }

View File

@ -105,7 +105,7 @@
</div> </div>
<div class="col-12"> <div class="col-12">
<label for="remote_url" class="form-label">Remote URL</label> <label for="remote_url" class="form-label">OCR Server URL</label>
<input class="form-control" id="remote_url" value="" /> <input class="form-control" id="remote_url" value="" />
</div> </div>
</div> </div>