From c46e2ba3985846019d3377895e52fc360a6ce061 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sat, 13 May 2023 23:24:52 -0400 Subject: incorporate shortcuts plugin into rose.c and makefile --- makefile | 5 +++-- rose.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/makefile b/makefile index be310c6..5650d05 100644 --- a/makefile +++ b/makefile @@ -25,12 +25,13 @@ ADBLOCK=#'-L/usr/lib/wyebrowser/adblock.so' ## Plugins LIBRE_REDIRECT=./plugins/libre_redirect/libre_redirect.c ./plugins/libre_redirect/str_replace_start.c -READABILITY=./plugins/readability/readability.c CUSTOM_STYLES=./plugins/style/style.c +READABILITY=./plugins/readability/readability.c +SHORTCUTS=./plugins/shortcuts/shortcuts.c STAND_IN=./plugins/stand_in/stand_in.c # gives function definitions for the above, which do nothing -PLUGS=$(LIBRE_REDIRECT) $(READABILITY) $(CUSTOM_STYLES) +PLUGS=$(LIBRE_REDIRECT) $(READABILITY) $(CUSTOM_STYLES) $(SHORTCUTS) # PLUGS=$(STAND_IN) # Note that if you want some plugins but not others, # You should edit the stand_in.c file diff --git a/rose.c b/rose.c index f19c88f..fcac2c9 100644 --- a/rose.c +++ b/rose.c @@ -7,6 +7,7 @@ #include "plugins/libre_redirect/libre_redirect.h" #include "plugins/readability/readability.h" +#include "plugins/shortcuts/shortcuts.h" #include "plugins/style/style.h" // #include "plugins/stand_in/stand_in.h" @@ -91,15 +92,40 @@ WebKitWebView* notebook_get_webview(GtkNotebook* notebook) notebook, gtk_notebook_get_current_page(notebook))); } + +void redirect_if_annoying(WebKitWebView* view, const char* uri) +{ + int l = LIBRE_N + strlen(uri) + 1; + char uri_filtered[l]; + str_init(uri_filtered, l); + + int check = libre_redirect(uri, uri_filtered); + + if (check == 2) { + webkit_web_view_load_uri(view, uri_filtered); + } +} + void load_uri(WebKitWebView* view, const char* uri) { if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") || g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) { webkit_web_view_load_uri(view, uri); } else { - // webkit_web_view_load_uri(view, uri); - char tmp[strlen(uri) + strlen(SEARCH)]; - snprintf(tmp, sizeof(tmp), SEARCH, uri); - webkit_web_view_load_uri(view, tmp); + // Check for shortcuts + int l = SHORTCUT_N + strlen(uri) + 1; + char uri_expanded[l]; + str_init(uri_expanded, l); + int check = shortcut_expand(uri, uri_expanded); + + if (check == 2) { + webkit_web_view_load_uri(view, uri_expanded); + } else { + // Feed into search engine. + char tmp[strlen(uri) + strlen(SEARCH)]; + snprintf(tmp, sizeof(tmp), SEARCH, uri); + webkit_web_view_load_uri(view, tmp); + } + } } -- cgit v1.2.3