Skip to content

Commit

Permalink
Add blacklist for html page redirection (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
qsniyg committed Jul 1, 2024
1 parent 78c4d74 commit bdfb8c3
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
61 changes: 59 additions & 2 deletions src/userscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
57 changes: 55 additions & 2 deletions userscript.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit bdfb8c3

Please sign in to comment.