From 98f6d5630f6be4f955e308a5c1a91749f8cf7300 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sat, 17 Jun 2023 00:29:27 -0600 Subject: alerts v2, formatting --- plugins/libre_redirect/libre_redirect.c | 4 +- plugins/libre_redirect/str_init.c | 1 - plugins/shortcuts/shortcuts.c | 8 +- plugins/style/style.c | 2 +- plugins/style/style.h | 2 +- plugins/style/style.js | 102 +++++++++++++------------- rose | Bin 47896 -> 47896 bytes rose.c | 125 ++++++++++++++++---------------- 8 files changed, 120 insertions(+), 124 deletions(-) diff --git a/plugins/libre_redirect/libre_redirect.c b/plugins/libre_redirect/libre_redirect.c index 13831fd..8bafded 100644 --- a/plugins/libre_redirect/libre_redirect.c +++ b/plugins/libre_redirect/libre_redirect.c @@ -32,7 +32,7 @@ int libre_redirect(const char* uri, char* output) char* annoying_sites[] = { "https://www.reddit.com", "https://www.youtube.com", - "https://google.com" + "https://google.com" "https://medium.com", "https://translate.google.com", "https://www.bloomberg.com", @@ -43,7 +43,7 @@ int libre_redirect(const char* uri, char* output) char* alternatives[] = { "https://teddit.nunosempere.com", "https://yt.artemislena.eu", - "https://search.nunosempere.com" + "https://search.nunosempere.com" "https://scribe.rip", "https://translate.riverside.rocks/", "https://archive.is/https://www.bloomberg.com", diff --git a/plugins/libre_redirect/str_init.c b/plugins/libre_redirect/str_init.c index edbe2ab..3fc548c 100644 --- a/plugins/libre_redirect/str_init.c +++ b/plugins/libre_redirect/str_init.c @@ -4,4 +4,3 @@ void str_init(char* str, int n) str[i] = ' '; str[n] = '\0'; } // could also use - diff --git a/plugins/shortcuts/shortcuts.c b/plugins/shortcuts/shortcuts.c index 1af4fda..7ee9e2e 100644 --- a/plugins/shortcuts/shortcuts.c +++ b/plugins/shortcuts/shortcuts.c @@ -2,8 +2,8 @@ #include #include -#include "../libre_redirect/str_replace_start.h" #include "../libre_redirect/str_init.h" +#include "../libre_redirect/str_replace_start.h" #define SHORTCUT_N 41 @@ -33,8 +33,8 @@ int shortcut_expand(const char* uri, char* output) char* shortcuts[] = { "!fnf", "!fnc", - "!hn", - "!hnb" + "!hn", + "!hnb" }; char* expansions[] = { @@ -45,7 +45,7 @@ int shortcut_expand(const char* uri, char* output) }; // len = sizeof(shortcuts) / sizeof(shortcuts[0]); - len = sizeof(shortcuts) / sizeof(char *); + len = sizeof(shortcuts) / sizeof(char*); for (int i = 0; i < len; i++) { int replace_check = str_replace_start(tmp_uri, shortcuts[i], diff --git a/plugins/style/style.c b/plugins/style/style.c index 34f7f35..7f0d3e4 100644 --- a/plugins/style/style.c +++ b/plugins/style/style.c @@ -1,7 +1,7 @@ #include #include #include -#define STYLE_N 3640 + 1 +#define STYLE_N 3858 + 1 void read_style_js(char* string) { diff --git a/plugins/style/style.h b/plugins/style/style.h index 75dd3ee..3a2cdc9 100644 --- a/plugins/style/style.h +++ b/plugins/style/style.h @@ -1,7 +1,7 @@ #ifndef STYLE #define STYLE -#define STYLE_N 3640 + 1 +#define STYLE_N 3858 + 1 void read_style_js(char* string); diff --git a/plugins/style/style.js b/plugins/style/style.js index cc98fa9..4f917ad 100644 --- a/plugins/style/style.js +++ b/plugins/style/style.js @@ -73,63 +73,61 @@ if(styles != null){ // Replace default alert with new function // whose style can be changed! -window.alert = function(message) { - // Check if the alert dialog already exists - var alertDiv = document.getElementById('customAlert'); +window.alert = (message) => { + let alertDiv = document.getElementById('customAlert'); if (!alertDiv) { - // Create the alert dialog - alertDiv = document.createElement('div'); - alertDiv.id = 'customAlert'; - alertDiv.className = 'custom-alert hidden'; - - var contentDiv = document.createElement('div'); - contentDiv.className = 'custom-alert-content'; - - var alertMessage = document.createElement('p'); - alertMessage.id = 'alertMessage'; - - var okButton = document.createElement('button'); - okButton.id = 'alertOkButton'; - okButton.textContent = 'OK'; - okButton.onclick = function() { - alertDiv.classList.add('hidden'); + const html = ` +
+
+

+ +
+
+ + `; + document.body.insertAdjacentHTML('beforeend', html); + alertDiv = document.getElementById('customAlert'); + document.getElementById('alertOkButton').onclick = () => { + alertDiv.classList.remove('visible'); + document.removeEventListener('keydown', dismissAlert); }; - - contentDiv.appendChild(alertMessage); - contentDiv.appendChild(okButton); - alertDiv.appendChild(contentDiv); - document.body.appendChild(alertDiv); - - // Inject CSS - var style = document.createElement('style'); - style.innerHTML = ` - .custom-alert { - position: fixed; - z-index: 999; - left: 0; - top: 0; - width: 100%; - height: 100%; - overflow: auto; - background-color: rgba(0,0,0,0.4); - } - .custom-alert-content { - background-color: #fefefe; - margin: 15% auto; - padding: 20px; - border: 1px solid #888; - width: 80%; + } + + const dismissAlert = (event) => { + if (event.key === 'Enter' /*&& event.ctrlKey*/ && alertDiv.classList.contains('visible')) { + alertDiv.classList.remove('visible'); + document.removeEventListener('keydown', dismissAlert); } - .hidden { - display: none; - }`; - document.head.appendChild(style); } - - // Show the alert dialog + + document.addEventListener('keydown', dismissAlert); document.getElementById('alertMessage').textContent = message; - alertDiv.classList.remove('hidden'); -} + alertDiv.classList.add('visible'); +} + // alert("Hello world!") document.body.style.visibility = "visible" diff --git a/rose b/rose index 4649d3d..2a41671 100755 Binary files a/rose and b/rose differ diff --git a/rose.c b/rose.c index f764f6c..bb6f6a0 100644 --- a/rose.c +++ b/rose.c @@ -98,20 +98,19 @@ 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 { - // 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); - } - + // 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); + } } } @@ -194,18 +193,18 @@ void notebook_append(GtkNotebook* notebook, const char* uri); GtkWidget* handle_create_new_tab(WebKitWebView* self, WebKitNavigationAction* navigation_action, GtkNotebook* notebook) -{ - if(NUM_TABS < MAX_NUM_TABS || NUM_TABS == 0){ - WebKitURIRequest* uri_request = webkit_navigation_action_get_request(navigation_action); - const char* uri = webkit_uri_request_get_uri(uri_request); - printf("Creating new window: %s\n", uri); - notebook_append(notebook, uri); - gtk_notebook_set_show_tabs(notebook, true); - return NULL; - } else { - webkit_web_view_run_javascript(notebook_get_webview(notebook), - "alert('Too many tabs, not opening a new one')", NULL, NULL, NULL); - } +{ + if (NUM_TABS < MAX_NUM_TABS || NUM_TABS == 0) { + WebKitURIRequest* uri_request = webkit_navigation_action_get_request(navigation_action); + const char* uri = webkit_uri_request_get_uri(uri_request); + printf("Creating new window: %s\n", uri); + notebook_append(notebook, uri); + gtk_notebook_set_show_tabs(notebook, true); + return NULL; + } else { + webkit_web_view_run_javascript(notebook_get_webview(notebook), + "alert('Too many tabs, not opening a new one')", NULL, NULL, NULL); + } /* WebKitGTK documentation recommends returning the new webview. * I imagine that this might allow e.g., to go back in a new tab * or generally to keep track of history. @@ -216,42 +215,42 @@ GtkWidget* handle_create_new_tab(WebKitWebView* self, void notebook_append(GtkNotebook* notebook, const char* uri) { - if(NUM_TABS < MAX_NUM_TABS || NUM_TABS == 0){ - GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(window)); - GdkVisual* rgba_visual = gdk_screen_get_rgba_visual(screen); - GdkRGBA rgba; - - gdk_rgba_parse(&rgba, BG_COLOR); - - WebKitWebView* view = webview_new(); - - gtk_widget_set_visual(GTK_WIDGET(window), rgba_visual); - g_signal_connect(view, "load_changed", G_CALLBACK(load_changed), notebook); - g_signal_connect(view, "create", G_CALLBACK(handle_create_new_tab), notebook); - - int n = gtk_notebook_append_page(notebook, GTK_WIDGET(view), NULL); - gtk_notebook_set_tab_reorderable(notebook, GTK_WIDGET(view), true); - gtk_widget_show_all(GTK_WIDGET(window)); - gtk_widget_hide(GTK_WIDGET(bar)); - webkit_web_view_set_background_color(view, &rgba); - load_uri(view, (uri) ? uri : HOME); - - if (CUSTOM_STYLE_ENABLED) { - char* style_js = malloc(STYLE_N + 1); - read_style_js(style_js); - webkit_web_view_run_javascript(notebook_get_webview(notebook), style_js, - NULL, NULL, NULL); - free(style_js); - } - - gtk_notebook_set_current_page(notebook, n); - gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(view), "-"); - webkit_web_view_set_zoom_level(view, ZOOM); - NUM_TABS+=1; - } else { - webkit_web_view_run_javascript(notebook_get_webview(notebook), - "alert('Too many tabs, not opening a new one')", NULL, NULL, NULL); - } + if (NUM_TABS < MAX_NUM_TABS || NUM_TABS == 0) { + GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(window)); + GdkVisual* rgba_visual = gdk_screen_get_rgba_visual(screen); + GdkRGBA rgba; + + gdk_rgba_parse(&rgba, BG_COLOR); + + WebKitWebView* view = webview_new(); + + gtk_widget_set_visual(GTK_WIDGET(window), rgba_visual); + g_signal_connect(view, "load_changed", G_CALLBACK(load_changed), notebook); + g_signal_connect(view, "create", G_CALLBACK(handle_create_new_tab), notebook); + + int n = gtk_notebook_append_page(notebook, GTK_WIDGET(view), NULL); + gtk_notebook_set_tab_reorderable(notebook, GTK_WIDGET(view), true); + gtk_widget_show_all(GTK_WIDGET(window)); + gtk_widget_hide(GTK_WIDGET(bar)); + webkit_web_view_set_background_color(view, &rgba); + load_uri(view, (uri) ? uri : HOME); + + if (CUSTOM_STYLE_ENABLED) { + char* style_js = malloc(STYLE_N + 1); + read_style_js(style_js); + webkit_web_view_run_javascript(notebook_get_webview(notebook), style_js, + NULL, NULL, NULL); + free(style_js); + } + + gtk_notebook_set_current_page(notebook, n); + gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(view), "-"); + webkit_web_view_set_zoom_level(view, ZOOM); + NUM_TABS += 1; + } else { + webkit_web_view_run_javascript(notebook_get_webview(notebook), + "alert('Too many tabs, not opening a new one')", NULL, NULL, NULL); + } } void show_bar(GtkNotebook* notebook) @@ -338,7 +337,7 @@ int handle_key(func id, GtkNotebook* notebook) case close_tab: gtk_notebook_remove_page(notebook, gtk_notebook_get_current_page(notebook)); - NUM_TABS-=1; + NUM_TABS -= 1; switch (gtk_notebook_get_n_pages(notebook)) { case 0: -- cgit v1.2.3