+ if (related_wv == NULL) {
+ WebKitUserContentManager *ucm = webkit_user_content_manager_new();
+ WebKitUserScript *wkscript;
+ WebKitUserStyleSheet *wkstyle;
+ gchar *path = NULL, *source, *base;
+ const gchar *entry = NULL;
+ GDir *dir = NULL;
+
+ base = g_build_filename(g_get_user_data_dir(), __NAME__, "user-scripts",
+ NULL);
+ dir = g_dir_open(base, 0, NULL);
+ if (dir != NULL) {
+ while ((entry = g_dir_read_name(dir)) != NULL) {
+ path = g_build_filename(base, entry, NULL);
+ if (g_str_has_suffix(path, ".js")) {
+ g_file_get_contents(path, &source, NULL, NULL);
+ wkscript = webkit_user_script_new(
+ source, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
+ WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START, NULL,
+ NULL);
+ webkit_user_content_manager_add_script(ucm, wkscript);
+ webkit_user_script_unref(wkscript);
+ }
+ g_free(path);
+ g_free(source);
+ }
+ g_dir_close(dir);
+ }
+
+ base = g_build_filename(g_get_user_data_dir(), __NAME__, "user-styles",
+ NULL);
+ dir = g_dir_open(base, 0, NULL);
+ if (dir != NULL) {
+ while ((entry = g_dir_read_name(dir)) != NULL) {
+ path = g_build_filename(base, entry, NULL);
+ if (g_str_has_suffix(path, ".css")) {
+ g_file_get_contents(path, &source, NULL, NULL);
+ wkstyle = webkit_user_style_sheet_new(
+ source, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
+ WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL);
+ webkit_user_content_manager_add_style_sheet(ucm, wkstyle);
+ webkit_user_style_sheet_unref(wkstyle);
+ }
+ g_free(path);
+ g_free(source);
+ }
+ g_dir_close(dir);
+ }
+
+ g_free(base);
+
+ c->web_view = webkit_web_view_new_with_user_content_manager(ucm);
+ } else {