Hi gang, I recently took the time to rework a patch to surf which adds the ability to toggle between two stylesheets. I use this to impose a dark stylesheet, for when my eyes are less strong.
I'll put it on the wiki in the next few days. The patch is against tip. Nick
diff -r ac33ab13d1d0 config.def.h
--- a/config.def.h Tue Jan 17 13:58:04 2012 +0100
+++ b/config.def.h Tue Jan 31 23:18:53 2012 +0000
@@ -4,6 +4,7 @@
static char *progress_untrust = "#FF6600";
static char *progress_trust = "#00FF00";
static char *stylefile = ".surf/style.css";
+static char *altstylefile = ".surf/altstyle.css";
static char *scriptfile = ".surf/script.js";
static char *cookiefile = ".surf/cookies.txt";
static time_t sessiontime = 3600;
@@ -36,6 +37,7 @@
{ MODKEY, GDK_h, navigate, { .i = -1 } },
{ MODKEY, GDK_j, scroll, { .i = +1 } },
{ MODKEY, GDK_k, scroll, { .i = -1 } },
+ { MODKEY, GDK_s, togglestyle,{ 0 } },
{ 0, GDK_Escape, stop, { 0 } },
{ MODKEY, GDK_o, source, { 0 } },
{ MODKEY, GDK_g, spawn, SETPROP("_SURF_URI",
"_SURF_GO") },
diff -r ac33ab13d1d0 surf.1
--- a/surf.1 Tue Jan 17 13:58:04 2012 +0100
+++ b/surf.1 Tue Jan 31 23:18:53 2012 +0000
@@ -89,6 +89,9 @@
.TP
.B Ctrl\-o
show the sourcecode of the current page.
+.TP
+.B Ctrl\-s
+Toggles the user stylesheet.
.SH SEE ALSO
.BR dmenu(1),
.BR xprop(1),
diff -r ac33ab13d1d0 surf.c
--- a/surf.c Tue Jan 17 13:58:04 2012 +0100
+++ b/surf.c Tue Jan 31 23:18:53 2012 +0000
@@ -97,6 +97,7 @@
static void reload(Client *c, const Arg *arg);
static void resize(GtkWidget *w, GtkAllocation *a, Client *c);
static void scroll(Client *c, const Arg *arg);
+static void togglestyle(Client *c, const Arg *arg);
static void setatom(Client *c, int a, const char *v);
static void setcookie(SoupCookie *c);
static void setup(void);
@@ -669,6 +670,26 @@
}
void
+togglestyle(Client *c, const Arg *arg) {
+ WebKitWebSettings *settings;
+ gchar *styleuri, *altstyleuri, *cururi;
+
+ styleuri = g_strconcat("file://", buildpath(stylefile), NULL);
+ altstyleuri = g_strconcat("file://", buildpath(altstylefile), NULL);
+
+ settings = webkit_web_view_get_settings(c->view);
+ g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &cururi, NULL);
+ if(strcmp(cururi,styleuri) == 0)
+ g_object_set(G_OBJECT(settings), "user-stylesheet-uri",
altstyleuri, NULL);
+ else
+ g_object_set(G_OBJECT(settings), "user-stylesheet-uri",
styleuri, NULL);
+
+ g_free(styleuri);
+ g_free(altstyleuri);
+ g_free(cururi);
+}
+
+void
setcookie(SoupCookie *c) {
int lock;
pgpIYOcTqCMON.pgp
Description: PGP signature
