feat: use flags rather than uncommenting code
- Significantly simpler - Easier for me to keep up with upstream - Alternatives: - Comments as before - git patches, as in the suckless community: eventually leads to confusion about conflicting patches. - some other option
This commit is contained in:
parent
cbaa97a766
commit
b48c504871
|
@ -9,9 +9,6 @@
|
||||||
- hackable without any knowledge
|
- hackable without any knowledge
|
||||||
- builtin rose-mklink script for in-shell static links
|
- builtin rose-mklink script for in-shell static links
|
||||||
|
|
||||||
### 👐 Contribute
|
|
||||||
See [contributing.md](https://github.com/mini-rose/rose/.github/contributing.md).
|
|
||||||
|
|
||||||
### 📜 License
|
### 📜 License
|
||||||
Rose is released under own license, which grants the following permissions:
|
Rose is released under own license, which grants the following permissions:
|
||||||
- Commercial use
|
- Commercial use
|
||||||
|
|
|
@ -82,7 +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 },
|
{ 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:
|
||||||
|
@ -102,7 +102,9 @@ 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 },
|
||||||
|
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
/* Reference for the key shorthand:
|
/* Reference for the key shorthand:
|
||||||
|
|
|
@ -1,55 +1,3 @@
|
||||||
## About
|
## About
|
||||||
|
|
||||||
This code automatically redirects webpage to their open-source frontends
|
This code automatically redirects webpage to their open-source frontends. It is based on <https://libredirect.codeberg.page/>
|
||||||
|
|
||||||
To enable it:
|
|
||||||
|
|
||||||
## In build.sh
|
|
||||||
|
|
||||||
In `build.sh`, uncomment this line:
|
|
||||||
|
|
||||||
```
|
|
||||||
REQS= #./plugins/*/*.c
|
|
||||||
```
|
|
||||||
|
|
||||||
or alternatively, write the full paths of `libre_redirect.c` and `str_replace_start.c`
|
|
||||||
|
|
||||||
|
|
||||||
### In rose.c
|
|
||||||
|
|
||||||
Uncomment these lines:
|
|
||||||
|
|
||||||
```
|
|
||||||
// #include "plugins/libre_redirect/libre_redirect.h"
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
/*
|
|
||||||
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);
|
|
||||||
|
|
||||||
int check = libre_redirect(uri, uri_filtered);
|
|
||||||
|
|
||||||
if (check == 2){
|
|
||||||
webkit_web_view_load_uri(view, uri_filtered);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
case WEBKIT_LOAD_STARTED:
|
|
||||||
// redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
|
||||||
break;
|
|
||||||
case WEBKIT_LOAD_REDIRECTED:
|
|
||||||
// redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
|
||||||
break;
|
|
||||||
case WEBKIT_LOAD_COMMITTED:
|
|
||||||
// redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
|
@ -1,68 +1,2 @@
|
||||||
## Readability
|
This code reimplements firefox readability mode. Code taken from <https://raw.githubusercontent.com/ushnisha/readability-reader-webextensions/master/content_scripts/tranquilize.js>
|
||||||
|
|
||||||
Taken from <https://raw.githubusercontent.com/ushnisha/readability-reader-webextensions/master/content_scripts/tranquilize.js>
|
|
||||||
|
|
||||||
|
|
||||||
## To enable it
|
|
||||||
|
|
||||||
In `build.sh`, uncomment this line:
|
|
||||||
|
|
||||||
```
|
|
||||||
REQS= #./plugins/*/*.c
|
|
||||||
```
|
|
||||||
|
|
||||||
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 },
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
|
@ -2,33 +2,4 @@
|
||||||
|
|
||||||
- Replicates: <https://addons.mozilla.org/en-GB/firefox/addon/styl-us/>.
|
- Replicates: <https://addons.mozilla.org/en-GB/firefox/addon/styl-us/>.
|
||||||
- The template is similar to the readability folder.
|
- The template is similar to the readability folder.
|
||||||
|
- You will also want to customize the `style.c` file.
|
||||||
## To enable it
|
|
||||||
|
|
||||||
In `build.sh`, uncomment this line:
|
|
||||||
|
|
||||||
```
|
|
||||||
REQS= #./plugins/*/*.c
|
|
||||||
```
|
|
||||||
|
|
||||||
In `rose.c`, uncomment:
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
// #include "plugins/style/style.h"
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
// Add custom style
|
|
||||||
/*
|
|
||||||
char* style_js = malloc(STYLE_N+1);
|
|
||||||
read_style_js(style_js);
|
|
||||||
webkit_web_view_run_javascript(notebook_get_webview(notebook),
|
|
||||||
style_js,
|
|
||||||
NULL, NULL, NULL);
|
|
||||||
free(style_js);
|
|
||||||
*/
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
You will also want to customize the `style.c` file.
|
|
||||||
|
|
61
rose.c
61
rose.c
|
@ -12,10 +12,22 @@
|
||||||
#include <webkit2/webkit2.h>
|
#include <webkit2/webkit2.h>
|
||||||
|
|
||||||
#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"
|
// #include "plugins/readability/readability.h"
|
||||||
// #include "plugins/style/style.h"
|
// #include "plugins/style/style.h"
|
||||||
|
|
||||||
|
int LIBRE_REDIRECT_ENABLED = false;
|
||||||
|
int READABILITY_ENABLED = false;
|
||||||
|
int CUSTOM_STYLE_ENABLED = false;
|
||||||
|
|
||||||
|
// to enable plugins,
|
||||||
|
// 1. uncomment their #include statement
|
||||||
|
// 2. set their variable to true;
|
||||||
|
// 3. in build.sh, uncomment:
|
||||||
|
// REQS= #./plugins/*/*.c
|
||||||
|
|
||||||
|
|
||||||
#define CACHE \
|
#define CACHE \
|
||||||
"base-cache-directory", CACHE_DIR, \
|
"base-cache-directory", CACHE_DIR, \
|
||||||
"base-data-directory", CACHE_DIR, \
|
"base-data-directory", CACHE_DIR, \
|
||||||
|
@ -80,7 +92,6 @@ void load_uri(WebKitWebView *view, const char *uri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void redirect_if_annoying(WebKitWebView *view, const char *uri){
|
void redirect_if_annoying(WebKitWebView *view, const char *uri){
|
||||||
int l = LIBRE_N + strlen(uri) + 1;
|
int l = LIBRE_N + strlen(uri) + 1;
|
||||||
char uri_filtered[l];
|
char uri_filtered[l];
|
||||||
|
@ -93,29 +104,33 @@ void redirect_if_annoying(WebKitWebView *view, const char *uri){
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
void load_changed(WebKitWebView *self, WebKitLoadEvent load_event, GtkNotebook *notebook)
|
void load_changed(WebKitWebView *self, WebKitLoadEvent load_event, GtkNotebook *notebook)
|
||||||
{
|
{
|
||||||
switch (load_event) {
|
switch (load_event) {
|
||||||
/* see <https://webkitgtk.org/reference/webkit2gtk/2.5.1/WebKitWebView.html> */
|
/* see <https://webkitgtk.org/reference/webkit2gtk/2.5.1/WebKitWebView.html> */
|
||||||
case WEBKIT_LOAD_STARTED:
|
case WEBKIT_LOAD_STARTED:
|
||||||
// redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
if(LIBRE_REDIRECT_ENABLED){
|
||||||
|
redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case WEBKIT_LOAD_REDIRECTED:
|
case WEBKIT_LOAD_REDIRECTED:
|
||||||
// redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
if(LIBRE_REDIRECT_ENABLED){
|
||||||
|
redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case WEBKIT_LOAD_COMMITTED:
|
case WEBKIT_LOAD_COMMITTED:
|
||||||
// redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
if(LIBRE_REDIRECT_ENABLED){
|
||||||
// Add custom style
|
redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
||||||
/*
|
}
|
||||||
char* style_js = malloc(STYLE_N+1);
|
if(CUSTOM_STYLE_ENABLED){
|
||||||
read_style_js(style_js);
|
char* style_js = malloc(STYLE_N+1);
|
||||||
webkit_web_view_run_javascript(notebook_get_webview(notebook),
|
read_style_js(style_js);
|
||||||
style_js,
|
webkit_web_view_run_javascript(notebook_get_webview(notebook),
|
||||||
NULL, NULL, NULL);
|
style_js,
|
||||||
free(style_js);
|
NULL, NULL, NULL);
|
||||||
*/
|
free(style_js);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case WEBKIT_LOAD_FINISHED:
|
case WEBKIT_LOAD_FINISHED:
|
||||||
{
|
{
|
||||||
|
@ -320,20 +335,20 @@ int handle_key(func id, GtkNotebook *notebook)
|
||||||
entry_mode = _HIDDEN;
|
entry_mode = _HIDDEN;
|
||||||
show_bar(notebook);
|
show_bar(notebook);
|
||||||
break;
|
break;
|
||||||
/*
|
|
||||||
case prettify:
|
case prettify:
|
||||||
{
|
{
|
||||||
|
if(READABILITY_ENABLED){
|
||||||
|
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);
|
||||||
|
|
||||||
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;
|
break;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user