tweak: very rudimentary version of tranquility reader mode.

This commit is contained in:
NunoSempere 2022-12-14 14:00:43 +00:00
parent fdb4ad7ced
commit 6ca97ba42f
17 changed files with 2727 additions and 9 deletions

View File

@ -1,6 +1,6 @@
CC=clang CC=clang
SRC=rose.c SRC=rose.c
REQS=./plugins/libre_redirect/*.c REQS=./plugins/*/*.c
DEPS=('webkit2gtk-4.0') DEPS=('webkit2gtk-4.0')
INCS=`pkg-config --cflags ${DEPS[@]}` INCS=`pkg-config --cflags ${DEPS[@]}`
@ -9,4 +9,5 @@ LIBS=`pkg-config --libs ${DEPS[@]}`
# Optional adblocking depends on https://github.com/jun7/wyebadblock # Optional adblocking depends on https://github.com/jun7/wyebadblock
WYEBAB='-L/usr/lib/wyebrowser/adblock.so' WYEBAB='-L/usr/lib/wyebrowser/adblock.so'
echo $CC $INCS $LIBS $SRC $REQS $WYEBAB -o rose
$CC $INCS $LIBS $SRC $REQS $WYEBAB -o rose $CC $INCS $LIBS $SRC $REQS $WYEBAB -o rose

View File

@ -48,7 +48,8 @@ typedef enum {
show_searchbar, show_searchbar,
show_finder, show_finder,
finder_next, finder_next,
finder_prev finder_prev,
prettify
} func; } func;
#define SFT 1 << 0 #define SFT 1 << 0
@ -76,7 +77,8 @@ static struct {
{ CTRL, KEY(l), show_searchbar }, { CTRL, KEY(l), show_searchbar },
{ CTRL, KEY(f), show_finder }, { CTRL, KEY(f), show_finder },
{ CTRL, KEY(n), finder_next }, { CTRL, KEY(n), finder_next },
{ CTRL | SFT, KEY(N), finder_prev } { CTRL | SFT, KEY(N), finder_prev },
{ CTRL, KEY(p), prettify },
}; };
/* ^ For controls more akin to normal browsers */ /* ^ For controls more akin to normal browsers */
/* Reference for the key shorthand: /* Reference for the key shorthand:

View File

@ -2,7 +2,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#define LIBRE_N 12 #define LIBRE_N 19
#define DEBUG false #define DEBUG false
/* Inspired by https://libredirect.github.io/, but in C. */ /* Inspired by https://libredirect.github.io/, but in C. */
@ -32,17 +32,19 @@ int libre_redirect(const char* uri, char* output){
"https://www.reddit.com", "https://www.reddit.com",
"https://medium.com", "https://medium.com",
"https://translate.google.com", "https://translate.google.com",
"https://forum.effectivealtruism.org" "https://forum.effectivealtruism.org",
// "https://www.bloomberg.com"
}; };
char* alternatives[] = { char* alternatives[] = {
"https://yt.artemislena.eu", "https://yt.artemislena.eu",
"https://teddit.nunosempere.com", "https://teddit.nunosempere.com",
"https://scribe.rip", "https://scribe.rip",
"https://simplytranslate.org/", "https://simplytranslate.org/",
"https://ea.greaterwrong.com" "https://ea.greaterwrong.com",
// "https://archive.is/https://www.bloomberg.com"
}; };
int n = sizeof(sites)/sizeof(sites[0]);
for(int i=0; i<4; i++){ for(int i=0; i<n ; i++){
int replace_check = str_replace_start(tmp_uri, sites[i], alternatives[i], output); int replace_check = str_replace_start(tmp_uri, sites[i], alternatives[i], output);
if(replace_check == 2){ if(replace_check == 2){
if(DEBUG) printf("tmp_uri: %s\n", tmp_uri); if(DEBUG) printf("tmp_uri: %s\n", tmp_uri);

View File

@ -1,7 +1,7 @@
#ifndef LIBRE_REDIRECT #ifndef LIBRE_REDIRECT
#define LIBRE_REDIRECT #define LIBRE_REDIRECT
#define LIBRE_N 12 #define LIBRE_N 19
int libre_redirect(const char* uri, char* uri_filtered); int libre_redirect(const char* uri, char* uri_filtered);
void str_init(char* str, int n); void str_init(char* str, int n);

View File

@ -0,0 +1,3 @@
Taken from <https://raw.githubusercontent.com/ushnisha/tranquility-reader-webextensions/master/content_scripts/tranquilize.js>
The file has 46193 characters. Or 46194 including the line terminator.

View File

@ -0,0 +1,50 @@
(() => {
'use strict';
const addStyle = (() => {
const parent = document.head || document.body || document.documentElement;
const style = document.createElement('style');
style.type = 'text/css';
parent.appendChild(style);
return (css) => {
style.appendChild(document.createTextNode(css + '\n'));
};
})();
Array.from(document.styleSheets, (css) => css.disabled = true);
// like a Firefox Reader View
const nightmode = `
* {
margin-top: initial !important;
padding-top: initial !important;
}
body {
margin-left: auto !important;
margin-right: auto !important;
max-width: 70% !important;
font-size: 1.6em !important;
line-height: 1.25em !important;
background-color: #343A3A !important;
color: #FDFDFD !important;
white-space: pre-line !important;
}
h1 {
line-height: 1em !important;
}
a {
color: lightskyblue !important;
background-color: initial !important;
}
img {
max-width: 100% !important;
}
pre, code {
white-space: pre-wrap !important;
}
`;
addStyle(nightmode);
})();

BIN
plugins/readability/tranquility Executable file

Binary file not shown.

View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define TRANQUILITY_N 46288
void read_tranquility_js(char* string){
FILE *fp=fopen("/home/loki/Documents/core/software/fresh/C/rose-browser/rose-bud-personal/plugins/tranquility/snippet.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* tranquility_js = malloc(TRANQUILITY_N+1);
read_tranquility_js(tranquility_js);
printf("%s", tranquility_js);
free(tranquility_js);
}
*/

View File

@ -0,0 +1,8 @@
#ifndef TRANQUILITY
#define TRANQUILITY
#define TRANQUILITY_N 46288
void read_tranquility_js(char* string);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
Taken from <https://raw.githubusercontent.com/ushnisha/tranquility-reader-webextensions/master/content_scripts/tranquilize.js>
The file has 46193 characters. Or 46194 including the line terminator.

View File

@ -0,0 +1,50 @@
(() => {
'use strict';
const addStyle = (() => {
const parent = document.head || document.body || document.documentElement;
const style = document.createElement('style');
style.type = 'text/css';
parent.appendChild(style);
return (css) => {
style.appendChild(document.createTextNode(css + '\n'));
};
})();
Array.from(document.styleSheets, (css) => css.disabled = true);
// like a Firefox Reader View
const nightmode = `
* {
margin-top: initial !important;
padding-top: initial !important;
}
body {
margin-left: auto !important;
margin-right: auto !important;
max-width: 70% !important;
font-size: 1.6em !important;
line-height: 1.25em !important;
background-color: #343A3A !important;
color: #FDFDFD !important;
white-space: pre-line !important;
}
h1 {
line-height: 1em !important;
}
a {
color: lightskyblue !important;
background-color: initial !important;
}
img {
max-width: 100% !important;
}
pre, code {
white-space: pre-wrap !important;
}
`;
addStyle(nightmode);
})();

BIN
plugins/tranquility/tranquility Executable file

Binary file not shown.

View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define TRANQUILITY_N 46288
void read_tranquility_js(char* string){
FILE *fp=fopen("/home/loki/Documents/core/software/fresh/C/rose-browser/rose-bud-personal/plugins/tranquility/snippet.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* tranquility_js = malloc(TRANQUILITY_N+1);
read_tranquility_js(tranquility_js);
printf("%s", tranquility_js);
free(tranquility_js);
}
*/

View File

@ -0,0 +1,8 @@
#ifndef TRANQUILITY
#define TRANQUILITY
#define TRANQUILITY_N 46288
void read_tranquility_js(char* string);
#endif

File diff suppressed because it is too large Load Diff

15
rose.c
View File

@ -15,6 +15,7 @@
#include "config.h" #include "config.h"
#include "plugins/libre_redirect/libre_redirect.h" #include "plugins/libre_redirect/libre_redirect.h"
#include "plugins/tranquility/tranquility.h"
#define CACHE \ #define CACHE \
"base-cache-directory", CACHE_DIR, \ "base-cache-directory", CACHE_DIR, \
@ -273,6 +274,20 @@ int handle_key(func id, GtkNotebook *notebook)
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 prettify:{
printf("prettify\n");
webkit_web_view_run_javascript(notebook_get_webview(notebook),
"alert('Tranquilizing!')",
NULL, NULL, NULL);
char* tranquility_js = malloc(TRANQUILITY_N+1);
read_tranquility_js(tranquility_js);
webkit_web_view_run_javascript(notebook_get_webview(notebook),
tranquility_js,
NULL, NULL, NULL);
free(tranquility_js);
break;
}
} }
return 1; return 1;