tweak: try to integrate plugin.
This commit is contained in:
parent
618262d2a2
commit
d25a6e7e79
3
build.sh
3
build.sh
|
@ -1,5 +1,6 @@
|
||||||
CC=clang
|
CC=clang
|
||||||
SRC=rose.c
|
SRC=rose.c
|
||||||
|
REQS=./plugins/libre_redirect/*.c
|
||||||
DEPS=('webkit2gtk-4.0')
|
DEPS=('webkit2gtk-4.0')
|
||||||
|
|
||||||
INCS=`pkg-config --cflags ${DEPS[@]}`
|
INCS=`pkg-config --cflags ${DEPS[@]}`
|
||||||
|
@ -8,4 +9,4 @@ 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'
|
||||||
|
|
||||||
$CC $INCS $LIBS $SRC $WYEBAB -o rose
|
$CC $INCS $LIBS $SRC $REQS $WYEBAB -o rose
|
||||||
|
|
|
@ -4,7 +4,7 @@ CC=gcc
|
||||||
FLAGS="-std=c99 -Wall -lm"
|
FLAGS="-std=c99 -Wall -lm"
|
||||||
|
|
||||||
SRC=example.c
|
SRC=example.c
|
||||||
REQS="str_replace_start.c libre_redirect.c"
|
REQS="../str_replace_start.c ../libre_redirect.c"
|
||||||
|
|
||||||
echo -e "\n\n\n"
|
echo -e "\n\n\n"
|
||||||
$CC $FLAGS $SRC $REQS -o example
|
$CC $FLAGS $SRC $REQS -o example
|
|
@ -1,4 +1,4 @@
|
||||||
#include "libre_redirect.h"
|
#include "../libre_redirect.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#include "str_replace_start.h"
|
#include "str_replace_start.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#define LIBRE_N 12
|
#define LIBRE_N 12
|
||||||
|
#define DEBUG true
|
||||||
|
|
||||||
/* Inspired by https://libredirect.github.io/, but in C. */
|
/* Inspired by https://libredirect.github.io/, but in C. */
|
||||||
|
|
||||||
|
@ -16,30 +19,43 @@ int libre_redirect(const char* uri, char* output){
|
||||||
int l2 = strlen(output);
|
int l2 = strlen(output);
|
||||||
|
|
||||||
if((l2 - l1) < LIBRE_N){
|
if((l2 - l1) < LIBRE_N){
|
||||||
|
if(DEBUG) printf("Not enough memory\n");
|
||||||
return 1; // not enough memory.
|
return 1; // not enough memory.
|
||||||
}else{
|
}else{
|
||||||
char tmp_uri[l2++];
|
char tmp_uri[l2++];
|
||||||
|
char tmp_output[l2++];
|
||||||
strcpy(tmp_uri, uri); // strcpy also copies the terminating '\0'
|
strcpy(tmp_uri, uri); // strcpy also copies the terminating '\0'
|
||||||
|
strcpy(tmp_output, output);
|
||||||
|
|
||||||
char* sites[] = {
|
char* sites[] = {
|
||||||
"https://youtube.com",
|
"https://youtube.com",
|
||||||
"https://reddit.com",
|
"https://reddit.com",
|
||||||
|
"https://www.reddit.com",
|
||||||
"https://medium.com",
|
"https://medium.com",
|
||||||
"https://translate.google.com"
|
"https://translate.google.com"
|
||||||
};
|
};
|
||||||
char* alternatives[] = {
|
char* alternatives[] = {
|
||||||
"https://yt.artemislena.eu",
|
"https://yt.artemislena.eu",
|
||||||
"https://teddit.nunosempere.com",
|
"https://teddit.nunosempere.com",
|
||||||
|
"https://teddit.nunosempere.com",
|
||||||
"https://scribe.rip",
|
"https://scribe.rip",
|
||||||
"https://simplytranslate.org/"
|
"https://simplytranslate.org/"
|
||||||
};
|
};
|
||||||
|
|
||||||
for(int i=1; i<4; i++){
|
for(int i=1; i<4; 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){
|
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 0;
|
||||||
|
}else if(replace_check == 1){
|
||||||
|
if(DEBUG) printf("replace_check failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
strcpy(tmp_uri, output);
|
strcpy(tmp_uri, output);
|
||||||
|
str_init(output, l2);
|
||||||
}
|
}
|
||||||
strcpy(output, tmp_uri);
|
strcpy(output, tmp_uri);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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:
|
||||||
|
@ -28,7 +28,7 @@ int str_replace_start(const char* string, const char* target, const char* replac
|
||||||
strcpy(output, string);
|
strcpy(output, string);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(DEBUG) printf("Looking for a match.\n");
|
if(DEBUG) printf("Looking for a match for %s in %s.\n", target, string);
|
||||||
int match = true;
|
int match = true;
|
||||||
for(int i=0; i<l2; i++){
|
for(int i=0; i<l2; i++){
|
||||||
if(string[i] != target[i]){
|
if(string[i] != target[i]){
|
||||||
|
@ -47,6 +47,7 @@ int str_replace_start(const char* string, const char* target, const char* replac
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
output[counter] = '\0';
|
output[counter] = '\0';
|
||||||
|
return 2; // success
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(DEBUG) printf("Did not find match.\n");
|
if(DEBUG) printf("Did not find match.\n");
|
||||||
|
|
42
rose.c
42
rose.c
|
@ -11,8 +11,9 @@
|
||||||
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "plugins/libre_redirect/libre_redirect.h"
|
||||||
#include <webkit2/webkit2.h>
|
#include <webkit2/webkit2.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define CACHE \
|
#define CACHE \
|
||||||
"base-cache-directory", CACHE_DIR, \
|
"base-cache-directory", CACHE_DIR, \
|
||||||
|
@ -70,7 +71,18 @@ void load_uri(WebKitWebView *view, const char *uri)
|
||||||
{
|
{
|
||||||
if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") ||
|
if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") ||
|
||||||
g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) {
|
g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) {
|
||||||
webkit_web_view_load_uri(view, uri);
|
int l = LIBRE_N + strlen(uri) + 1;
|
||||||
|
char uri_filtered[l];
|
||||||
|
str_init(uri_filtered, l);
|
||||||
|
printf("Uri: %s\n", uri);
|
||||||
|
int check = libre_redirect(uri, uri_filtered);
|
||||||
|
if(!check){
|
||||||
|
webkit_web_view_load_uri(view, uri_filtered);
|
||||||
|
}else{
|
||||||
|
webkit_web_view_load_uri(view, uri);
|
||||||
|
}
|
||||||
|
printf("uri_filtered: %s\n", uri_filtered);
|
||||||
|
printf("check: %d\n", check);
|
||||||
} else {
|
} else {
|
||||||
char tmp[strlen(uri) + strlen(SEARCH)];
|
char tmp[strlen(uri) + strlen(SEARCH)];
|
||||||
snprintf(tmp, sizeof(tmp), SEARCH, uri);
|
snprintf(tmp, sizeof(tmp), SEARCH, uri);
|
||||||
|
@ -80,11 +92,29 @@ void load_uri(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)
|
||||||
{
|
{
|
||||||
if (load_event == WEBKIT_LOAD_FINISHED) {
|
switch (load_event) {
|
||||||
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self),
|
case WEBKIT_LOAD_STARTED:
|
||||||
|
/* New load, we have now a provisional URI */
|
||||||
|
provisional_uri = webkit_web_view_get_uri (web_view);
|
||||||
|
/* Here we could start a spinner or update the
|
||||||
|
* location bar with the provisional URI */
|
||||||
|
break;
|
||||||
|
case WEBKIT_LOAD_REDIRECTED:
|
||||||
|
redirected_uri = webkit_web_view_get_uri (web_view);
|
||||||
|
break;
|
||||||
|
case WEBKIT_LOAD_COMMITTED:
|
||||||
|
/* The load is being performed. Current URI is
|
||||||
|
* the final one and it won't change unless a new
|
||||||
|
* load is requested or a navigation within the
|
||||||
|
* same page is performed */
|
||||||
|
uri = webkit_web_view_get_uri (web_view);
|
||||||
|
break;
|
||||||
|
case WEBKIT_LOAD_FINISHED:
|
||||||
|
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self),
|
||||||
webkit_web_view_get_title(self));
|
webkit_web_view_get_title(self));
|
||||||
gtk_widget_hide(GTK_WIDGET(bar));
|
gtk_widget_hide(GTK_WIDGET(bar));
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void notebook_append(GtkNotebook *notebook, const char *uri)
|
void notebook_append(GtkNotebook *notebook, const char *uri)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user