feat: add readability mode, and explain how to enable it.

This commit is contained in:
NunoSempere 2023-02-05 03:11:56 +01:00
parent 9a533b7e26
commit be043958f0
8 changed files with 2548 additions and 81 deletions

View File

@ -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:

View 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

Binary file not shown.

View 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);
}
*/

View File

@ -0,0 +1,8 @@
#ifndef READABILITY
#define READABILITY
#define READABILITY_N 84251 + 1
void read_readability_js(char* string);
#endif

File diff suppressed because it is too large Load Diff

View 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"

18
rose.c
View File

@ -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, \
@ -303,11 +304,28 @@ int handle_key(func id, GtkNotebook *notebook)
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;
} }