-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now with basic api for greasemonkey script
- Loading branch information
Graham Tackley
committed
Nov 25, 2011
1 parent
36745fc
commit a1a3c20
Showing
4 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package dashboard | ||
|
||
import comet.TopHitsServer | ||
import net.liftweb.common.Full | ||
|
||
import net.liftweb.json._ | ||
import net.liftweb.http.{S, JsonResponse} | ||
import net.liftweb.http.js.JE | ||
|
||
object Api { | ||
implicit val formats = Serialization.formats(NoTypeHints) | ||
|
||
private case class ApiCount(path: String, hitsPerSec: Double) | ||
|
||
def counts = { | ||
val cb = S.param("callback").getOrElse("fuck") | ||
val response = TopHitsServer.topStuff.everything.hits | ||
.map{ hit => "http://www.guardian.co.uk" + hit.url -> "%.1f".format(hit.hitsPerSec) }.toMap | ||
|
||
Full(JsonResponse(JE.Call(cb, Extraction.decompose(response)))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// ==UserScript== | ||
// @include http://www.guardian.co.uk/* | ||
// @name Show Guardian Link Hits | ||
// @namespace http://www.guardian.co.uk/usage | ||
// @description Show's Live Usage information on all guardian links | ||
// ==/UserScript== | ||
|
||
var jQuery = unsafeWindow.jQuery; | ||
|
||
jQuery.getJSON("http://gnmfasteragain.int.gnl:8081/api/counts?callback=?", function(result) { | ||
jQuery('.greasy-hits').remove() | ||
jQuery('a.link-text').each(function(i, node) { | ||
console.log(node); | ||
if (result[node.href] != undefined) { | ||
jQuery(node).before("<span class=greasy-hits style='position: absolute; z-index: 9000; background-color: #62CFFC;font-size: 10pt;border-radius: 3px;color: white;padding: 1px 3px 2px; text-indent: 0'>" + result[node.href] +"</span>"); | ||
} | ||
}); | ||
}); | ||
|