custom alert first pass, with GPT-4 help
This commit is contained in:
parent
a24af4aad1
commit
1cf68bb1fe
2
config.h
2
config.h
|
@ -21,7 +21,7 @@
|
||||||
#define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */
|
#define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */
|
||||||
#define BG_COLOR "#FEFEFE" /* "FEFEFE", "#1E1E2E" */
|
#define BG_COLOR "#FEFEFE" /* "FEFEFE", "#1E1E2E" */
|
||||||
#define DEBUG false
|
#define DEBUG false
|
||||||
#define MAX_NUM_TABS 10 // set to 0 or false if you want unlimited tabs, or look at the relevant rose.c code.
|
#define MAX_NUM_TABS 8 // set to 0 or false if you want unlimited tabs, or look at the relevant rose.c code.
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
goback,
|
goback,
|
||||||
|
|
|
@ -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 1781 + 1
|
#define STYLE_N 3640 + 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 1781 + 1
|
#define STYLE_N 3640 + 1
|
||||||
|
|
||||||
void read_style_js(char* string);
|
void read_style_js(char* string);
|
||||||
|
|
||||||
|
|
|
@ -70,5 +70,66 @@ if(styles != null){
|
||||||
console.log('Style changed')
|
console.log('Style changed')
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body.style.visibility = "visible"
|
|
||||||
|
|
||||||
|
// 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');
|
||||||
|
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');
|
||||||
|
};
|
||||||
|
|
||||||
|
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%;
|
||||||
|
}
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}`;
|
||||||
|
document.head.appendChild(style);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the alert dialog
|
||||||
|
document.getElementById('alertMessage').textContent = message;
|
||||||
|
alertDiv.classList.remove('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
// alert("Hello world!")
|
||||||
|
document.body.style.visibility = "visible"
|
||||||
|
|
10
rose.c
10
rose.c
|
@ -235,6 +235,15 @@ void notebook_append(GtkNotebook* notebook, const char* uri)
|
||||||
gtk_widget_hide(GTK_WIDGET(bar));
|
gtk_widget_hide(GTK_WIDGET(bar));
|
||||||
webkit_web_view_set_background_color(view, &rgba);
|
webkit_web_view_set_background_color(view, &rgba);
|
||||||
load_uri(view, (uri) ? uri : HOME);
|
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_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);
|
||||||
|
@ -329,6 +338,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;
|
||||||
|
|
||||||
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