debug shortcuts plugin
This commit is contained in:
parent
c46e2ba398
commit
a8be16b1ee
2
makefile
2
makefile
|
@ -24,7 +24,7 @@ LIBS=`pkg-config --libs ${DEPS}`
|
|||
ADBLOCK=#'-L/usr/lib/wyebrowser/adblock.so'
|
||||
|
||||
## Plugins
|
||||
LIBRE_REDIRECT=./plugins/libre_redirect/libre_redirect.c ./plugins/libre_redirect/str_replace_start.c
|
||||
LIBRE_REDIRECT=./plugins/libre_redirect/libre_redirect.c ./plugins/libre_redirect/str_replace_start.c ./plugins/libre_redirect/str_init.c
|
||||
CUSTOM_STYLES=./plugins/style/style.c
|
||||
READABILITY=./plugins/readability/readability.c
|
||||
SHORTCUTS=./plugins/shortcuts/shortcuts.c
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "str_init.h"
|
||||
#include "str_replace_start.h"
|
||||
|
||||
#define LIBRE_N 19
|
||||
|
@ -11,13 +12,6 @@
|
|||
|
||||
/* 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);
|
||||
|
|
7
plugins/libre_redirect/str_init.c
Normal file
7
plugins/libre_redirect/str_init.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
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>
|
||||
|
1
plugins/libre_redirect/str_init.h
Normal file
1
plugins/libre_redirect/str_init.h
Normal file
|
@ -0,0 +1 @@
|
|||
void str_init(char* str, int n);
|
|
@ -1,3 +1,7 @@
|
|||
## About
|
||||
|
||||
This code automatically redirects shortcuts to their longer expansions. Similar to DuckDuckGo's bangs (<https://duckduckgo.com/bangs>)
|
||||
|
||||
Note that Whoogle (the default search engine) also has its own bangs!
|
||||
- See: https://github.com/benbusby/whoogle-search/blob/main/app/utils/bangs.py
|
||||
- and https://duckduckgo.com/bang.v255.js
|
||||
|
|
|
@ -3,23 +3,18 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "../libre_redirect/str_replace_start.h"
|
||||
#include "../libre_redirect/str_init.h"
|
||||
|
||||
#define SHORTCUT_N 20
|
||||
#define SHORTCUT_N 41
|
||||
|
||||
/* Uncomment for debug */
|
||||
/* #define DEBUG */
|
||||
|
||||
/* Inspired by https://duckduckgo.com/bangs */
|
||||
|
||||
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 shortcut_expand(const char* uri, char* output)
|
||||
{
|
||||
printf("SHORTCUT EXPAND!");
|
||||
int l1 = strlen(uri);
|
||||
int l2 = strlen(output);
|
||||
int len;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#define SHORTCUT_N 20
|
||||
#define SHORTCUT_N 41
|
||||
|
||||
int shortcut_expand(const char* uri, char* output);
|
||||
void str_init(char* str, int n);
|
||||
|
|
15
rose.c
15
rose.c
|
@ -92,20 +92,6 @@ WebKitWebView* notebook_get_webview(GtkNotebook* notebook)
|
|||
notebook, gtk_notebook_get_current_page(notebook)));
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void load_uri(WebKitWebView* view, const char* uri)
|
||||
{
|
||||
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:")) {
|
||||
|
@ -116,7 +102,6 @@ void load_uri(WebKitWebView* view, const char* uri)
|
|||
char uri_expanded[l];
|
||||
str_init(uri_expanded, l);
|
||||
int check = shortcut_expand(uri, uri_expanded);
|
||||
|
||||
if (check == 2) {
|
||||
webkit_web_view_load_uri(view, uri_expanded);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user