summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hofmann <scm@uninformativ.de>2018-07-10 19:44:09 +0200
committerPeter Hofmann <scm@uninformativ.de>2018-07-10 19:44:09 +0200
commitbd5749a1eaf3ce19687f1b68116343860e213055 (patch)
treec2ba06bd3d2877eb11c4b0b1ce950d6b2a5b6e41
parentbed710a4d1adc0d97cd9077e4a3cc95ea4ab9a1d (diff)
downloadlariza-bd5749a1eaf3ce19687f1b68116343860e213055.tar.gz
Get rid of those ugly global variables
-rw-r--r--browser.c89
1 files changed, 41 insertions, 48 deletions
diff --git a/browser.c b/browser.c
index 3b62ef3..e943f48 100644
--- a/browser.c
+++ b/browser.c
@@ -92,47 +92,6 @@ static gchar *search_text = NULL;
static gboolean tabbed_automagic = TRUE;
static gchar *user_agent = NULL;
-static gchar *feed_html_header =
-"<!DOCTYPE html>"
-"<html>"
-" <head>"
-" <meta charset=\"UTF-8\">"
-" <title>Feeds</title>"
-" </head>"
-" <body>"
-" <p>Feeds found on this page:</p>"
-" <ul>"
-;
-
-static gchar *feed_html_footer =
-" </ul>"
-" </body>"
-"</html>"
-;
-
-static gchar *grab_feeds =
-"a = document.querySelectorAll('"
-" html > head > link[rel=\"alternate\"][href][type=\"application/atom+xml\"],"
-" html > head > link[rel=\"alternate\"][href][type=\"application/rss+xml\"]"
-"');"
-"if (a.length == 0)"
-" null;"
-"else"
-"{"
-" out = '';"
-" for (i = 0; i < a.length; i++)"
-" {"
-" url = encodeURIComponent(a[i].href);"
-" if ('title' in a[i] && a[i].title != '')"
-" title = encodeURIComponent(a[i].title);"
-" else"
-" title = url;"
-" out += '<li><a href=\"' + url + '\">' + title + '</a></li>';"
-" }"
-" out;"
-"}"
-;
-
void
client_destroy(GtkWidget *widget, gpointer data)
@@ -379,14 +338,35 @@ changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data)
{
struct Client *c = (struct Client *)data;
gdouble p;
+ gchar *grab_feeds =
+ "a = document.querySelectorAll('"
+ " html > head > link[rel=\"alternate\"][href][type=\"application/atom+xml\"],"
+ " html > head > link[rel=\"alternate\"][href][type=\"application/rss+xml\"]"
+ "');"
+ "if (a.length == 0)"
+ " null;"
+ "else"
+ "{"
+ " out = '';"
+ " for (i = 0; i < a.length; i++)"
+ " {"
+ " url = encodeURIComponent(a[i].href);"
+ " if ('title' in a[i] && a[i].title != '')"
+ " title = encodeURIComponent(a[i].title);"
+ " else"
+ " title = url;"
+ " out += '<li><a href=\"' + url + '\">' + title + '</a></li>';"
+ " }"
+ " out;"
+ "}";
p = webkit_web_view_get_estimated_load_progress(WEBKIT_WEB_VIEW(c->web_view));
if (p == 1)
{
p = 0;
- /* The page has loaded fully. We now run a short JavaScript
- * snippet that operates on the DOM. It tries to grab all
+ /* The page has loaded fully. We now run a the short JavaScript
+ * snippet above that operates on the DOM. It tries to grab all
* occurences of <link rel="alternate" ...>, i.e. RSS/Atom feed
* references. */
webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(c->web_view),
@@ -777,10 +757,26 @@ hover_web_view(WebKitWebView *web_view, WebKitHitTestResult *ht, guint modifiers
}
void
-icon_location(GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event, gpointer data)
+icon_location(GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event,
+ gpointer data)
{
struct Client *c = (struct Client *)data;
gchar *d;
+ gchar *data_template =
+ "data:text/html,"
+ "<!DOCTYPE html>"
+ "<html>"
+ " <head>"
+ " <meta charset=\"UTF-8\">"
+ " <title>Feeds</title>"
+ " </head>"
+ " <body>"
+ " <p>Feeds found on this page:</p>"
+ " <ul>"
+ " %s"
+ " </ul>"
+ " </body>"
+ "</html>";
if (c->feed_html != NULL)
{
@@ -797,10 +793,7 @@ icon_location(GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event, g
*
* [0]: https://tools.ietf.org/html/rfc2397
* [1]: https://en.wikipedia.org/wiki/Data_URI_scheme */
- d = g_strdup_printf("data:text/html,%s%s%s",
- feed_html_header,
- c->feed_html,
- feed_html_footer);
+ d = g_strdup_printf(data_template, c->feed_html);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), d);
g_free(d);
}