Add support for userscript and readjust/rename existing patches - pkgsrc-localpatches - leot's pkgsrc LOCALPATCHES
(HTM) hg clone https://bitbucket.org/iamleot/pkgsrc-localpatches
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) changeset a3bb5710584d93c5f56ce1006325968899130b03
(DIR) parent 15b6ebeea60b0ca57995d8c573ed2dae277d9212
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Sat, 8 Jun 2019 15:13:28
Add support for userscript and readjust/rename existing patches
Diffstat:
wip/surf-git/clickplumb.patch | 30 +++++++
wip/surf-git/patch-config.h | 15 +++-
wip/surf-git/patch-surf.c | 30 -------
wip/surf-git/userscript.patch | 159 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 201 insertions(+), 33 deletions(-)
---
diff -r 15b6ebeea60b -r a3bb5710584d wip/surf-git/clickplumb.patch
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/wip/surf-git/clickplumb.patch Sat Jun 08 15:13:28 2019 +0200
@@ -0,0 +1,30 @@
+$NetBSD$
+
+Add support to invoke plumb via a button.
+
+--- surf.c.orig 2019-03-06 11:19:52.000000000 +0000
++++ surf.c
+@@ -236,6 +236,7 @@ static void find(Client *c, const Arg *a
+ static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
+ static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
+ static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
++static void clickplumb(Client *c, const Arg *a, WebKitHitTestResult *h);
+
+ static char winid[64];
+ static char togglestats[12];
+@@ -1971,6 +1972,15 @@ clickexternplayer(Client *c, const Arg *
+ spawn(c, &arg);
+ }
+
++void
++clickplumb(Client *c, const Arg *a, WebKitHitTestResult *h)
++{
++ Arg arg;
++
++ arg = (Arg)PLUMB(c->targeturi ? c->targeturi : geturi(c));
++ spawn(c, &arg);
++}
++
+ int
+ main(int argc, char *argv[])
+ {
diff -r 15b6ebeea60b -r a3bb5710584d wip/surf-git/patch-config.h
--- a/wip/surf-git/patch-config.h Thu Jun 06 23:47:28 2019 +0200
+++ b/wip/surf-git/patch-config.h Sat Jun 08 15:13:28 2019 +0200
@@ -1,10 +1,11 @@
---- /dev/null 2019-06-03 18:40:00.341169522 +0200
-+++ config.h 2019-06-03 18:39:16.301339328 +0200
-@@ -0,0 +1,209 @@
+--- /dev/null 2019-06-08 14:15:07.842795313 +0200
++++ config.h 2019-06-08 14:14:50.272358309 +0200
+@@ -0,0 +1,218 @@
+/* modifier 0 means no modifier */
+static int surfuseragent = 0; /* Append Surf version to default WebKit user agent */
+static char *fulluseragent = "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"; /* Or override the whole user agent string */
+static char *scriptfile = "~/.surf/script.js";
++static char *scriptdir = "~/.surf/script/";
+static char *styledir = "~/.surf/styles/";
+static char *certdir = "~/.surf/certificates/";
+static char *cachedir = "/tmp/.surf/cache/";
@@ -49,6 +50,7 @@
+ [SpellLanguages] = { { .v = ((char *[]){ "en_US", NULL }) }, },
+ [StrictTLS] = { { .i = 1 }, },
+ [Style] = { { .i = 1 }, },
++ [UserScript] = { { .i = 1 }, },
+ [WebGL] = { { .i = 0 }, },
+ [ZoomLevel] = { { .f = 1.0 }, },
+};
@@ -128,6 +130,13 @@
+ { ".*", "default.css" },
+};
+
++/* scripts */
++static SiteSpecific scripts[] = {
++ /* regexp file in $scriptdir */
++ { "://twitter\\.com/", "twitter.js" },
++ { ".*", "default.js" },
++};
++
+/* certificates */
+/*
+ * Provide custom certificate for urls
diff -r 15b6ebeea60b -r a3bb5710584d wip/surf-git/patch-surf.c
--- a/wip/surf-git/patch-surf.c Thu Jun 06 23:47:28 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-$NetBSD$
-
-Add support to invoke plumb via a button.
-
---- surf.c.orig 2019-03-06 11:19:52.000000000 +0000
-+++ surf.c
-@@ -236,6 +236,7 @@ static void find(Client *c, const Arg *a
- static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
- static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
- static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
-+static void clickplumb(Client *c, const Arg *a, WebKitHitTestResult *h);
-
- static char winid[64];
- static char togglestats[12];
-@@ -1971,6 +1972,15 @@ clickexternplayer(Client *c, const Arg *
- spawn(c, &arg);
- }
-
-+void
-+clickplumb(Client *c, const Arg *a, WebKitHitTestResult *h)
-+{
-+ Arg arg;
-+
-+ arg = (Arg)PLUMB(c->targeturi ? c->targeturi : geturi(c));
-+ spawn(c, &arg);
-+}
-+
- int
- main(int argc, char *argv[])
- {
diff -r 15b6ebeea60b -r a3bb5710584d wip/surf-git/userscript.patch
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/wip/surf-git/userscript.patch Sat Jun 08 15:13:28 2019 +0200
@@ -0,0 +1,159 @@
+$NetBSD$
+
+Add support for user script.
+
+--- config.def.h.orig
++++ config.def.h
+@@ -3,6 +3,7 @@ static int surfuseragent = 1; /* Append Surf version to default WebKit user
+ static char *fulluseragent = ""; /* Or override the whole user agent string */
+ static char *scriptfile = "~/.surf/script.js";
+ static char *styledir = "~/.surf/styles/";
++static char *scriptdir = "~/.surf/script/";
+ static char *certdir = "~/.surf/certificates/";
+ static char *cachedir = "~/.surf/cache/";
+ static char *cookiefile = "~/.surf/cookies.txt";
+@@ -46,6 +47,7 @@ static Parameter defconfig[ParameterLast] = {
+ [SpellLanguages] = { { .v = ((char *[]){ "en_US", NULL }) }, },
+ [StrictTLS] = { { .i = 1 }, },
+ [Style] = { { .i = 1 }, },
++ [UserScript] = { { .i = 1 }, },
+ [WebGL] = { { .i = 0 }, },
+ [ZoomLevel] = { { .f = 1.0 }, },
+ };
+@@ -112,6 +114,12 @@ static SiteSpecific styles[] = {
+ { ".*", "default.css" },
+ };
+
++/* scripts */
++static SiteSpecific scripts[] = {
++ /* regexp file in $scriptdir */
++ { ".*", "default.js" },
++};
++
+ /* certificates */
+ /*
+ * Provide custom certificate for urls
+--- surf.c.orig
++++ surf.c
+@@ -80,6 +80,7 @@ typedef enum {
+ SpellLanguages,
+ StrictTLS,
+ Style,
++ UserScript,
+ WebGL,
+ ZoomLevel,
+ ParameterLast
+@@ -164,7 +165,9 @@ static void seturiparameters(Client *c, const char *uri, ParamName *params);
+ static void setparameter(Client *c, int refresh, ParamName p, const Arg *a);
+ static const char *getcert(const char *uri);
+ static void setcert(Client *c, const char *file);
++static const char *getscript(const char *uri);
+ static const char *getstyle(const char *uri);
++static void setscript(Client *c, const char *file);
+ static void setstyle(Client *c, const char *file);
+ static void runscript(Client *c);
+ static void evalscript(Client *c, const char *jsstr, ...);
+@@ -265,6 +268,7 @@ static ParamName loadtransient[] = {
+ PreferredLanguages,
+ ShowIndicators,
+ StrictTLS,
++ UserScript,
+ ParameterLast
+ };
+
+@@ -340,6 +344,7 @@ setup(void)
+ scriptfile = buildfile(scriptfile);
+ cachedir = buildpath(cachedir);
+ certdir = buildpath(certdir);
++ scriptdir = buildpath(scriptdir);
+
+ gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
+
+@@ -364,6 +369,17 @@ setup(void)
+ }
+ }
+
++ for (i = 0; i < LENGTH(scripts); ++i) {
++ if (!regcomp(&(scripts[i].re), scripts[i].regex, REG_EXTENDED)) {
++ scripts[i].file = g_strconcat(scriptdir, "/", scripts[i].file,
++ NULL);
++ } else {
++ fprintf(stderr, "Could not compile regex: %s\n",
++ scripts[i].regex);
++ scripts[i].regex = NULL;
++ }
++ }
++
+ if (!stylefile) {
+ styledir = buildpath(styledir);
+ for (i = 0; i < LENGTH(styles); ++i) {
+@@ -722,6 +738,7 @@ seturiparameters(Client *c, const char *uri, ParamName *params)
+ case Certificate:
+ case CookiePolicies:
+ case Style:
++ case UserScript:
+ setparameter(c, 0, p, &curconfig[p].val);
+ }
+ }
+@@ -846,6 +863,13 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a)
+ setstyle(c, getstyle(geturi(c)));
+ refresh = 0;
+ break;
++ case UserScript:
++ webkit_user_content_manager_remove_all_scripts(
++ webkit_web_view_get_user_content_manager(c->view));
++ if (a->i)
++ setscript(c, getscript(geturi(c)));
++ refresh = 0;
++ break;
+ case WebGL:
+ webkit_settings_set_enable_webgl(s, a->i);
+ break;
+@@ -902,6 +926,20 @@ setcert(Client *c, const char *uri)
+
+ }
+
++const char *
++getscript(const char *uri)
++{
++ int i;
++
++ for (i = 0; i < LENGTH(scripts); ++i) {
++ if (scripts[i].regex &&
++ !regexec(&(scripts[i].re), uri, 0, NULL, 0))
++ return scripts[i].file;
++ }
++
++ return "";
++}
++
+ const char *
+ getstyle(const char *uri)
+ {
+@@ -919,6 +957,26 @@ getstyle(const char *uri)
+ return "";
+ }
+
++void
++setscript(Client *c, const char *file)
++{
++ gchar *script;
++
++ if (!g_file_get_contents(file, &script, NULL, NULL)) {
++ fprintf(stderr, "Could not read script file: %s\n", file);
++ return;
++ }
++
++ webkit_user_content_manager_add_script(
++ webkit_web_view_get_user_content_manager(c->view),
++ webkit_user_script_new(script,
++ WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
++ WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END,
++ NULL, NULL));
++
++ g_free(script);
++}
++
+ void
+ setstyle(Client *c, const char *file)
+ {