From 990b6b77bdf1ddc6b47337a899db672179a432a3 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Mon, 24 Oct 2011 19:27:34 +0200 Subject: [PATCH] Look for localized "next page" link and unify code --- midori/midori-view.c | 71 ++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/midori/midori-view.c b/midori/midori-view.c index 8d94a6e3..f1be02ac 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -4969,43 +4969,56 @@ midori_view_go_forward (MidoriView* view) webkit_web_view_go_forward (WEBKIT_WEB_VIEW (view->web_view)); } -/** - * midori_view_get_previous_page - * @view: a #MidoriView - * - * Determines the previous sub-page in the view. - * - * Return value: an URI, or %NULL - * - * Since: 0.2.3 - **/ -const gchar* -midori_view_get_previous_page (MidoriView* view) +static gchar* +midori_view_get_related_page (MidoriView* view, + const gchar* rel, + const gchar* local) { + gchar* script; static gchar* uri = NULL; WebKitWebFrame* web_frame; JSContextRef js_context; - g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL); - if (!view->web_view) return NULL; web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view)); js_context = webkit_web_frame_get_global_context (web_frame); - katze_assign (uri, sokoke_js_script_eval (js_context, + script = g_strdup_printf ( "(function (tags) {" "for (var tag in tags) {" "var l = document.getElementsByTagName (tag);" "for (var i in l) { " - "if ((l[i].rel && l[i].rel.toLowerCase () == 'prev') " + "if ((l[i].rel && l[i].rel.toLowerCase () == '%s') " " || (l[i].innerHTML" - " && l[i].innerHTML.toLowerCase ().indexOf ('prev') != -1)) " + " && (l[i].innerHTML.toLowerCase ().indexOf ('%s') != -1 " + " || l[i].innerHTML.toLowerCase ().indexOf ('%s') != -1)))" "{ return l[i].href; } } } return 0; })(" - "{ link:'link', a:'a' });", NULL)); + "{ link:'link', a:'a' });", rel, rel, local); + katze_assign (uri, sokoke_js_script_eval (js_context, script, NULL)); + g_free (script); return uri && uri[0] != '0' ? uri : NULL; } +/** + * midori_view_get_previous_page + * @view: a #MidoriView + * + * Determines the previous sub-page in the view. + * + * Return value: an URI, or %NULL + * + * Since: 0.2.3 + **/ +const gchar* +midori_view_get_previous_page (MidoriView* view) +{ + g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL); + + /* i18n: word stem of "previous page" type links, case is not important */ + return midori_view_get_related_page (view, "prev", _("previous")); +} + /** * midori_view_get_next_page * @view: a #MidoriView @@ -5019,28 +5032,10 @@ midori_view_get_previous_page (MidoriView* view) const gchar* midori_view_get_next_page (MidoriView* view) { - static gchar* uri = NULL; - WebKitWebFrame* web_frame; - JSContextRef js_context; - g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL); - if (!view->web_view) - return NULL; - - web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view)); - js_context = webkit_web_frame_get_global_context (web_frame); - katze_assign (uri, sokoke_js_script_eval (js_context, - "(function (tags) {" - "for (var tag in tags) {" - "var l = document.getElementsByTagName (tag);" - "for (var i in l) { " - "if ((l[i].rel && l[i].rel.toLowerCase () == 'next') " - " || (l[i].innerHTML" - " && l[i].innerHTML.toLowerCase ().indexOf ('next') != -1)) " - "{ return l[i].href; } } } return 0; })(" - "{ link:'link', a:'a' });", NULL)); - return uri && uri[0] != '0' ? uri : NULL; + /* i18n: word stem of "next page" type links, case is not important */ + return midori_view_get_related_page (view, "next", _("next")); } static GtkWidget* -- 2.39.5