alerts v2, formatting
This commit is contained in:
parent
1cf68bb1fe
commit
98f6d5630f
|
@ -4,4 +4,3 @@ void str_init(char* str, int n)
|
||||||
str[i] = ' ';
|
str[i] = ' ';
|
||||||
str[n] = '\0';
|
str[n] = '\0';
|
||||||
} // could also use <https://manpages.ubuntu.com/manpages/impish/man3/strinit.3pub.html>
|
} // could also use <https://manpages.ubuntu.com/manpages/impish/man3/strinit.3pub.html>
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "../libre_redirect/str_replace_start.h"
|
|
||||||
#include "../libre_redirect/str_init.h"
|
#include "../libre_redirect/str_init.h"
|
||||||
|
#include "../libre_redirect/str_replace_start.h"
|
||||||
|
|
||||||
#define SHORTCUT_N 41
|
#define SHORTCUT_N 41
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ int shortcut_expand(const char* uri, char* output)
|
||||||
};
|
};
|
||||||
|
|
||||||
// len = sizeof(shortcuts) / sizeof(shortcuts[0]);
|
// len = sizeof(shortcuts) / sizeof(shortcuts[0]);
|
||||||
len = sizeof(shortcuts) / sizeof(char *);
|
len = sizeof(shortcuts) / sizeof(char*);
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
int replace_check = str_replace_start(tmp_uri, shortcuts[i],
|
int replace_check = str_replace_start(tmp_uri, shortcuts[i],
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#define STYLE_N 3640 + 1
|
#define STYLE_N 3858 + 1
|
||||||
|
|
||||||
void read_style_js(char* string)
|
void read_style_js(char* string)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef STYLE
|
#ifndef STYLE
|
||||||
#define STYLE
|
#define STYLE
|
||||||
|
|
||||||
#define STYLE_N 3640 + 1
|
#define STYLE_N 3858 + 1
|
||||||
|
|
||||||
void read_style_js(char* string);
|
void read_style_js(char* string);
|
||||||
|
|
||||||
|
|
|
@ -73,37 +73,19 @@ if(styles != null){
|
||||||
|
|
||||||
// Replace default alert with new function
|
// Replace default alert with new function
|
||||||
// whose style can be changed!
|
// whose style can be changed!
|
||||||
window.alert = function(message) {
|
window.alert = (message) => {
|
||||||
// Check if the alert dialog already exists
|
let alertDiv = document.getElementById('customAlert');
|
||||||
var alertDiv = document.getElementById('customAlert');
|
|
||||||
if (!alertDiv) {
|
if (!alertDiv) {
|
||||||
// Create the alert dialog
|
const html = `
|
||||||
alertDiv = document.createElement('div');
|
<div id="customAlert" class="custom-alert">
|
||||||
alertDiv.id = 'customAlert';
|
<div class="custom-alert-content">
|
||||||
alertDiv.className = 'custom-alert hidden';
|
<p id="alertMessage"></p>
|
||||||
|
<button id="alertOkButton">OK</button>
|
||||||
var contentDiv = document.createElement('div');
|
</div>
|
||||||
contentDiv.className = 'custom-alert-content';
|
</div>
|
||||||
|
<style>
|
||||||
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');
|
|
||||||
};
|
|
||||||
|
|
||||||
contentDiv.appendChild(alertMessage);
|
|
||||||
contentDiv.appendChild(okButton);
|
|
||||||
alertDiv.appendChild(contentDiv);
|
|
||||||
document.body.appendChild(alertDiv);
|
|
||||||
|
|
||||||
// Inject CSS
|
|
||||||
var style = document.createElement('style');
|
|
||||||
style.innerHTML = `
|
|
||||||
.custom-alert {
|
.custom-alert {
|
||||||
|
display: none;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 999;
|
z-index: 999;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
@ -119,17 +101,33 @@ window.alert = function(message) {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
border: 1px solid #888;
|
border: 1px solid #888;
|
||||||
width: 80%;
|
width: 80%;
|
||||||
|
font-family: monospace; /* Use monospace font */
|
||||||
}
|
}
|
||||||
.hidden {
|
.visible {
|
||||||
display: none;
|
display: block;
|
||||||
}`;
|
}
|
||||||
document.head.appendChild(style);
|
</style>
|
||||||
|
`;
|
||||||
|
document.body.insertAdjacentHTML('beforeend', html);
|
||||||
|
alertDiv = document.getElementById('customAlert');
|
||||||
|
document.getElementById('alertOkButton').onclick = () => {
|
||||||
|
alertDiv.classList.remove('visible');
|
||||||
|
document.removeEventListener('keydown', dismissAlert);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the alert dialog
|
const dismissAlert = (event) => {
|
||||||
|
if (event.key === 'Enter' /*&& event.ctrlKey*/ && alertDiv.classList.contains('visible')) {
|
||||||
|
alertDiv.classList.remove('visible');
|
||||||
|
document.removeEventListener('keydown', dismissAlert);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('keydown', dismissAlert);
|
||||||
document.getElementById('alertMessage').textContent = message;
|
document.getElementById('alertMessage').textContent = message;
|
||||||
alertDiv.classList.remove('hidden');
|
alertDiv.classList.add('visible');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// alert("Hello world!")
|
// alert("Hello world!")
|
||||||
document.body.style.visibility = "visible"
|
document.body.style.visibility = "visible"
|
||||||
|
|
9
rose.c
9
rose.c
|
@ -111,7 +111,6 @@ void load_uri(WebKitWebView* view, const char* uri)
|
||||||
snprintf(tmp, sizeof(tmp), SEARCH, uri);
|
snprintf(tmp, sizeof(tmp), SEARCH, uri);
|
||||||
webkit_web_view_load_uri(view, tmp);
|
webkit_web_view_load_uri(view, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +194,7 @@ GtkWidget* handle_create_new_tab(WebKitWebView* self,
|
||||||
WebKitNavigationAction* navigation_action,
|
WebKitNavigationAction* navigation_action,
|
||||||
GtkNotebook* notebook)
|
GtkNotebook* notebook)
|
||||||
{
|
{
|
||||||
if(NUM_TABS < MAX_NUM_TABS || NUM_TABS == 0){
|
if (NUM_TABS < MAX_NUM_TABS || NUM_TABS == 0) {
|
||||||
WebKitURIRequest* uri_request = webkit_navigation_action_get_request(navigation_action);
|
WebKitURIRequest* uri_request = webkit_navigation_action_get_request(navigation_action);
|
||||||
const char* uri = webkit_uri_request_get_uri(uri_request);
|
const char* uri = webkit_uri_request_get_uri(uri_request);
|
||||||
printf("Creating new window: %s\n", uri);
|
printf("Creating new window: %s\n", uri);
|
||||||
|
@ -216,7 +215,7 @@ GtkWidget* handle_create_new_tab(WebKitWebView* self,
|
||||||
|
|
||||||
void notebook_append(GtkNotebook* notebook, const char* uri)
|
void notebook_append(GtkNotebook* notebook, const char* uri)
|
||||||
{
|
{
|
||||||
if(NUM_TABS < MAX_NUM_TABS || NUM_TABS == 0){
|
if (NUM_TABS < MAX_NUM_TABS || NUM_TABS == 0) {
|
||||||
GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(window));
|
GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(window));
|
||||||
GdkVisual* rgba_visual = gdk_screen_get_rgba_visual(screen);
|
GdkVisual* rgba_visual = gdk_screen_get_rgba_visual(screen);
|
||||||
GdkRGBA rgba;
|
GdkRGBA rgba;
|
||||||
|
@ -247,7 +246,7 @@ void notebook_append(GtkNotebook* notebook, const char* uri)
|
||||||
gtk_notebook_set_current_page(notebook, n);
|
gtk_notebook_set_current_page(notebook, n);
|
||||||
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(view), "-");
|
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(view), "-");
|
||||||
webkit_web_view_set_zoom_level(view, ZOOM);
|
webkit_web_view_set_zoom_level(view, ZOOM);
|
||||||
NUM_TABS+=1;
|
NUM_TABS += 1;
|
||||||
} else {
|
} else {
|
||||||
webkit_web_view_run_javascript(notebook_get_webview(notebook),
|
webkit_web_view_run_javascript(notebook_get_webview(notebook),
|
||||||
"alert('Too many tabs, not opening a new one')", NULL, NULL, NULL);
|
"alert('Too many tabs, not opening a new one')", NULL, NULL, NULL);
|
||||||
|
@ -338,7 +337,7 @@ int handle_key(func id, GtkNotebook* notebook)
|
||||||
|
|
||||||
case close_tab:
|
case close_tab:
|
||||||
gtk_notebook_remove_page(notebook, gtk_notebook_get_current_page(notebook));
|
gtk_notebook_remove_page(notebook, gtk_notebook_get_current_page(notebook));
|
||||||
NUM_TABS-=1;
|
NUM_TABS -= 1;
|
||||||
|
|
||||||
switch (gtk_notebook_get_n_pages(notebook)) {
|
switch (gtk_notebook_get_n_pages(notebook)) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user