commit 136ad046784c08fb45c0559a90f31b8b46230774
parent a1a22bb282b18c555179c40345b3954bf18db471
Author: NunoSempere <nuno.semperelh@protonmail.com>
Date: Sun, 24 Mar 2024 07:07:29 -0400
tweaks: readd adblock, refactor toggle_bar, simplify
Diffstat:
6 files changed, 19 insertions(+), 26 deletions(-)
diff --git 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
@@ -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
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#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
@@ -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
@@ -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
@@ -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++)