+ # Enhance URL mode by updating the mapping.
+ $config{mapping}{mode}{u} = sub {
+ my ($key, $screen, $config, $input) = @_;
+
+ # First get matches of normal URL mode.
+ my $result = mapping_mode_url(@_);
+
+ # Add all strings matching "CVE-1234-1234" with URLs pointing to the
+ # Debian security tracker. "->{value}" is the string which is used as
+ # result of the match (e.g. the URL in this case).
+ my @matches = get_regex_matches($input, qr/\b(CVE-\d+-\d+)\b/);
+ foreach (@matches) {
+ $_->{value} = "https://security-tracker.debian.org/$_->{string}";
+ }
+ push @{$result->{matches}}, @matches;
+
+ # Change all YouTube links to use the custom "youtube" handler (see
+ # below). This will allow us to automatically open YouTube URLs with a
+ # custom program, like `youtube-dl` or `mpv`.
+ foreach (@{$result->{matches}}) {
+ if ($_->{string} =~ m{^https://www.youtube.com/}) {
+ $_->{handler} = $config{handler}{youtube};
+ }
+ }
+
+ return $result;
+ }
+ # Also update initial mode to use our new "URL mode".
+ $config{setting}{initial_mode} = $config{mapping}{mode}{u};
+
+ # Special handler to download YouTube URLs with `youtube-dl`. You could
+ # also use `mpv` here to immediately play them.
+ $config{handler}{youtube} = sub {
+ my ($screen, $config, $match) = @_;
+
+ return run_in_background($screen, sub {
+ run_command($screen, ['youtube-dl', $match->{value}]);
+ });
+ };
+
+