From bdfb8c37bab44038b484306c21299f0e5073123e Mon Sep 17 00:00:00 2001 From: qsniyg Date: Mon, 1 Jul 2024 03:53:18 +0000 Subject: [PATCH] Add blacklist for html page redirection (#773) --- CHANGELOG.txt | 4 +++ src/userscript.ts | 61 ++++++++++++++++++++++++++++++++++++++++++++-- userscript.user.js | 57 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 118 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 31e71af3..8c01032e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ 2023.5.0 (in-dev) +New features: + + * Add custom blacklist for HTML page redirects (#773) + Improvements: * Various improvements/fixes to existing rules (including Flickr, iTunes, Patreon, Soundcloud, Threads, TikTok, Tumblr) diff --git a/src/userscript.ts b/src/userscript.ts index e3bac164..d455a438 100644 --- a/src/userscript.ts +++ b/src/userscript.ts @@ -3124,6 +3124,10 @@ var $$IMU_EXPORT$$; return true; }; + let host_html_filter:BigImageFilter = function(url:string):boolean { + return true; + }; + if (is_interactive || is_extension_bg) { let blackwhitelist_filter = function(url:string, regexes, option) { let result = true; @@ -3153,6 +3157,11 @@ var $$IMU_EXPORT$$; return blackwhitelist_filter(url, regexes, settings.host_blacklist_mode); }; + + host_html_filter = function(url) { + console.log(host_html_blacklist_regexes); + return blackwhitelist_filter(url, host_html_blacklist_regexes, settings.host_html_blacklist_mode); + }; } type BigImageRuleSpecificOptions = { @@ -13539,6 +13548,8 @@ var $$IMU_EXPORT$$; redirect_to_no_infobox: false, // thanks to nijaz-lab on github for the idea: https://github.com/qsniyg/maxurl/issues/557 redirect_host_html: false, + host_html_blacklist: "", + host_html_blacklist_mode: "blacklist", mouseover: true, // thanks to blue-lightning on github for the idea: https://github.com/qsniyg/maxurl/issues/16 mouseover_open_behavior: "popup", @@ -17141,6 +17152,33 @@ var $$IMU_EXPORT$$; } } }, + host_html_blacklist: { + name: "HTML page blacklist", + description: "A list of URLs (one per line) that are blacklisted from being redirected.", + requires: { + redirect: true, + redirect_host_html: true + }, + category: "redirection", + type: "textarea" + }, + host_html_blacklist_mode: { + name: "HTML page blacklist mode", + description: "Whether the HTML page blacklist should act as a blacklist or a whitelist", + requires: { + redirect: true, + redirect_host_html: true + }, + category: "redirection", + options: { + whitelist: { + name: "Whitelist" + }, + blacklist: { + name: "Blacklist" + } + } + }, filename_format: { name: "Filename format", description: "Format string(s) for the filename", @@ -17656,6 +17694,9 @@ var $$IMU_EXPORT$$; }, host_blacklist: { create_regexes() {return create_host_blacklist_regexes()} + }, + host_html_blacklist: { + create_regexes() {return create_host_html_blacklist_regexes()} } }; for (let bl in blacklist_settings) { @@ -19343,6 +19384,7 @@ var $$IMU_EXPORT$$; var blacklist_regexes = []; var host_blacklist_regexes = []; + var host_html_blacklist_regexes = []; function update_rule_setting() { url_cache.clear(); @@ -19463,6 +19505,15 @@ var $$IMU_EXPORT$$; } } + function create_host_html_blacklist_regexes() { + host_html_blacklist_regexes = []; + try { + host_html_blacklist_regexes = parse_blacklist_regexes(settings.host_html_blacklist, settings.bigimage_blacklist_engine); + } catch (e) { + return [e]; + } + } + var parse_headers = function(headerstr) { var headers = []; @@ -119852,8 +119903,12 @@ var $$IMU_EXPORT$$; } function do_redirect() { - if (!settings.redirect_host_html && !currenttab_is_image()) { - return; + if (!currenttab_is_image()) { + if (!settings.redirect_host_html) + return; + + if (!host_html_filter(window.location.href)) + return; } cursor_wait(); @@ -122259,6 +122314,8 @@ var $$IMU_EXPORT$$; function upgrade_settings(cb) { try { create_blacklist_regexes(); + create_host_blacklist_regexes(); + create_host_html_blacklist_regexes(); } catch(e) { console_error(e); } diff --git a/userscript.user.js b/userscript.user.js index 1a61e3b6..064ea8bb 100644 --- a/userscript.user.js +++ b/userscript.user.js @@ -2563,6 +2563,9 @@ var $$IMU_EXPORT$$; var host_filter = function(url) { return true; }; + var host_html_filter = function(url) { + return true; + }; if (is_interactive || is_extension_bg) { var blackwhitelist_filter_1 = function(url, regexes, option) { var result = true; @@ -2587,6 +2590,10 @@ var $$IMU_EXPORT$$; regexes = blacklist_regexes; return blackwhitelist_filter_1(url, regexes, settings.host_blacklist_mode); }; + host_html_filter = function(url) { + console.log(host_html_blacklist_regexes); + return blackwhitelist_filter_1(url, host_html_blacklist_regexes, settings.host_html_blacklist_mode); + }; } var default_options = { fill_object: true, @@ -12792,6 +12799,8 @@ var $$IMU_EXPORT$$; redirect_to_no_infobox: false, // thanks to nijaz-lab on github for the idea: https://github.com/qsniyg/maxurl/issues/557 redirect_host_html: false, + host_html_blacklist: "", + host_html_blacklist_mode: "blacklist", mouseover: true, // thanks to blue-lightning on github for the idea: https://github.com/qsniyg/maxurl/issues/16 mouseover_open_behavior: "popup", @@ -16353,6 +16362,33 @@ var $$IMU_EXPORT$$; } } }, + host_html_blacklist: { + name: "HTML page blacklist", + description: "A list of URLs (one per line) that are blacklisted from being redirected.", + requires: { + redirect: true, + redirect_host_html: true + }, + category: "redirection", + type: "textarea" + }, + host_html_blacklist_mode: { + name: "HTML page blacklist mode", + description: "Whether the HTML page blacklist should act as a blacklist or a whitelist", + requires: { + redirect: true, + redirect_host_html: true + }, + category: "redirection", + options: { + whitelist: { + name: "Whitelist" + }, + blacklist: { + name: "Blacklist" + } + } + }, filename_format: { name: "Filename format", description: "Format string(s) for the filename", @@ -16851,6 +16887,9 @@ var $$IMU_EXPORT$$; }, host_blacklist: { create_regexes: function() { return create_host_blacklist_regexes(); } + }, + host_html_blacklist: { + create_regexes: function() { return create_host_html_blacklist_regexes(); } } }; var _loop_1 = function(bl) { @@ -18199,6 +18238,7 @@ var $$IMU_EXPORT$$; } var blacklist_regexes = []; var host_blacklist_regexes = []; + var host_html_blacklist_regexes = []; function update_rule_setting() { url_cache.clear(); } @@ -18298,6 +18338,14 @@ var $$IMU_EXPORT$$; return [e]; } } + function create_host_html_blacklist_regexes() { + host_html_blacklist_regexes = []; + try { + host_html_blacklist_regexes = parse_blacklist_regexes(settings.host_html_blacklist, settings.bigimage_blacklist_engine); + } catch (e) { + return [e]; + } + } var parse_headers = function(headerstr) { var headers = []; var splitted = headerstr.split("\r\n"); @@ -107257,8 +107305,11 @@ var $$IMU_EXPORT$$; }); } function do_redirect() { - if (!settings.redirect_host_html && !currenttab_is_image()) { - return; + if (!currenttab_is_image()) { + if (!settings.redirect_host_html) + return; + if (!host_html_filter(window.location.href)) + return; } cursor_wait(); var force_page = false; @@ -109188,6 +109239,8 @@ var $$IMU_EXPORT$$; function upgrade_settings(cb) { try { create_blacklist_regexes(); + create_host_blacklist_regexes(); + create_host_html_blacklist_regexes(); } catch (e) { console_error(e); }