From 136ad046784c08fb45c0559a90f31b8b46230774 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 24 Mar 2024 07:07:29 -0400 Subject: [PATCH] tweaks: readd adblock, refactor toggle_bar, simplify --- makefile | 1 + plugins/plugins.mk | 2 -- plugins/style/style.c | 2 +- plugins/style/style.h | 2 +- plugins/style/style.js | 6 ++++-- rosenrot.c | 32 ++++++++++++-------------------- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/makefile b/makefile index d9cab30..855c3d1 100644 --- a/makefile +++ b/makefile @@ -17,6 +17,7 @@ CONFIG=config.h # Plugins include plugins/plugins.mk # PLUGINS=./plugins/stand_in/stand_in.c +ADBLOCK='-L/usr/lib/wyebrowser/adblock.so' # optional adblocking; depends on https://github.com/jun7/wyebadblock ## Formatter STYLE_BLUEPRINT="{BasedOnStyle: webkit, AllowShortIfStatementsOnASingleLine: true, IndentCaseLabels: true, AllowShortEnumsOnASingleLine: true}" diff --git a/plugins/plugins.mk b/plugins/plugins.mk index f8d000f..87141cc 100644 --- a/plugins/plugins.mk +++ b/plugins/plugins.mk @@ -7,8 +7,6 @@ SHORTCUTS=./plugins/shortcuts/shortcuts.c READABILITY=./plugins/readability/readability.c LIBRE_REDIRECT=./plugins/libre_redirect/libre_redirect.c -ADBLOCK='-L/usr/lib/wyebrowser/adblock.so' # optional adblocking; depends on https://github.com/jun7/wyebadblock - STAND_IN=./plugins/stand_in/stand_in.c # gives function definitions for the above, which do nothing PLUGINS=$(COMMON_CODE) $(CUSTOM_STYLES) $(SHORTCUTS) $(READABILITY) $(LIBRE_REDIRECT) diff --git a/plugins/style/style.c b/plugins/style/style.c index a9a6be5..e9c2762 100644 --- a/plugins/style/style.c +++ b/plugins/style/style.c @@ -1,7 +1,7 @@ #include #include #include -#define STYLE_N 7624 + 1000 +#define STYLE_N 7653 + 1000 void read_style_js(char* string) { diff --git a/plugins/style/style.h b/plugins/style/style.h index 42fe798..59cc7d7 100644 --- a/plugins/style/style.h +++ b/plugins/style/style.h @@ -1,5 +1,5 @@ #pragma once -#define STYLE_N 7624 + 1000 +#define STYLE_N 7653 + 1000 void read_style_js(char* string); diff --git a/plugins/style/style.js b/plugins/style/style.js index e3eeda7..71284e1 100644 --- a/plugins/style/style.js +++ b/plugins/style/style.js @@ -2,6 +2,7 @@ // Main part of the code: switch on the domain and select the corresponding style var styles = null; +console.log(document.domain) switch (document.domain) { case "forum.effectivealtruism.org": styles = ` @@ -81,6 +82,8 @@ switch (document.domain) { .native-ad-container, .native-sidebar-ad, .premium-banner-outer, + .promotedlink, + .promoted { display: none !important; } @@ -152,7 +155,6 @@ switch (document.domain) { /* No change of colors in hover */ *:hover { /* background-color: white !important; */ - background-color: !important; transition: none !important; }*/ /* @@ -283,4 +285,4 @@ if (document.domain == "twitter.com") { hideVideoPlayerGrandparent(); } -document.body.style.visibility = "visible"; +// document.body.style.visibility = "visible"; diff --git a/rosenrot.c b/rosenrot.c index 91070bc..5f250d5 100644 --- a/rosenrot.c +++ b/rosenrot.c @@ -9,16 +9,17 @@ /* Global declarations */ static GtkNotebook* notebook; static GtkWindow* window; +typedef enum { _SEARCH, _FIND, _HIDDEN } Bar_entry_mode; static struct { GtkHeaderBar* widget; GtkEntry* line; GtkEntryBuffer* line_text; - enum { _SEARCH, _FIND, _HIDDEN } entry_mode; + Bar_entry_mode entry_mode; } bar; static int num_tabs = 0; // Forward declarations -void toggle_bar(GtkNotebook* notebook); +void toggle_bar(GtkNotebook* notebook, Bar_entry_mode mode); void notebook_create_new_tab(GtkNotebook* notebook, const char* uri); /* Utils */ @@ -33,8 +34,7 @@ void load_uri(WebKitWebView* view, const char* uri) { if (strlen(uri) == 0) { webkit_web_view_load_uri(view, ""); - bar.entry_mode = _SEARCH; - toggle_bar(notebook); + toggle_bar(notebook, _SEARCH); } else 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 if (strstr(uri, ".com") || strstr(uri, ".org")) { @@ -192,8 +192,9 @@ void notebook_create_new_tab(GtkNotebook* notebook, const char* uri) } /* Top bar */ -void toggle_bar(GtkNotebook* notebook) +void toggle_bar(GtkNotebook* notebook, Bar_entry_mode mode) { + bar.entry_mode = mode; switch (bar.entry_mode) { case _SEARCH: { const char* url = webkit_web_view_get_uri(notebook_get_webview(notebook)); @@ -219,6 +220,7 @@ void toggle_bar(GtkNotebook* notebook) gtk_widget_hide(GTK_WIDGET(bar.widget)); } } + // Handle what happens when the user is on the bar and presses enter void handle_signal_bar_press_enter(GtkEntry* self, GtkNotebook* notebook) { @@ -312,12 +314,10 @@ int handle_shortcut(func id, GtkNotebook* notebook) break; case show_searchbar: - bar.entry_mode = _SEARCH; - toggle_bar(notebook); + toggle_bar(notebook, _SEARCH); break; case show_finder: - bar.entry_mode = _FIND; - toggle_bar(notebook); + toggle_bar(notebook, _FIND); break; case finder_next: @@ -330,13 +330,11 @@ int handle_shortcut(func id, GtkNotebook* notebook) case new_tab: notebook_create_new_tab(notebook, NULL); gtk_notebook_set_show_tabs(notebook, true); - bar.entry_mode = _SEARCH; - toggle_bar(notebook); + toggle_bar(notebook, _SEARCH); break; case hide_bar: - bar.entry_mode = _HIDDEN; - toggle_bar(notebook); + toggle_bar(notebook, _HIDDEN); break; case prettify: { @@ -362,15 +360,9 @@ int handle_signal_keypress(void* self, GdkEvent* event, GtkNotebook* notebook) GdkModifierType event_state = 0; gdk_event_get_state(event, &event_state); - int debug_shortcuts = 0; - if (debug_shortcuts) { + if (0) { printf("Keypress state: %d\n", event_state); - if (event_state & GDK_CONTROL_MASK) { - printf("Keypress state is: CONTROL\n"); - } printf("Keypress value: %d\n", event_keyval); - printf("PageUp: %d %d\n", KEY(Page_Up), GDK_KEY_KP_Page_Up); - printf("PageDown: %d %d\n", KEY(Page_Down), GDK_KEY_KP_Page_Down); } for (int i = 0; i < sizeof(shortcut) / sizeof(shortcut[0]); i++)