Skip to content
This repository
Browse code

Started messing with injecting back/forward buttons. Going to be more…

… difficult than expected:

1. The CSS for toggle buttons is only served up by Rdio if required, which means the user has to load their collection for it to show properly (initial page does not need it).
2. The header does some ajaxy operations which seem to remove anything I inject on dom ready (or even when $('#header') element is loaded. Which means I have to listen for some other event to know when I can inject the controls... no idea what event though.
3. Need to keep track of history to not let user back out of rdio.com (initial load is rdio.com/signup which redirects to rdio.com if user is signed in)

Current revision works but in a very buggy and unreliable way.
  • Loading branch information...
commit 482ce898e3a6dc2cffafabc42416493cefc2d928 1 parent 22a5d1d
Scott Ringwelski authored February 19, 2013

Showing 1 changed file with 25 additions and 0 deletions. Show diff stats Hide diff stats

  1. 25  rdio/Middleware.vala
25  rdio/Middleware.vala
@@ -83,6 +83,22 @@ public class Rdio.Middleware : GLib.Object {
83 83
 		alert(JSON.stringify(rv));
84 84
 	""";
85 85
 
  86
+	string INJECTED_CONTROLS = """<nav class="ViewToggle clearfix" style="float: left; margin: 20px 0px 20px 25px;"><ul><li class="first"><a href="#" onclick="history.back();">&lt;</a></li><li class="last"><a href="#" onclick="history.forward();">&gt;</a></li></ul></nav>""";
  87
+
  88
+	string INJECT_JS = """
  89
+		var timer = null;
  90
+		timer = setInterval(function(){
  91
+            if ($('#header')) {
  92
+				console.log('injecting into header');
  93
+				$('#header').prepend('%s');
  94
+                clearInterval(timer);  
  95
+            }
  96
+            else {
  97
+				console.log('waiting...');
  98
+			}
  99
+        },50);
  100
+	""";
  101
+
86 102
 	public Middleware (WebKit.WebView view) {
87 103
 		webview = view;
88 104
 		playing = false;
@@ -103,6 +119,15 @@ public class Rdio.Middleware : GLib.Object {
103 119
 
104 120
 		webview.execute_script (jquery_contents);
105 121
 		webview.execute_script (JS);
  122
+		
  123
+		Timeout.add(15000, () => {
  124
+			stdout.printf("injecting!!!!!!!!!!!!\n");
  125
+			stdout.printf(INJECT_JS.printf ("<p>hi</p>"));
  126
+			stdout.printf(INJECT_JS.printf (INJECTED_CONTROLS));
  127
+			webview.execute_script (INJECT_JS.printf (INJECTED_CONTROLS));
  128
+			stdout.printf("injected...................\n");
  129
+			return false;
  130
+		});
106 131
 
107 132
 		webview.script_alert.connect (alert);
108 133
 

0 notes on commit 482ce89

Please sign in to comment.
Something went wrong with that request. Please try again.