---- - config.def.h | 8 +++++++- - surf.1 | 9 +-------- - surf.c | 59 +++++++++++++++++++++++++++++++++++++++++------------------ - 3 files changed, 49 insertions(+), 27 deletions(-) - -diff --git a/config.def.h b/config.def.h -index 80a0feb..ebab5bd 100644 ---- a/config.def.h -+++ b/config.def.h -_AT_@ -2,7 +2,6 @@ - static char *useragent = "Mozilla/5.0 (X11; U; Unix; en-US) " - "AppleWebKit/537.15 (KHTML, like Gecko) Chrome/24.0.1295.0 " - "Safari/537.15 Surf/"VERSION; --static char *stylefile = "~/.surf/style.css"; - static char *scriptfile = "~/.surf/script.js"; - - static Bool kioskmode = FALSE; /* Ignore shortcuts */ -_AT_@ -51,6 +50,13 @@ static Bool allowgeolocation = TRUE; - - #define MODKEY GDK_CONTROL_MASK - -+#define STYLEDIR "~/.surf/styles/" -+static SiteSpecificStyle styles[] = { -+ { "^https?://[a-z]+\.wikipedia\.org", STYLEDIR "wiki.css" }, -+ { "^https?://startpage\.com", STYLEDIR "startpage.css" }, -+ { ".*", STYLEDIR "default.css" }, -+}; -+ - /* hotkeys */ - /* - * If you use anything else but MODKEY and GDK_SHIFT_MASK, don't forget to -diff --git a/surf.1 b/surf.1 -index f838773..9e13932 100644 ---- a/surf.1 -+++ b/surf.1 -_AT_@ -8,7 +8,6 @@ surf \- simple webkit-based browser - .RB [-c\ cookiefile] - .RB [-e\ xid] - .RB [-r\ scriptfile] --.RB [-t\ stylefile] - .RB [-u\ useragent] - .RB [-z\ zoomlevel] - .RB "URI" -_AT_@ -90,10 +89,6 @@ Disable Javascript - .B \-S - Enable Javascript - .TP --.B \-t stylefile --Specify the user --.I stylefile. --.TP - .B \-u useragent - Specify the - .I useragent -_AT_@ -194,9 +189,7 @@ Toggle caret browsing. This will reload the page. - Toggle auto-loading of images. This will reload the page. - .TP - .B Ctrl\-Shift\-m --Toggle if the --.I stylefile --file should be loaded. This will reload the page. -+Toggle if custom styles should be loaded. This will reload the page. - .TP - .B Ctrl\-Shift\-o - Open the Web Inspector (Developer Tools) window for the current page. -diff --git a/surf.c b/surf.c -index 6beda59..5994486 100644 ---- a/surf.c -+++ b/surf.c -_AT_@ -23,6 +23,7 @@ - #include <sys/file.h> - #include <libgen.h> - #include <stdarg.h> -+#include <regex.h> - - #include "arg.h" - -_AT_@ -71,6 +72,12 @@ typedef struct { - - G_DEFINE_TYPE(CookieJar, cookiejar, SOUP_TYPE_COOKIE_JAR_TEXT) - -+typedef struct { -+ char *regex; -+ char *style; -+ regex_t re; -+} SiteSpecificStyle; -+ - static Display *dpy; - static Atom atoms[AtomLast]; - static Client *clients = NULL; -_AT_@ -127,6 +134,8 @@ static const char *getatom(Client *c, int a); - static void gettogglestat(Client *c); - static void getpagestat(Client *c); - static char *geturi(Client *c); -+static gchar *getstyle(const char *uri); -+ - static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c); - - static void inspector(Client *c, const Arg *arg); -_AT_@ -264,7 +273,6 @@ cleanup(void) { - destroyclient(clients); - g_free(cookiefile); - g_free(scriptfile); -- g_free(stylefile); - } - - static void -_AT_@ -533,6 +541,15 @@ geturi(Client *c) { - return uri; - } - -+static gchar * -+getstyle(const char *uri) { -+ int i; -+ for(i = 0; i < LENGTH(styles); i++) -+ if(styles[i].regex && !regexec(&(styles[i].re), uri, 0, NULL, 0)) -+ return g_strconcat("file://", styles[i].style, NULL); -+ return g_strdup(""); -+} -+ - static gboolean - initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) { - Arg arg; -_AT_@ -629,8 +646,10 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) { - WebKitWebFrame *frame; - WebKitWebDataSource *src; - WebKitNetworkRequest *request; -+ WebKitWebSettings *set = webkit_web_view_get_settings(c->view); - SoupMessage *msg; - char *uri; -+ char *path; - - switch(webkit_web_view_get_load_status (c->view)) { - case WEBKIT_LOAD_COMMITTED: -_AT_@ -644,6 +663,9 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) { - & SOUP_MESSAGE_CERTIFICATE_TRUSTED); - } - setatom(c, AtomUri, uri); -+ g_object_get(G_OBJECT(set), "user-stylesheet-uri", &path, NULL); -+ if (path && path[0]) -+ g_object_set(G_OBJECT(set), "user-stylesheet-uri", getstyle(uri), NULL); - break; - case WEBKIT_LOAD_FINISHED: - c->progress = 100; -_AT_@ -702,7 +724,7 @@ newclient(void) { - GdkGeometry hints = { 1, 1 }; - GdkScreen *screen; - gdouble dpi; -- char *uri, *ua; -+ char *ua; - - if(!(c = calloc(1, sizeof(Client)))) - die("Cannot malloc! "); -_AT_@ -832,8 +854,6 @@ newclient(void) { - if(!(ua = getenv("SURF_USERAGENT"))) - ua = useragent; - g_object_set(G_OBJECT(settings), "user-agent", ua, NULL); -- uri = g_strconcat("file://", stylefile, NULL); -- g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL); - g_object_set(G_OBJECT(settings), "auto-load-images", loadimages, - NULL); - g_object_set(G_OBJECT(settings), "enable-plugins", enableplugins, -_AT_@ -888,8 +908,6 @@ newclient(void) { - fullscreen(c, NULL); - } - -- g_free(uri); -- - setatom(c, AtomFind, ""); - setatom(c, AtomUri, "about:blank"); - if(hidebackground) -_AT_@ -1094,6 +1112,7 @@ setatom(Client *c, int a, const char *v) { - - static void - setup(void) { -+ int i; - char *proxy; - char *new_proxy; - SoupURI *puri; -_AT_@ -1114,7 +1133,15 @@ setup(void) { - /* dirs and files */ - cookiefile = buildpath(cookiefile); - scriptfile = buildpath(scriptfile); -- stylefile = buildpath(stylefile); -+ -+ /* site specific stylesheet regexes */ -+ for(i = 0; i < LENGTH(styles); i++) { -+ if(regcomp(&(styles[i].re), styles[i].regex, REG_EXTENDED)) { -+ fprintf(stderr, "Could not compile regex: %s ", styles[i].regex); -+ styles[i].regex = NULL; -+ } -+ styles[i].style = buildpath(styles[i].style); -+ } - - /* request handler */ - s = webkit_get_default_session(); -_AT_@ -1282,13 +1309,12 @@ togglescrollbars(Client *c, const Arg *arg) { - - static void - togglestyle(Client *c, const Arg *arg) { -- WebKitWebSettings *settings; -- char *uri; -+ WebKitWebSettings *settings = webkit_web_view_get_settings(c->view); -+ char *path; - -- settings = webkit_web_view_get_settings(c->view); -- g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &uri, NULL); -- uri = uri[0] ? g_strdup("") : g_strconcat("file://", stylefile, NULL); -- g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL); -+ g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &path, NULL); -+ path = (path && path[0]) ? g_strdup("") : getstyle(geturi(c)); -+ g_object_set(G_OBJECT(settings), "user-stylesheet-uri", path, NULL); - - updatetitle(c); - } -_AT_@ -1318,7 +1344,7 @@ gettogglestat(Client *c){ - togglestat[p++] = value? 'V': 'v'; - - g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &uri, NULL); -- togglestat[p++] = uri[0] ? 'M': 'm'; -+ togglestat[p++] = (uri && uri[0]) ? 'M': 'm'; - - togglestat[p] = 'Received on Tue Jan 20 2015 - 16:15:38 CET
This archive was generated by hypermail 2.3.0 : Thu Jun 18 2015 - 17:40:04 CEST