Hello,

first of all, the credit for this patch does not go to me, although I modified
it partly.

I made a new patch against tip which now includes a setting in the config.h and
seems to work The problem is, when you toggle flash or images you need to
reload the page by hand with the old patch, so I added a reload call.  Also,
the tabs should now be conforming to those found in surf sourcecode (\t
instead of spaces)

Thanks to Julien to remind me of this patch, and to whoever wrote the original
patch some time ago.

Moritz

On Mon, Mar 22, 2010 at 05:20:38PM +0100, julien steinhauser wrote:
> Hello,
> 
> I added 2 SLOC to the patch Moritz Wilhelmy sent to the mailing list on
> 28/09/2009.
> 
> These 2 lines in newclient function make the patch behave opposite to what it
> behaved.
> 
> I mean that images and flash are now disabled by default and it's a good
> adblocker. :)
> 
> It applies on tip.  I hope it will be useful for someone.
> 
> Thanks to Moritz for this patch as it prevents disturbances while surfing and
> that's quite enjoyable to me.
> 
> Julien
diff -r 36f57673edf0 config.def.h
--- a/config.def.h	Wed Mar 10 21:38:07 2010 +0100
+++ b/config.def.h	Mon Mar 22 18:45:45 2010 +0100
@@ -7,6 +7,8 @@
 static char *cookiefile     = ".surf/cookies.txt";
 static char *dldir          = ".surf/dl/";
 static time_t sessiontime   = 3600;
+static gboolean enable_plugins = FALSE; /* do not load plugins, for instance flash on program start */
+static gboolean auto_load_images = TRUE; /* do load images per default */
 
 #define SETPROP(p)       { .v = (char *[]){ "/bin/sh", "-c", \
 	"prop=\"`xprop -id $1 $0 | cut -d '\"' -f 2 | dmenu`\" &&" \
@@ -18,6 +20,8 @@
     { MODKEY|GDK_SHIFT_MASK,GDK_r,      reload,     { .b = TRUE } },
     { MODKEY,               GDK_r,      reload,     { .b = FALSE } },
     { MODKEY|GDK_SHIFT_MASK,GDK_p,      print,      { 0 } },
+    { MODKEY,               GDK_f,      toggleflash,{ 0 } },
+    { MODKEY,               GDK_i,      toggleimages,{ 0 } },
     { MODKEY,               GDK_p,      clipboard,  { .b = TRUE } },
     { MODKEY,               GDK_y,      clipboard,  { .b = FALSE } },
     { MODKEY|GDK_SHIFT_MASK,GDK_j,      zoom,       { .i = -1 } },
diff -r 36f57673edf0 surf.c
--- a/surf.c	Wed Mar 10 21:38:07 2010 +0100
+++ b/surf.c	Mon Mar 22 18:45:45 2010 +0100
@@ -104,6 +104,8 @@
 static void spawn(Client *c, const Arg *arg);
 static void stop(Client *c, const Arg *arg);
 static void titlechange(WebKitWebView *v, WebKitWebFrame* frame, const char* title, Client *c);
+static void toggleflash(Client *c, const Arg *arg);
+static void toggleimages(Client *c, const Arg *arg);
 static void update(Client *c);
 static void updatedownload(WebKitDownload *o, GParamSpec *pspec, Client *c);
 static void updatewinid(Client *c);
@@ -534,6 +536,8 @@
 	if(!(ua = getenv("SURF_USERAGENT")))
 		ua = useragent;
 	g_object_set(G_OBJECT(settings), "user-agent", ua, NULL);
+	g_object_set(G_OBJECT(settings), "enable-plugins", enable_plugins, NULL);
+	g_object_set(G_OBJECT(settings), "auto-load-images", auto_load_images, NULL);
 	uri = g_strconcat("file://", stylefile, NULL);
 	g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
 	g_free(uri);
@@ -763,6 +767,26 @@
 }
 
 void
+toggleflash(Client *c, const Arg *arg)
+{
+	WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
+	g_object_get(G_OBJECT(settings), "enable_plugins", &enable_plugins, NULL);
+	enable_plugins = !enable_plugins;
+	g_object_set(G_OBJECT(settings), "enable-plugins", enable_plugins, NULL);
+	reload(c, arg); /* required for the settings to be applied */
+}
+
+void
+toggleimages(Client *c, const Arg *arg)
+{
+	WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
+	g_object_get(G_OBJECT(settings), "auto-load-images", &auto_load_images, NULL);
+	auto_load_images = !auto_load_images;
+	g_object_set(G_OBJECT(settings), "auto-load-images", auto_load_images, NULL);
+	reload(c, arg); /* required for the settings to be applied */
+}
+
+void
 update(Client *c) {
 	char *t;
 

Reply via email to