Compare commits

...

56 Commits

Author SHA1 Message Date
1e45fb881b tweak: change README.md 2023-01-22 13:40:58 +01:00
00113a38f4 tweak: add documentation for segfault, debug in build.sh 2023-01-22 13:39:25 +01:00
707b84492c feat: add open in new tab functionality. 2023-01-22 13:39:07 +01:00
14cae1987c tweak: various qol improvements 2023-01-07 00:31:12 +01:00
b3a0f14b2f tweak: allow rose.desktop to be used as default mime type
and add instructions to do so.
2023-01-04 15:42:08 +01:00
4958d9eeaa tweaks: redirect wikipedia to wikiless & add max tab title length. 2022-12-27 15:39:18 +01:00
4da5aad23e tweak: README 2022-12-17 21:10:59 +01:00
dfa4b299a4 tweak: light cleanup. 2022-12-17 21:04:01 +01:00
f8ed7f9ef7 tweak: update config.def.h 2022-12-17 20:31:34 +01:00
c27525cc32 tweak: background color 2022-12-16 01:40:50 +01:00
8790adb0fc tweak: Reader mode. 2022-12-16 01:40:09 +01:00
350e6022df tweak: Add hide searchbar option
Also bring config.def.h up to date
2022-12-16 01:29:34 +01:00
ca5438c626 Merge branch 'personal' of github.com:NunoSempere/rose-browser into personal 2022-12-16 01:05:20 +01:00
cd6b158e3e feat: make reader mode right
Use a whiter background, which is nicer on my screen.

Add plugin step to install.sh
2022-12-16 01:03:35 +01:00
31be29c7cb tweak: rose-mklink to run on background 2022-12-15 22:53:33 +00:00
7fa7698265 bug: point to Spanish layout as known bug. 2022-12-15 21:32:07 +00:00
0a7ab47224 tweakÑ same some progress. 2022-12-15 20:44:53 +00:00
38c5c0fb47 tweak: chance variable name for a gag. 2022-12-14 17:23:19 +00:00
f27979ab6f tweak: cleanup. 2022-12-14 17:04:20 +00:00
4e153dd592 tweak: cleanup. 2022-12-14 17:02:52 +00:00
246128e0c9 feat: save progress.
Now has a functional reader mode.
2022-12-14 16:49:24 +00:00
6ca97ba42f tweak: very rudimentary version of tranquility reader mode. 2022-12-14 14:00:43 +00:00
fdb4ad7ced tweak: load default tab title sooner 2022-12-14 01:17:23 +00:00
254b0ed658 tweaks.
Now top bar appears after a search
and only goes away after an enter.
Otherwise what's the point of a bar/tab
2022-12-14 01:04:55 +00:00
5366c5d636 tweak: make tabs css better for me 2022-12-14 00:08:53 +00:00
54fffb3b66 tweak: set DEBUG flag to false 2022-12-13 22:53:59 +00:00
a5394e8a88 tweak: add another page. 2022-12-13 22:50:59 +00:00
d3caecab58 tweak: fix off-by-one error. 2022-12-13 22:31:21 +00:00
a6835ab2ae tweak: cleanup after adding "plugin" 2022-12-13 22:10:34 +00:00
21e5800bbe feat: working version of libredirect. 2022-12-13 21:59:04 +00:00
d25a6e7e79 tweak: try to integrate plugin. 2022-12-13 21:26:53 +00:00
618262d2a2 cleaup: cleanup code. 2022-12-13 20:25:35 +00:00
7c155525fd tweak: even more conciseness. 2022-12-13 20:19:45 +00:00
76ab73e38c tweak: conciseness tweaks. 2022-12-13 20:18:23 +00:00
304b4b274c feat: minimal redirection functionality. 2022-12-13 20:04:18 +00:00
9ca14fb3d4 tweak: add Ctrl+T command to add new tab. 2022-12-13 16:57:39 +00:00
892b3d3d41 cleanup: locs 2022-12-13 16:38:40 +00:00
29c07b9cbb tweak: add less sucky duckduckgo homepage 2022-12-13 16:34:04 +00:00
b2b3acf140 tweak: change name in license. 2022-12-13 15:35:42 +00:00
109d641017 tweak: save my own config.h file.
I want to keep track of this, though I agree that it shouldn't
be in the upstream source code.
2022-12-13 15:21:16 +00:00
4b2b46149c tweak: add normal browser controls
In particular, ctrl+e instead of ctrl+l was killing me.

Also, replace tabs with spaces.
2022-12-13 15:19:40 +00:00
4dffbbae14 fix: filename error 2022-12-13 15:02:39 +00:00
747499de2e hack: create new tab with correct zoom leve. Code could be cleaner.
I am fairly uncertain about the quality of this commit,
it could easily be that there is a much better way
of doing this kind of thing

In particular, maybe this could be done inside the
notebook_append function?
2022-12-13 14:59:44 +00:00
0cbb1d97a9 tweak: add color suggestion when not using dark mode. 2022-12-13 14:26:15 +00:00
c9a81029da tweak: notes default shortcuts. 2022-12-13 14:21:45 +00:00
a08755d8c9 tweak: Move TODO.md contents to README.md 2022-12-13 14:20:17 +00:00
0d9b05b7ec cleanup: user-scripts folder. 2022-12-13 14:11:39 +00:00
c88b56d6c7 tweak: add list of features I want to implement. 2022-12-13 11:08:05 +00:00
f89ef9951f tweak: use bash for mlink, use better markdown syntax for README. 2022-12-12 22:10:15 +00:00
fbf45c5c80 tweak: Change background & make bar better for me. 2022-12-12 19:03:31 +00:00
2f447f0b7b feat: Add default zoom from the start. 2022-12-12 13:39:02 +00:00
235e535008 tweak: add WIDTH and HEIGHT features. 2022-12-12 13:14:27 +00:00
19d8b63387 tweak: reorg 2022-12-12 12:45:41 +00:00
efb0491d1b tweak: rename ubuntu-20.04 file 2022-12-12 12:11:32 +00:00
bc3bb429bd tweak: attempt to launch on fullscreen 2022-12-12 11:23:15 +00:00
bebfbeb71c tweak: add compile dependencies for ubuntu 20.04 2022-12-12 11:22:57 +00:00
39 changed files with 4309 additions and 44 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
rose
config.h
# config.h
.clang-format

View File

@ -1,21 +1,37 @@
<h3 align=center> Rose Browser</h1>
<h4 align=center>Minimal browser based on webkit2gtk</h4>
## Rosebud
Personal tweaks for [rose](https://github.com/mini-rose/rose), a minimal browser based on webkit2gtk
#### Features
- tabs, cookies, caching
- minimal ui, autohiding elements
- ~400L code base
- custom gtk and websites css
- hackable without any knowledge
- builtin rose-mklink script for in-shell static links
#
### 👐 Contribute
See [contributing.md](https://github.com/mini-rose/rose/.github/contributing.md).
- tabs, cookies, caching
- minimal ui, autohiding elements
- ~400L code base (edit: no longer)
- custom gtk and websites css
- hackable without any knowledge
- builtin rose-mklink script for in-shell static links
- A few quality of life improvements.
### 📜 License
Rose is released under own license, which grants the following permissions:
- Commercial use
- Distribution
- Modification
- Private use
### 👐 Contribute
This is my personal version. Contribute upstream to [github.com/mini-rose/rose](https://github.com/mini-rose/) instead.
### To do
- [ ] Find out what each of the css elements refers to.
- [ ] Use something other than Whatsapp as an example syslink.
Done:
- [x] String substitution on uri in order to redirect to better frontends.
- [x] Present "standard" browser keybindings as an alternative.
- [x] Fix zoom in new tab
- [x] Reader mode
- [x] Add reader mode to config.def.
- [x] Make tab bar slightly prettier.
- [x] Add "open in new window" functionality.
- Useful for opening links in new tab when clicking on them and selecting that option
- And for actually opening links with the href newtab option.
- Links: <https://docs.gtk.org/gobject/func.signal_connect.html>, <https://webkitgtk.org/reference/webkit2gtk/2.37.90/signal.AutomationSession.create-web-view.html>, <https://webkitgtk.org/reference/webkit2gtk/2.26.0/WebKitWebView.html#WebKitWebView-create> <https://stackoverflow.com/questions/40180757/webkit2gtk-get-new-window-link>
### Known bugs
- [ ] Doesn't work with when Spanish is selected as the language, for some reason.

View File

@ -1,6 +1,10 @@
#!/bin/bash
CC=clang
SRC=rose.c
REQS=./plugins/*/*.c
DEPS=('webkit2gtk-4.0')
DEBUG="" # set to "-g" for debug mode.
INCS=`pkg-config --cflags ${DEPS[@]}`
LIBS=`pkg-config --libs ${DEPS[@]}`
@ -8,4 +12,5 @@ LIBS=`pkg-config --libs ${DEPS[@]}`
# Optional adblocking depends on https://github.com/jun7/wyebadblock
WYEBAB='-L/usr/lib/wyebrowser/adblock.so'
$CC $INCS $LIBS $SRC $WYEBAB -o rose
# echo $CC $INCS $LIBS $SRC $REQS $WYEBAB -o rose
$CC $DEBUG $INCS $LIBS $SRC $REQS $WYEBAB -o rose

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 mini-rose
* Copyright (c) 2022 Nuño Sempere.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and any associated documentation
@ -7,10 +7,10 @@
* sublicense copies of this sotware for their own use.
* This code does not come with any warranty.
*
* Author: fenze <contact@fenze.dev>
*/
#include <gdk/gdkkeysyms.h>
#include <stdbool.h>
/* See more:
* https://webkitgtk.org/reference/webkit2gtk/stable/class.Settings.html */
@ -18,16 +18,19 @@
"enable-back-forward-navigation-gestures", true, "enable-developer-extras", true, \
"enable-smooth-scrolling", false
#define GTK "gtk-application-prefer-dark-theme", true, "gtk-enable-animations", false
#define HOME "https://duckduckgo.com"
#define SEARCH "https://duckduckgo.com/?q=%s"
#define CACHE_DIR "/home/fenze/.cache/rose"
#define GTK "gtk-application-prefer-dark-theme", false, "gtk-enable-animations", false
#define ROSE_HOMEPAGE true
#define HOME ROSE_HOMEPAGE ? "file:///home/loki/Documents/core/software/fresh/C/rose-browser/rose-bud-personal/user-scripts/ubuntu-20.04/rose-images/rose-homepage.png" : "https://lite.duckduckgo.com/html"
#define SEARCH "https://lite.duckduckgo.com/html/?q=%s"
#define CACHE_DIR "/home/your_username/.cache/rose"
#define WIDTH 1920
#define HEIGHT 1080
#define KEY(x) GDK_KEY_##x
#define ZOOM 1 /* Starting zoom level */
#define ZOOM 1.4 /* Starting zoom level.*/
#define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */
#define BG_COLOR "#1E1E2E"
#define BG_COLOR "#FEFEFE" /* "#1E1E2E" */
#define DEBUG false
typedef enum {
goback,
@ -43,9 +46,11 @@ typedef enum {
prev_tab,
close_tab,
show_searchbar,
hide_searchbar,
show_finder,
finder_next,
finder_prev
finder_prev,
prettify
} func;
#define SFT 1 << 0
@ -57,6 +62,31 @@ static struct {
unsigned key;
func id;
} keys[] = {
{ CTRL, KEY(h), goback },
{ CTRL, KEY(j), goforward },
{ CTRL, KEY(r), refresh },
{ CTRL | SFT, KEY(R), refresh_force },
{ CTRL | SFT, KEY(H), back_to_home },
{ CTRL, KEY(equal), zoomin },
{ CTRL, KEY(minus), zoomout },
{ CTRL, KEY(0), zoom_reset },
{ CTRL, KEY(Page_Down), prev_tab },
{ CTRL, KEY(Page_Up), next_tab },
{ CTRL, KEY(t), next_tab },
{ CTRL, KEY(w), close_tab },
{ 0x0, KEY(F11), toggle_fullscreen },
{ CTRL, KEY(l), show_searchbar },
{ CTRL, KEY(k), hide_searchbar },
{ CTRL, KEY(f), show_finder },
{ CTRL, KEY(n), finder_next },
{ CTRL | SFT, KEY(N), finder_prev },
{ CTRL, KEY(p), prettify }
};
/* ^ The controls above try to be similar to those in normal browsers */
/* Reference for the key shorthand:
* <https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gdk/gdkkeysyms.h> */
/* Alternative controls: {
{ CTRL, KEY(h), goback },
{ CTRL, KEY(l), goforward },
{ CTRL, KEY(r), refresh },
@ -66,11 +96,14 @@ static struct {
{ CTRL, KEY(minus), zoomout },
{ CTRL, KEY(0), zoom_reset },
{ ALT, KEY(h), prev_tab },
{ CTRL, KEY(k), hide_searchbar },
{ ALT, KEY(l), next_tab },
{ CTRL, KEY(w), close_tab },
{ 0x0, KEY(F11), toggle_fullscreen },
{ CTRL, KEY(e), show_searchbar },
{ CTRL, KEY(f), show_finder },
{ CTRL, KEY(n), finder_next },
{ CTRL | SFT, KEY(N), finder_prev }
{ CTRL | SFT, KEY(N), finder_prev },
{ CTRL, KEY(p), prettify }
};
*/

109
config.h Normal file
View File

@ -0,0 +1,109 @@
/*
* Copyright (c) 2022 Nuño Sempere.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and any associated documentation
* files to modify, copy, merge, publish, distribute and/or
* sublicense copies of this sotware for their own use.
* This code does not come with any warranty.
*
*/
#include <gdk/gdkkeysyms.h>
#include <stdbool.h>
/* See more:
* https://webkitgtk.org/reference/webkit2gtk/stable/class.Settings.html */
#define WEBKIT \
"enable-back-forward-navigation-gestures", true, "enable-developer-extras", true, \
"enable-smooth-scrolling", false
#define GTK "gtk-application-prefer-dark-theme", false, "gtk-enable-animations", false
#define ROSE_HOMEPAGE true
#define HOME ROSE_HOMEPAGE ? "file:///home/loki/Documents/core/software/fresh/C/rose-browser/rose-bud-personal/user-scripts/ubuntu-20.04/rose-images/rose-homepage.png" : "https://lite.duckduckgo.com/html"
#define SEARCH "https://lite.duckduckgo.com/html/?q=%s"
#define CACHE_DIR "/home/loki/.cache/rose"
#define WIDTH 1920
#define HEIGHT 1080
#define KEY(x) GDK_KEY_##x
#define ZOOM 1.4 /* Starting zoom level.*/
#define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */
#define BG_COLOR "#FEFEFE" /* "FEFEFE", "#1E1E2E" */
#define DEBUG false
typedef enum {
goback,
goforward,
refresh,
refresh_force,
back_to_home,
toggle_fullscreen,
zoomin,
zoomout,
zoom_reset,
next_tab,
prev_tab,
close_tab,
show_searchbar,
hide_searchbar,
show_finder,
finder_next,
finder_prev,
prettify
} func;
#define SFT 1 << 0
#define CTRL 1 << 2
#define ALT 1 << 3
static struct {
unsigned mod;
unsigned key;
func id;
} keys[] = {
{ CTRL, KEY(h), goback },
{ CTRL, KEY(j), goforward },
{ CTRL, KEY(r), refresh },
{ CTRL | SFT, KEY(R), refresh_force },
{ CTRL | SFT, KEY(H), back_to_home },
{ CTRL, KEY(equal), zoomin },
{ CTRL, KEY(minus), zoomout },
{ CTRL, KEY(0), zoom_reset },
{ CTRL, KEY(Page_Down), prev_tab },
{ CTRL, KEY(Page_Up), next_tab },
{ CTRL, KEY(t), next_tab },
{ CTRL, KEY(w), close_tab },
{ 0x0, KEY(F11), toggle_fullscreen },
{ CTRL, KEY(l), show_searchbar },
{ CTRL, KEY(k), hide_searchbar },
{ CTRL, KEY(f), show_finder },
{ CTRL, KEY(n), finder_next },
{ CTRL | SFT, KEY(N), finder_prev },
{ CTRL, KEY(p), prettify }
};
/* ^ For controls more akin to normal browsers */
/* Reference for the key shorthand:
* <https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gdk/gdkkeysyms.h> */
/* Old controls: {
{ CTRL, KEY(h), goback },
{ CTRL, KEY(l), goforward },
{ CTRL, KEY(r), refresh },
{ CTRL | SFT, KEY(R), refresh_force },
{ CTRL | SFT, KEY(H), back_to_home },
{ CTRL, KEY(equal), zoomin },
{ CTRL, KEY(minus), zoomout },
{ CTRL, KEY(0), zoom_reset },
{ ALT, KEY(h), prev_tab },
{ CTRL, KEY(k), hide_searchbar },
{ ALT, KEY(l), next_tab },
{ CTRL, KEY(w), close_tab },
{ 0x0, KEY(F11), toggle_fullscreen },
{ CTRL, KEY(e), show_searchbar },
{ CTRL, KEY(f), show_finder },
{ CTRL, KEY(n), finder_next },
{ CTRL | SFT, KEY(N), finder_prev },
{ CTRL, KEY(p), prettify }
};
*/

View File

@ -1,3 +1,5 @@
./plugins/*/*.sh
./build.sh && {
cp -f rose /usr/bin
mkdir -p /usr/share/themes/rose

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);
})();

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,71 @@
#include "str_replace_start.h"
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#define LIBRE_N 19
#define DEBUG false
/* Inspired by https://libredirect.github.io/, but in C. */
void str_init(char* str, int n){
for(int i=0; i<n; i++){
str[i] = ' ';
}
str[n] = '\0';
} // could also use <https://manpages.ubuntu.com/manpages/impish/man3/strinit.3pub.html>
int libre_redirect(const char* uri, char* output){
int l1 = strlen(uri);
int l2 = strlen(output);
if((l2 - l1) < LIBRE_N){
if(DEBUG) printf("Not enough memory\n");
return 1; // not enough memory.
}else{
char tmp_uri[l2++];
char tmp_output[l2++];
strcpy(tmp_uri, uri); // strcpy also copies the terminating '\0'
strcpy(tmp_output, output);
char* annoying_sites[] = {
"https://www.youtube.com",
"https://www.reddit.com",
"https://medium.com",
"https://translate.google.com",
"https://forum.effectivealtruism.org",
"https://www.bloomberg.com",
"https://twitter.com",
"https://wikipedia.org"
};
char* alternatives[] = {
"https://invidious.flokinet.to", /* "https://yt.artemislena.eu", */
"https://teddit.nunosempere.com",
"https://scribe.rip",
"https://simplytranslate.org/",
"https://ea.greaterwrong.com",
"https://archive.is/https://www.bloomberg.com",
"https://nitter.net",
"https://wikiless.org"
};
int n = sizeof(annoying_sites)/sizeof(annoying_sites[0]);
for(int i=0; i<n ; i++){
int replace_check = str_replace_start(tmp_uri, annoying_sites[i], alternatives[i], output);
if(replace_check == 2){
if(DEBUG) printf("tmp_uri: %s\n", tmp_uri);
if(DEBUG) printf("output: %s\n", output);
// strcpy(output, tmp_uri);
// break;
return 2;
}else if(replace_check == 1){
if(DEBUG) printf("replace_check failed\n");
return 1;
}
strcpy(tmp_uri, output);
str_init(output, l2);
}
strcpy(output, tmp_uri);
}
if(DEBUG) printf("No match found\n\n");
return 0;
}

View File

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

View File

@ -0,0 +1,60 @@
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#define DEBUG false
/*
See also:
* <https://web.archive.org/web/20160201212501/coding.debuntu.org/c-implementing-str_replace-replace-all-occurrences-substring>
* https://github.com/irl/la-cucina/blob/master/str_replace.c
*/
int str_replace_start(const char* string, const char* target, const char* replacement, char* output){
int l1 = strlen(string);
int l2 = strlen(target);
int l3 = strlen(replacement);
int l4 = strlen(output);
if(DEBUG) printf("%d,%d,%d,%d\n", l1, l2, l3, l4);
// if(DEBUG) printf("%s,%s,%s,%s\n", string, target, replacement, output);
if((l4 < (l1 - l2 + l3)) || l4 < l1 ){
// Not enough memory in output string.
if(DEBUG) printf("String not long enough.\n");
return 1;
}
/* else if(l1 < l2){
// Not even possible that there is a match.
if(DEBUG) printf("Target larger than string.\n");
strcpy(output, string);
} */
else {
if(DEBUG) printf("Looking for a match for %s in %s.\n", target, string);
int match = true;
for(int i=0; i<l2; i++){
if(string[i] != target[i]){
match = false;
break;
}
}
if(match){
if(DEBUG) printf("Found match.\n");
for(int i=0; i<l3; i++){
output[i] = replacement[i];
}
int counter = l3;
for(int i=l2; i<l1; i++){
output[counter] = string[i];
counter++;
}
output[counter] = '\0';
return 2; // success
}
else {
if(DEBUG) printf("Did not find match.\n");
strcpy(output, string);
}
}
return 0;
}

View File

@ -0,0 +1,6 @@
#ifndef STR_REPLACE_H_
#define STR_REPLACE_H_
int str_replace_start(const char* string, const char* target, const char* replacement, char* output);
#endif

View File

@ -0,0 +1,11 @@
#!/bin/bash
CC=gcc
FLAGS="-std=c99 -Wall -lm"
SRC=example.c
REQS="../str_replace_start.c ../libre_redirect.c"
echo -e "\n\n\n"
$CC $FLAGS $SRC $REQS -o example

Binary file not shown.

View File

@ -0,0 +1,20 @@
#include "../libre_redirect.h"
#include <string.h>
#include <stdio.h>
int main(){
char uri[] = "https://reddit.com/r/blah";
int l = LIBRE_N + strlen(uri) + 1;
char uri_filtered[l];
str_init(uri_filtered, l);
if(!libre_redirect(uri, uri_filtered)){
printf("Filtered uri: %s\n", uri_filtered);
}else{
printf("Uri: %s\n", uri);
// failure; do something with the original uri.
}
}

View File

@ -0,0 +1,3 @@
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.

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"

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
test "$1" = "--help" || test -z "$1" && {
echo -e "usage: rose-mklink <alias> <url>\n"
@ -12,6 +12,6 @@ test -z "$2" || {
exit 1
}
echo -e "#!/bin/sh\n\nrose $2" > /usr/bin/$1
echo -e "#!/bin/sh\n\nrose $2 > /dev/null &1>2 &" > /usr/bin/$1
chmod +x /usr/bin/$1
}

118
rose.c
View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 mini-rose
* Copyright (c) 2022 Nuño Sempere.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and any associated documentation
@ -7,13 +7,16 @@
* sublicense copies of this sotware for their own use.
* This code does not come with any warranty.
*
* Author: fenze <contact@fenze.dev>
*/
#include "config.h"
#include <string.h>
#include <stdbool.h>
#include <webkit2/webkit2.h>
#include "config.h"
#include "plugins/libre_redirect/libre_redirect.h"
#include "plugins/readability/readability.h"
#define CACHE \
"base-cache-directory", CACHE_DIR, \
"base-data-directory", CACHE_DIR, \
@ -72,21 +75,87 @@ void load_uri(WebKitWebView *view, const char *uri)
g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) {
webkit_web_view_load_uri(view, uri);
} else {
// webkit_web_view_load_uri(view, uri);
char tmp[strlen(uri) + strlen(SEARCH)];
snprintf(tmp, sizeof(tmp), SEARCH, uri);
webkit_web_view_load_uri(view, tmp);
}
}
void redirect_if_annoying(WebKitWebView *view, const char *uri){
int l = LIBRE_N + strlen(uri) + 1;
char uri_filtered[l];
str_init(uri_filtered, l);
if(DEBUG) printf("libre_redirect uri received : %s\n", uri);
int check = libre_redirect(uri, uri_filtered);
if(check == 2){
webkit_web_view_load_uri(view, uri_filtered);
}
if(DEBUG) printf("libre_redirect uri_filtered: %s\n", uri_filtered);
if(DEBUG) printf("libre_redirect check: %d\n", check);
}
void load_changed(WebKitWebView *self, WebKitLoadEvent load_event, GtkNotebook *notebook)
{
if (load_event == WEBKIT_LOAD_FINISHED) {
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self),
webkit_web_view_get_title(self));
gtk_widget_hide(GTK_WIDGET(bar));
switch (load_event) {
/* see <https://webkitgtk.org/reference/webkit2gtk/2.5.1/WebKitWebView.html> */
case WEBKIT_LOAD_STARTED:
redirect_if_annoying(self, webkit_web_view_get_uri(self));
if(DEBUG) printf("Load started with uri: %s\n", webkit_web_view_get_uri (self));
break;
case WEBKIT_LOAD_REDIRECTED:
redirect_if_annoying(self, webkit_web_view_get_uri(self));
if(DEBUG) printf("Load redirected to uri: %s\n", webkit_web_view_get_uri (self));
break;
case WEBKIT_LOAD_COMMITTED:
redirect_if_annoying(self, webkit_web_view_get_uri(self));
if(DEBUG) printf("Load committed with: %s\n", webkit_web_view_get_uri (self));
break;
case WEBKIT_LOAD_FINISHED:
{
const char* webpage_title = webkit_web_view_get_title(self);
const int max_length = 25;
char tab_title[max_length + 1];
if(webpage_title != NULL){
for(int i = 0; i<(max_length); i++){
tab_title[i] = webpage_title[i];
if(webpage_title[i] == '\0'){
break;
}
}
tab_title[max_length] = '\0';
}
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self),
webpage_title == NULL ? "" : tab_title );
// gtk_widget_hide(GTK_WIDGET(bar));
break;
}
}
}
void notebook_append(GtkNotebook *notebook, const char *uri);
/* notebook_append calls handle_create, but handle_create also calls notebook_append.
* Therefore we need to declare notebook_append, so that handle_create_new_tab knows its type.
*/
GtkWidget* handle_create_new_tab(WebKitWebView *self, WebKitNavigationAction *navigation_action, GtkNotebook *notebook){
WebKitURIRequest *uri_request = webkit_navigation_action_get_request(navigation_action);
const char *uri = webkit_uri_request_get_uri (uri_request);
printf("Creating new window: %s\n", uri);
notebook_append(notebook, uri);
gtk_notebook_set_show_tabs(notebook, true);
return NULL;
/* WebKitGTK documentation recommends returning the new webview.
* I imagine that this might allow e.g., to go back in a new tab
* or generally to keep track of history.
* However, this would require either modifying notebook_append
* or duplicating its contents, for unclear gain.
*/
}
void notebook_append(GtkNotebook *notebook, const char *uri)
{
GdkScreen *screen = gtk_window_get_screen(GTK_WINDOW(window));
@ -99,6 +168,7 @@ void notebook_append(GtkNotebook *notebook, const char *uri)
gtk_widget_set_visual(GTK_WIDGET(window), rgba_visual);
g_signal_connect(view, "load_changed", G_CALLBACK(load_changed), notebook);
g_signal_connect(view, "create", G_CALLBACK(handle_create_new_tab), notebook);
int n = gtk_notebook_append_page(notebook, GTK_WIDGET(view), NULL);
gtk_notebook_set_tab_reorderable(notebook, GTK_WIDGET(view), true);
@ -107,6 +177,7 @@ void notebook_append(GtkNotebook *notebook, const char *uri)
webkit_web_view_set_background_color(view, &rgba);
load_uri(view, (uri) ? uri : HOME);
gtk_notebook_set_current_page(notebook, n);
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(view), "-" );
}
WebKitWebView *notebook_get_webview(GtkNotebook *notebook)
@ -186,9 +257,12 @@ int handle_key(func id, GtkNotebook *notebook)
gtk_notebook_get_n_pages(notebook) - 1) {
notebook_append(notebook, NULL);
gtk_notebook_set_show_tabs(notebook, true);
webkit_web_view_set_zoom_level(notebook_get_webview(notebook), zoom);
} else {
gtk_notebook_next_page(notebook);
}
entry_mode = _SEARCH;
show_bar(notebook);
break;
case close_tab:
@ -218,6 +292,10 @@ int handle_key(func id, GtkNotebook *notebook)
entry_mode = _SEARCH;
show_bar(notebook);
break;
case hide_searchbar:
gtk_widget_hide(GTK_WIDGET(bar));
break;
case show_finder:
entry_mode = _FIND;
@ -233,6 +311,22 @@ int handle_key(func id, GtkNotebook *notebook)
webkit_find_controller_search_previous(
webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
break;
case prettify:{
if(DEBUG){
printf("prettify\n");
webkit_web_view_run_javascript(notebook_get_webview(notebook),
"alert('Tranquilizing!')",
NULL, NULL, NULL);
}
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;
@ -273,7 +367,7 @@ void window_init(GtkNotebook *notebook)
gtk_entry_buffer_new("", 0);
gtk_entry_set_alignment(search, 0.48);
gtk_widget_set_size_request(GTK_WIDGET(search), 300, -1);
gtk_widget_set_size_request(GTK_WIDGET(search), 1200, -1);
gtk_header_bar_set_custom_title(bar, GTK_WIDGET(search));
gtk_window_set_titlebar(window, GTK_WIDGET(bar));
@ -297,14 +391,18 @@ void setup(GtkNotebook *notebook, const char *uri)
search_buf = GTK_ENTRY_BUFFER(gtk_entry_buffer_new("", 0));
search = GTK_ENTRY(gtk_entry_new_with_buffer(search_buf));
// gtk_window_fullscreen(window);
gtk_window_set_default_size(window, WIDTH, HEIGHT);
// gtk_window_set_resizable (window, FALSE);
window_init(notebook);
notebook_init(notebook, uri);
g_object_set(gtk_settings_get_default(), GTK, NULL);
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(notebook));
gtk_widget_show_all(GTK_WIDGET(window));
gtk_widget_hide(GTK_WIDGET(bar));
webkit_web_view_set_zoom_level(notebook_get_webview(notebook), ZOOM);
}
int main(int argc, char **argv)

View File

@ -10,7 +10,10 @@
margin: 0px;
outline-color: @Lavender;
color: @Text;
border-bottom-color: @Base;
border-color: white;
font-size: 16px;
/*@Base; */
/* border-bottom-color: @Base; */
}
window, notebook, headerbar {
@ -20,11 +23,21 @@ window, notebook, headerbar {
tabs {
background-color: @Base;
padding: 3px;
outline-color: white;
border-color: @Base;
}
tab {
background-color: @Base;
margin: 2px 5px 2px 0px;
padding: 5px;
border-style: solid;
/*border-color: white;
border-bottom-color: white;
outline-color: white;
margin: 5px;
padding-left: 10px;
padding-right: 10px; */
}
entry {
@ -33,5 +46,7 @@ entry {
}
entry:focus {
box-shadow: none;
background-color: @Surface0;
padding-left: 10px;
}

View File

@ -0,0 +1,23 @@
# Dependencies
sudo apt install libwebkit2gtk-4.0-dev
sudo apt install clang
# sudo apt instal sudo apt install gstreamer1.0-plugins-good gstreamer1.0-libav
# Adblock
git clone https://github.com/jun7/wyebadblock
cd wyebadblock
make
sudo make install
cd ..
# Rose config
user=$(whoami)
mkdir -p /home/$user/.cache/rose
cp ../../config.def.h ../../config.h # you should also probably customize this yourself.
sed "s/fenze/$user/g" ../../config.h
sudo bash ../../install.sh
# Ubuntu desktop icon
chmod +x rose.desktop
sudo cp rose.desktop /usr/share/applications

View File

@ -0,0 +1,13 @@
For some reason, the Ubuntu environment assigns a program to the rose desktop tab if it is called from within /usr/bin/rose, even if from the Whatsapp desktop file.
The solution is to make a syslink from rose to whatsapp:
```
$ ln -s /usr/bin/rose /usr/bin/whatsapp
```
and then call whatsapp from:
```
/usr/bin/whatsapp https://web.whatsapp.com/
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 KiB

View File

@ -0,0 +1 @@
<https://www.onlygfx.com/red-rose-png-image-transparent/>

View File

@ -0,0 +1,9 @@
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec= /usr/bin/rose %u
Name=Rose
Comment=Minimalistic browser
Icon=/home/loki/Documents/core/software/fresh/C/rose-browser/rose-bud-personal/user-scripts/ubuntu-20.04/rose-images/rose-desktop-icon.png

View File

@ -0,0 +1,8 @@
# Requires:
# sudo cp rose.desktop /usr/share/applications
xdg-mime default rose.desktop x-scheme-handler/https
xdg-mime default rose.desktop x-scheme-handler/http
# This is useful e.g., for setting how to open
# links in vim when pressing gx.

View File

@ -0,0 +1,10 @@
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec= /usr/bin/whatsapp https://web.whatsapp.com
Name=Whatsapp
Comment=Whatsapp messaging service.
Icon=/home/loki/Pictures/fresh/misc/whatsapp_icon.svg

View File

@ -0,0 +1,9 @@
In case you arrive at a segmentation fault when working on rose, you can use valgrind.
To do this, you can compile rose with the `DEBUG` value in `build.sh` set to `-g`
and then:
```
valgrind --track-origins=yes ./rose
```