Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 9d6ce52c85
Fetching contributors…

Cannot retrieve contributors at this time

55 lines (53 sloc) 1.863 kB
<!DOCTYPE html>
<!--
* Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<html>
<head>
</head>
<body>
<script>
/**
* Performs an XMLHttpRequest to Twitter's API to get trending topics.
* @param callback Function If the response from fetching url has a
* HTTP status of 200, this function is called with a JSON decoded
* response. Otherwise, this function is called with null.
*/
function getHNComments(URL, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(data) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var data = JSON.parse(xhr.responseText);
callback(data);
} else {
callback(null);
}
}
}
// Note that any URL fetched here must be matched by a permission in
// the manifest.json file!
var url = "http://api.ihackernews.com/getid?url="+ escape(URL) +"&format=json";
xhr.open('GET', url, true);
xhr.send();
};
/**
* Handles data sent via chrome.extension.sendRequest().
* @param request Object Data sent in the request.
* @param sender Object Origin of the request.
* @param callback Function The method to call when the request completes.
*/
function onRequest(request, sender, callback) {
// Only supports the 'fetchTwitterFeed' method, although this could be
// generalized into a more robust RPC system.
if(request.URL){
getHNComments(request.URL, callback);
}
};
// Wire up the listener.
chrome.extension.onRequest.addListener(onRequest);
</script>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.