From 353d0ffad7c1810d2c5a87d73f6649bcbc55aad4 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 5 Feb 2023 03:21:30 +0100 Subject: feat: add plugin to customize css for individual websites... and how to enable it. Also tweak README.mds --- plugins/style/README.md | 34 ++++++++++++++++++++++++++++++++++ plugins/style/recompute_STYLE_N.sh | 8 ++++++++ plugins/style/style.c | 29 +++++++++++++++++++++++++++++ plugins/style/style.h | 8 ++++++++ plugins/style/style.js | 26 ++++++++++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 plugins/style/README.md create mode 100755 plugins/style/recompute_STYLE_N.sh create mode 100644 plugins/style/style.c create mode 100644 plugins/style/style.h create mode 100644 plugins/style/style.js (limited to 'plugins/style') diff --git a/plugins/style/README.md b/plugins/style/README.md new file mode 100644 index 0000000..0d11c54 --- /dev/null +++ b/plugins/style/README.md @@ -0,0 +1,34 @@ +## Customize css style for individual websites. + +- Replicates: . +- The template is similar to the readability folder. + +## 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. diff --git a/plugins/style/recompute_STYLE_N.sh b/plugins/style/recompute_STYLE_N.sh new file mode 100755 index 0000000..906aad8 --- /dev/null +++ b/plugins/style/recompute_STYLE_N.sh @@ -0,0 +1,8 @@ +#!/bin/bash +function sedr(){ + find ./ -type f -exec sed -i -e "$1" {} \; +} ## e.g., sedr "s/target/replacement/g" + +STYLE_N=$(wc -c style.js | cut -d " " -f 1) +sedr "s/^#define STYLE_N .*/#define STYLE_N $STYLE_N + 1/g" + diff --git a/plugins/style/style.c b/plugins/style/style.c new file mode 100644 index 0000000..dc2da8a --- /dev/null +++ b/plugins/style/style.c @@ -0,0 +1,29 @@ +#include +#include +#include +#define STYLE_N 794 + 1 + +void read_style_js(char* string){ + FILE *fp=fopen("/home/loki/Documents/core/software/fresh/C/rose-browser/rose-bud-personal/plugins/style/style.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(STYLE_N+1); + read_readability_js(readability_js); + printf("%s", readability_js); + free(readability_js); +} +*/ diff --git a/plugins/style/style.h b/plugins/style/style.h new file mode 100644 index 0000000..20a684b --- /dev/null +++ b/plugins/style/style.h @@ -0,0 +1,8 @@ +#ifndef STYLE +#define STYLE + +#define STYLE_N 794 + 1 + +void read_style_js(char* string); + +#endif diff --git a/plugins/style/style.js b/plugins/style/style.js new file mode 100644 index 0000000..01524d0 --- /dev/null +++ b/plugins/style/style.js @@ -0,0 +1,26 @@ +// Replicates the Stylus app: + +if (document.domain == "forum.effectivealtruism.org"){ + var styles = ` + .Layout-main { + margin-left: 100px; + } + .SingleColumnSection-root { + width: 1000px !important; + max-width: 1400px !important; + padding-left: 100px !important; + } + .NavigationStandalone-sidebar { + display: none; + } + .intercom-lightweight-app{ + display: none; + } + ` + var styleSheet = document.createElement('style') + styleSheet.innerText = styles + document.head.appendChild(styleSheet) + console.log('Style changed') +} + +document.body.style.visibility = "visible" -- cgit v1.3.1 From b48c504871c4732895b00ae6c2a87c97a63ad3d8 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 5 Feb 2023 03:57:29 +0100 Subject: 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 --- README.md | 3 -- config.def.h | 6 ++-- plugins/libre_redirect/README.md | 54 +------------------------------ plugins/readability/README.md | 68 +--------------------------------------- plugins/style/README.md | 31 +----------------- rose.c | 61 +++++++++++++++++++++-------------- 6 files changed, 45 insertions(+), 178 deletions(-) (limited to 'plugins/style') diff --git a/README.md b/README.md index 4359611..ca08322 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,6 @@ - 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). - ### 📜 License Rose is released under own license, which grants the following permissions: - Commercial use diff --git a/config.def.h b/config.def.h index b16bcb8..4ba77e6 100644 --- a/config.def.h +++ b/config.def.h @@ -82,7 +82,7 @@ static struct { { CTRL, KEY(n), finder_next }, { CTRL | SFT, KEY(N), finder_prev }, { CTRL, KEY(t), newtab }, - // { CTRL, KEY(p), prettify }, + { CTRL, KEY(p), prettify }, { 0x0, KEY(Escape), hidebar } }; /* For controls more akin to normal browsers, use: @@ -102,7 +102,9 @@ static struct { { CTRL, KEY(l), 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 }, + }; */ /* Reference for the key shorthand: diff --git a/plugins/libre_redirect/README.md b/plugins/libre_redirect/README.md index 7b32370..f3f58c9 100644 --- a/plugins/libre_redirect/README.md +++ b/plugins/libre_redirect/README.md @@ -1,55 +1,3 @@ ## About -This code automatically redirects webpage to their open-source frontends - -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; - - -``` +This code automatically redirects webpage to their open-source frontends. It is based on \ No newline at end of file diff --git a/plugins/readability/README.md b/plugins/readability/README.md index d6c0fe2..2a19a8e 100644 --- a/plugins/readability/README.md +++ b/plugins/readability/README.md @@ -1,68 +1,2 @@ -## Readability +This code reimplements firefox readability mode. Code taken from -Taken from - - -## 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 }, - - -``` diff --git a/plugins/style/README.md b/plugins/style/README.md index 0d11c54..e0aad62 100644 --- a/plugins/style/README.md +++ b/plugins/style/README.md @@ -2,33 +2,4 @@ - Replicates: . - The template is similar to the readability folder. - -## 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. +- You will also want to customize the `style.c` file. diff --git a/rose.c b/rose.c index fd9f67f..989c2de 100644 --- a/rose.c +++ b/rose.c @@ -12,10 +12,22 @@ #include #include "config.h" + // #include "plugins/libre_redirect/libre_redirect.h" // #include "plugins/readability/readability.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 \ "base-cache-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){ int l = LIBRE_N + strlen(uri) + 1; 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) { switch (load_event) { /* see */ 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; 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; case WEBKIT_LOAD_COMMITTED: - // redirect_if_annoying(self, webkit_web_view_get_uri(self)); - // 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); - */ + if(LIBRE_REDIRECT_ENABLED){ + redirect_if_annoying(self, webkit_web_view_get_uri(self)); + } + if(CUSTOM_STYLE_ENABLED){ + 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); + } break; case WEBKIT_LOAD_FINISHED: { @@ -320,20 +335,20 @@ int handle_key(func id, GtkNotebook *notebook) entry_mode = _HIDDEN; show_bar(notebook); break; - /* + 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; } - */ } return 1; -- cgit v1.3.1