feat: save progress.

Now has a functional reader mode.
This commit is contained in:
NunoSempere 2022-12-14 16:49:24 +00:00
parent 6ca97ba42f
commit 246128e0c9
21 changed files with 2388 additions and 1361 deletions

View File

@ -29,7 +29,7 @@
#define BG_COLOR "#1E1E2E" /* or "#FEFEFE" if you are not using the dark theme. */ #define BG_COLOR "#1E1E2E" /* or "#FEFEFE" if you are not using the dark theme. */
#define WIDTH 500 #define WIDTH 500
#define HEIGHT 400 #define HEIGHT 400
#define DEBUG false #define DEBUG true
typedef enum { typedef enum {
goback, goback,

View File

@ -30,7 +30,7 @@
#define ZOOM 1.4 /* Starting zoom level.*/ #define ZOOM 1.4 /* Starting zoom level.*/
#define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */ #define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */
#define BG_COLOR "#FEFEFE" /*"#1E1E2E" */ #define BG_COLOR "#FEFEFE" /*"#1E1E2E" */
#define DEBUG false #define DEBUG true
typedef enum { typedef enum {
goback, goback,

View File

@ -3,7 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#define LIBRE_N 19 #define LIBRE_N 19
#define DEBUG false #define DEBUG true
/* Inspired by https://libredirect.github.io/, but in C. */ /* Inspired by https://libredirect.github.io/, but in C. */
@ -33,7 +33,7 @@ int libre_redirect(const char* uri, char* output){
"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" "https://www.bloomberg.com"
}; };
char* alternatives[] = { char* alternatives[] = {
"https://yt.artemislena.eu", "https://yt.artemislena.eu",
@ -41,7 +41,7 @@ int libre_redirect(const char* uri, char* output){
"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" "https://archive.is/https://www.bloomberg.com"
}; };
int n = sizeof(sites)/sizeof(sites[0]); int n = sizeof(sites)/sizeof(sites[0]);
for(int i=0; i<n ; i++){ for(int i=0; i<n ; i++){

View File

@ -1,7 +1,7 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#define DEBUG false #define DEBUG true
/* /*
See also: See also:

View File

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

View File

@ -0,0 +1,29 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define READABILITY_N 83750
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 83750
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 readability.js | cut -d " " -f 1)
sedr "s/^#define READABILITY_N .*/#define READABILITY_N $READABILITY_N/g"

View File

@ -1,50 +0,0 @@
(() => {
'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);
})();

View File

@ -1,30 +0,0 @@
#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

@ -1,8 +0,0 @@
#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

12
rose.c
View File

@ -15,7 +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" #include "plugins/readability/readability.h"
#define CACHE \ #define CACHE \
"base-cache-directory", CACHE_DIR, \ "base-cache-directory", CACHE_DIR, \
@ -275,16 +275,18 @@ int handle_key(func id, GtkNotebook *notebook)
webkit_web_view_get_find_controller(notebook_get_webview(notebook))); webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
break; break;
case prettify:{ case prettify:{
if(DEBUG){
printf("prettify\n"); printf("prettify\n");
webkit_web_view_run_javascript(notebook_get_webview(notebook), webkit_web_view_run_javascript(notebook_get_webview(notebook),
"alert('Tranquilizing!')", "alert('Tranquilizing!')",
NULL, NULL, NULL); NULL, NULL, NULL);
char* tranquility_js = malloc(TRANQUILITY_N+1); }
read_tranquility_js(tranquility_js); char* readability_js = malloc(READABILITY_N+1);
read_readability_js(readability_js);
webkit_web_view_run_javascript(notebook_get_webview(notebook), webkit_web_view_run_javascript(notebook_get_webview(notebook),
tranquility_js, readability_js,
NULL, NULL, NULL); NULL, NULL, NULL);
free(tranquility_js); free(readability_js);
break; break;
} }