Skip to content

Instantly share code, notes, and snippets.

@youpy
Created March 21, 2009 20:37
Show Gist options
  • Save youpy/82974 to your computer and use it in GitHub Desktop.
Save youpy/82974 to your computer and use it in GitHub Desktop.
/* appjet:version 0.1 */
import('lib-html-xpath');
import('lib-json');
import("lib-uri");
function get_main() {
print(P(A({
href: '/pagelinks?url=' + encodeURIComponent('http://google.com/')
}, appjet.appName)));
}
function get_pagelinks() {
page.setMode("plain");
var url = request.params.url;
if(!url) {
return;
}
var hrefs = xget(url, '//*[@href]');
var uri = new URI(hrefs.base ? hrefs.base[0].href : url);
var links = [].concat(hrefs.a).map(function(link) {
if(link.href) {
return {
link: uri.resolveLink(link.href).toString()
};
}
});
print(raw(JSON.stringify(links)));
}
dispatch();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment