feat: add readability mode, and explain how to enable it.
This commit is contained in:
parent
9a533b7e26
commit
be043958f0
|
@ -52,6 +52,7 @@ typedef enum {
|
||||||
finder_next,
|
finder_next,
|
||||||
finder_prev,
|
finder_prev,
|
||||||
newtab,
|
newtab,
|
||||||
|
/*prettify,*/
|
||||||
hidebar
|
hidebar
|
||||||
} func;
|
} func;
|
||||||
|
|
||||||
|
@ -81,6 +82,7 @@ static struct {
|
||||||
{ CTRL, KEY(n), finder_next },
|
{ CTRL, KEY(n), finder_next },
|
||||||
{ CTRL | SFT, KEY(N), finder_prev },
|
{ CTRL | SFT, KEY(N), finder_prev },
|
||||||
{ CTRL, KEY(t), newtab },
|
{ CTRL, KEY(t), newtab },
|
||||||
|
// { CTRL, KEY(p), prettify },
|
||||||
{ 0x0, KEY(Escape), hidebar }
|
{ 0x0, KEY(Escape), hidebar }
|
||||||
};
|
};
|
||||||
/* For controls more akin to normal browsers, use:
|
/* For controls more akin to normal browsers, use:
|
||||||
|
|
62
plugins/readability/README.md
Normal file
62
plugins/readability/README.md
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
## Readability
|
||||||
|
|
||||||
|
Taken from <https://raw.githubusercontent.com/ushnisha/readability-reader-webextensions/master/content_scripts/tranquilize.js>
|
||||||
|
|
||||||
|
|
||||||
|
## To enable it
|
||||||
|
|
||||||
|
In rose.c uncomment:
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
// #include "plugins/readability/readability.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
case prettify:
|
||||||
|
{
|
||||||
|
|
||||||
|
char* readability_js = malloc(READABILITY_N+1);
|
||||||
|
read_readability_js(readability_js);
|
||||||
|
webkit_web_view_run_javascript(notebook_get_webview(notebook),
|
||||||
|
readability_js,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
free(readability_js);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
In config.h, uncomment:
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
goback,
|
||||||
|
goforward,
|
||||||
|
refresh,
|
||||||
|
refresh_force,
|
||||||
|
back_to_home,
|
||||||
|
toggle_fullscreen,
|
||||||
|
zoomin,
|
||||||
|
zoomout,
|
||||||
|
zoom_reset,
|
||||||
|
next_tab,
|
||||||
|
prev_tab,
|
||||||
|
close_tab,
|
||||||
|
show_searchbar,
|
||||||
|
show_finder,
|
||||||
|
finder_next,
|
||||||
|
finder_prev,
|
||||||
|
newtab,
|
||||||
|
/*prettify,*/
|
||||||
|
hidebar
|
||||||
|
} func;
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
// { CTRL, KEY(p), prettify },
|
||||||
|
|
||||||
|
|
||||||
|
```
|
BIN
plugins/readability/readability
Executable file
BIN
plugins/readability/readability
Executable file
Binary file not shown.
29
plugins/readability/readability.c
Normal file
29
plugins/readability/readability.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define READABILITY_N 84251 + 1
|
||||||
|
|
||||||
|
void read_readability_js(char* string){
|
||||||
|
FILE *fp=fopen("/home/loki/Documents/core/software/fresh/C/rose-browser/rose-bud-personal/plugins/readability/readability.js", "r");
|
||||||
|
if (!fp) { // fp is NULL, fopen failed
|
||||||
|
fprintf(stderr, "Failed to open file\n");
|
||||||
|
string=NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int i=0;
|
||||||
|
int c;
|
||||||
|
while ((c = fgetc(fp)) != EOF){
|
||||||
|
string[i++] = c;
|
||||||
|
}
|
||||||
|
string[i]='\0';
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
int main(){
|
||||||
|
char* readability_js = malloc(READABILITY_N+1);
|
||||||
|
read_readability_js(readability_js);
|
||||||
|
printf("%s", readability_js);
|
||||||
|
free(readability_js);
|
||||||
|
}
|
||||||
|
*/
|
8
plugins/readability/readability.h
Normal file
8
plugins/readability/readability.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef READABILITY
|
||||||
|
#define READABILITY
|
||||||
|
|
||||||
|
#define READABILITY_N 84251 + 1
|
||||||
|
|
||||||
|
void read_readability_js(char* string);
|
||||||
|
|
||||||
|
#endif
|
2340
plugins/readability/readability.js
Normal file
2340
plugins/readability/readability.js
Normal file
File diff suppressed because it is too large
Load Diff
8
plugins/readability/recompute_READABILITY_N.sh
Executable file
8
plugins/readability/recompute_READABILITY_N.sh
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
|
function sedr(){
|
||||||
|
find ./ -type f -exec sed -i -e "$1" {} \;
|
||||||
|
} ## e.g., sedr "s/target/replacement/g"
|
||||||
|
|
||||||
|
READABILITY_N=$(wc -c ./plugins/*/readability.js | cut -d " " -f 1)
|
||||||
|
sedr "s/^#define READABILITY_N .*/#define READABILITY_N $READABILITY_N + 1/g"
|
||||||
|
|
180
rose.c
180
rose.c
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
// #include "plugins/libre_redirect/libre_redirect.h"
|
// #include "plugins/libre_redirect/libre_redirect.h"
|
||||||
|
// #include "plugins/readability/readability.h"
|
||||||
|
|
||||||
#define CACHE \
|
#define CACHE \
|
||||||
"base-cache-directory", CACHE_DIR, \
|
"base-cache-directory", CACHE_DIR, \
|
||||||
|
@ -207,107 +208,124 @@ int handle_key(func id, GtkNotebook *notebook)
|
||||||
static bool is_fullscreen = 0;
|
static bool is_fullscreen = 0;
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case goback:
|
case goback:
|
||||||
webkit_web_view_go_back(notebook_get_webview(notebook));
|
webkit_web_view_go_back(notebook_get_webview(notebook));
|
||||||
break;
|
break;
|
||||||
case goforward:
|
case goforward:
|
||||||
webkit_web_view_go_forward(notebook_get_webview(notebook));
|
webkit_web_view_go_forward(notebook_get_webview(notebook));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case refresh:
|
case refresh:
|
||||||
webkit_web_view_reload(notebook_get_webview(notebook));
|
webkit_web_view_reload(notebook_get_webview(notebook));
|
||||||
break;
|
break;
|
||||||
case refresh_force:
|
case refresh_force:
|
||||||
webkit_web_view_reload_bypass_cache(notebook_get_webview(notebook));
|
webkit_web_view_reload_bypass_cache(notebook_get_webview(notebook));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case back_to_home:
|
case back_to_home:
|
||||||
load_uri(notebook_get_webview(notebook), HOME);
|
load_uri(notebook_get_webview(notebook), HOME);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case zoomin:
|
case zoomin:
|
||||||
webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom += ZOOM_VAL));
|
webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom += ZOOM_VAL));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case zoomout:
|
case zoomout:
|
||||||
webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom -= ZOOM_VAL));
|
webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom -= ZOOM_VAL));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case zoom_reset:
|
case zoom_reset:
|
||||||
webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom = ZOOM));
|
webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom = ZOOM));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case prev_tab:
|
case prev_tab:
|
||||||
if (gtk_notebook_get_current_page(notebook) == 0) {
|
if (gtk_notebook_get_current_page(notebook) == 0) {
|
||||||
gtk_notebook_set_current_page(notebook,
|
gtk_notebook_set_current_page(notebook,
|
||||||
gtk_notebook_get_n_pages(notebook) - 1);
|
gtk_notebook_get_n_pages(notebook) - 1);
|
||||||
} else {
|
} else {
|
||||||
gtk_notebook_prev_page(notebook);
|
gtk_notebook_prev_page(notebook);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case next_tab:
|
case next_tab:
|
||||||
if (gtk_notebook_get_current_page(notebook) ==
|
if (gtk_notebook_get_current_page(notebook) ==
|
||||||
gtk_notebook_get_n_pages(notebook) - 1) {
|
gtk_notebook_get_n_pages(notebook) - 1) {
|
||||||
notebook_append(notebook, NULL);
|
notebook_append(notebook, NULL);
|
||||||
gtk_notebook_set_show_tabs(notebook, true);
|
gtk_notebook_set_show_tabs(notebook, true);
|
||||||
} else {
|
} else {
|
||||||
gtk_notebook_next_page(notebook);
|
gtk_notebook_next_page(notebook);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
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));
|
||||||
|
|
||||||
switch (gtk_notebook_get_n_pages(notebook)) {
|
switch (gtk_notebook_get_n_pages(notebook)) {
|
||||||
case 0:
|
case 0:
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
gtk_notebook_set_show_tabs(notebook, false);
|
gtk_notebook_set_show_tabs(notebook, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case toggle_fullscreen:
|
case toggle_fullscreen:
|
||||||
if (is_fullscreen)
|
if (is_fullscreen)
|
||||||
gtk_window_unfullscreen(window);
|
gtk_window_unfullscreen(window);
|
||||||
else
|
else
|
||||||
gtk_window_fullscreen(window);
|
gtk_window_fullscreen(window);
|
||||||
|
|
||||||
is_fullscreen = ! is_fullscreen;
|
is_fullscreen = ! is_fullscreen;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case show_searchbar:
|
case show_searchbar:
|
||||||
entry_mode = _SEARCH;
|
entry_mode = _SEARCH;
|
||||||
show_bar(notebook);
|
show_bar(notebook);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case show_finder:
|
case show_finder:
|
||||||
entry_mode = _FIND;
|
entry_mode = _FIND;
|
||||||
show_bar(notebook);
|
show_bar(notebook);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case finder_next:
|
case finder_next:
|
||||||
webkit_find_controller_search_next(
|
webkit_find_controller_search_next(
|
||||||
webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
|
webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case finder_prev:
|
case finder_prev:
|
||||||
webkit_find_controller_search_previous(
|
webkit_find_controller_search_previous(
|
||||||
webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
|
webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case newtab:
|
case newtab:
|
||||||
notebook_append(notebook, NULL);
|
notebook_append(notebook, NULL);
|
||||||
gtk_notebook_set_show_tabs(notebook, true);
|
gtk_notebook_set_show_tabs(notebook, true);
|
||||||
|
break;
|
||||||
|
|
||||||
case hidebar:
|
case hidebar:
|
||||||
entry_mode = _HIDDEN;
|
entry_mode = _HIDDEN;
|
||||||
show_bar(notebook);
|
show_bar(notebook);
|
||||||
|
break;
|
||||||
|
/*
|
||||||
|
case prettify:
|
||||||
|
{
|
||||||
|
|
||||||
|
char* readability_js = malloc(READABILITY_N+1);
|
||||||
|
read_readability_js(readability_js);
|
||||||
|
webkit_web_view_run_javascript(notebook_get_webview(notebook),
|
||||||
|
readability_js,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
free(readability_js);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user