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
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):
options = uc.ChromeOptions()
options.page_load_strategy = 'eager'
@ -581,16 +626,7 @@ def get_uc_options(uc, config_dict, webdriver_path):
if os.path.exists(ext):
# sync config.
if CONST_MAXBOT_EXTENSION_NAME in ext:
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)
dump_settins_to_maxbot_plus_extension(ext, config_dict)
load_extension_path += ("," + os.path.abspath(ext))
if len(load_extension_path) > 0:

View File

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

View File

@ -29,13 +29,19 @@
"declarativeNetRequestFeedback"
],
"host_permissions": [
"http://127.0.0.1:16888/*"
"http://maxbot.dropboxlike.com:16888/*"
],
"web_accessible_resources": [
{
"resources": [ "data/*.json" ],
"extension_ids": ["*"],
"matches": [ "*://*/*" ]
"resources": [
"data/*.json"
],
"extension_ids": [
"*"
],
"matches": [
"*://*/*"
]
}
],
"options_page": "options.html",
@ -43,195 +49,297 @@
"default_icon": "icons/maxbot-128.png",
"default_title": "MaxBot"
},
"content_scripts" : [
"content_scripts": [
{
"matches" : [
"matches": [
"https://tixcraft.com/",
"https://www.indievox.com/",
"https://indievox.com/",
"https://ticketmaster.sg/"
],
"run_at": "document_end",
"js" : [ "jquery.min.js", "js/tixcraft_home.js" ]
"js": [
"jquery.min.js",
"js/tixcraft_home.js"
]
},
{
"matches" : [
"matches": [
"https://tixcraft.com/activity/detail/*",
"https://www.indievox.com/activity/detail/*",
"https://indievox.com/activity/detail/*",
"https://ticketmaster.sg/activity/detail/*"
],
"run_at": "document_start",
"js" : [ "jquery.min.js", "js/tixcraft_detail.js" ]
"js": [
"jquery.min.js",
"js/tixcraft_detail.js"
]
},
{
"matches" : [
"matches": [
"https://tixcraft.com/activity/game/*",
"https://www.indievox.com/activity/game/*",
"https://indievox.com/activity/game/*",
"https://ticketmaster.sg/activity/game/*"
],
"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": [
"https://tixcraft.com/ticket/area/*",
"https://www.indievox.com/ticket/area/*",
"https://indievox.com/ticket/area/*"
],
"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": [
"https://tixcraft.com/ticket/ticket/*",
"https://www.indievox.com/ticket/ticket/*",
"https://indievox.com/ticket/ticket/*",
"https://ticketmaster.sg/ticket/ticket/*"
],
"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",
"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",
"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",
"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",
"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",
"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",
"world": "MAIN",
"js" : [ "jquery.min.js", "js/kham_event_home.js" ]
"js": [
"jquery.min.js",
"js/kham_event_home.js"
]
},
{
"matches" : [
"matches": [
"https://kham.com.tw/application/UTK02/UTK0201_00.aspx?PRODUCT_ID=*"
],
"run_at": "document_end",
"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",
"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",
"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",
"js" : [ "jquery.min.js", "js/ibon_area.js" ]
"js": [
"jquery.min.js",
"js/ibon_area.js"
]
},
{
"matches" : [
"matches": [
"https://orders.ibon.com.tw/application/UTK02/UTK0201_001.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",
"js" : [ "jquery.min.js", "js/ibon_ticket.js" ]
"js": [
"jquery.min.js",
"js/ibon_ticket.js"
]
},
{
"matches" : [
"matches": [
"https://orders.ibon.com.tw/application/UTK02/UTK0201_001.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",
"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*"
],
"run_at": "document_end",
"js" : [ "jquery.min.js", "js/cityline_msg_background.js"]
"js": [
"jquery.min.js",
"js/cityline_msg_background.js"
]
},
{
"matches" : [
"matches": [
"https://msg.cityline.com/*"
],
"run_at": "document_end",
"world": "MAIN",
"js" : [ "jquery.min.js", "js/cityline_msg_front.js"]
"js": [
"jquery.min.js",
"js/cityline_msg_front.js"
]
},
{
"matches" : [
"matches": [
"https://*.cityline.com/utsvInternet/internet/eventDetail?event=*",
"https://*.cityline.com/utsvlnternet/*/login?lang=TW"
],
"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/*"
],
"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/*"
],
"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/"
],
"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/*"
],
"run_at": "document_end",
"js" : [ "jquery.min.js", "js/kktix_events.js" ]
"js": [
"jquery.min.js",
"js/kktix_events.js"
]
},
{
"matches" : [
"matches": [
"https://kktix.com/events/*/registrations/new"
],
"world": "MAIN",
"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"
],
"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 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="" />
</div>
</div>