Fetch page titles

This commit is contained in:
Mattias Erming 2014-09-27 13:39:14 -07:00
parent 2a00fb1bb6
commit 3a28afe408
4 changed files with 41 additions and 21 deletions

View File

@ -574,7 +574,7 @@ button {
content: '* '; content: '* ';
} }
#chat .toggle-button { #chat .toggle-button {
background: #eee; background: #f5f5f5;
border-radius: 2px; border-radius: 2px;
display: inline-block; display: inline-block;
color: #666; color: #666;
@ -588,16 +588,27 @@ button {
display: none; display: none;
color: #222; color: #222;
font: 12px Lato; font: 12px Lato;
max-width: 220px; max-width: 480px;
padding: 6px 8px; padding: 6px 8px;
margin-top: 2px; margin-top: 2px;
} }
#chat .toggle-content.show { #chat .toggle-content a {
display: inline-block !important; color: inherit;
} }
#chat .toggle-content img { #chat .toggle-content img {
max-width: 100%; max-width: 100%;
max-height: 100%; max-height: 100%;
display: block;
margin: 2px 0;
}
#chat .toggle-content .head {
font-weight: bold;
}
#chat .toggle-content .body {
color: #999;
}
#chat .toggle-content.show {
display: inline-block !important;
} }
#chat .count { #chat .count {
background: #fafafa; background: #fafafa;

View File

@ -130,17 +130,19 @@ templates['network'] = template({"1":function(depth0,helpers,partials,data) {
templates['toggle'] = template({"1":function(depth0,helpers,partials,data) { templates['toggle'] = template({"1":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return " <a href=\"" return " <a href=\""
+ escapeExpression(((helper = (helper = helpers.body || (depth0 != null ? depth0.body : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"body","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.link || (depth0 != null ? depth0.link : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"link","hash":{},"data":data}) : helper)))
+ "\" target=\"_blank\">\n <img src=\"" + "\" target=\"_blank\">\n <img src=\""
+ escapeExpression(((helper = (helper = helpers.body || (depth0 != null ? depth0.body : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"body","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.link || (depth0 != null ? depth0.link : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"link","hash":{},"data":data}) : helper)))
+ "\">\n </a>\n"; + "\">\n </a>\n";
},"3":function(depth0,helpers,partials,data) { },"3":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = " <a href=\""
return " <div class=\"head\">" + escapeExpression(((helper = (helper = helpers.link || (depth0 != null ? depth0.link : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"link","hash":{},"data":data}) : helper)))
+ escapeExpression(((helper = (helper = helpers.head || (depth0 != null ? depth0.head : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"head","hash":{},"data":data}) : helper))) + "\" target=\"_blank\">\n <div class=\"head\">";
+ "</div>\n <div class=\"body\">\n " stack1 = ((helper = (helper = helpers.head || (depth0 != null ? depth0.head : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"head","hash":{},"data":data}) : helper));
if (stack1 != null) { buffer += stack1; }
return buffer + "</div>\n <div class=\"body\">\n "
+ escapeExpression(((helper = (helper = helpers.body || (depth0 != null ? depth0.body : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"body","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.body || (depth0 != null ? depth0.body : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"body","hash":{},"data":data}) : helper)))
+ "\n </div>\n"; + "\n </div>\n </a>\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helperMissing=helpers.helperMissing, buffer = "<div class=\"toggle-content\">\n"; var stack1, helperMissing=helpers.helperMissing, buffer = "<div class=\"toggle-content\">\n";
stack1 = ((helpers.equal || (depth0 && depth0.equal) || helperMissing).call(depth0, (depth0 != null ? depth0.type : depth0), "image", {"name":"equal","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data})); stack1 = ((helpers.equal || (depth0 && depth0.equal) || helperMissing).call(depth0, (depth0 != null ? depth0.type : depth0), "image", {"name":"equal","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data}));

View File

@ -1,13 +1,15 @@
<div class="toggle-content"> <div class="toggle-content">
{{#equal type "image"}} {{#equal type "image"}}
<a href="{{body}}" target="_blank"> <a href="{{link}}" target="_blank">
<img src="{{body}}"> <img src="{{link}}">
</a> </a>
{{else}} {{else}}
<div class="head">{{head}}</div> <a href="{{link}}" target="_blank">
<div class="head">{{{head}}}</div>
<div class="body"> <div class="body">
{{body}} {{body}}
</div> </div>
</a>
{{/equal}} {{/equal}}
</div> </div>
</div> </div>

View File

@ -1,4 +1,5 @@
var _ = require("lodash"); var _ = require("lodash");
var cheerio = require("cheerio");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
var request = require("superagent"); var request = require("superagent");
@ -43,12 +44,16 @@ module.exports = function(irc, network) {
}; };
function parse(id, url, res, client) { function parse(id, url, res, client) {
var type = "";
var head = ""; var head = "";
var body = ""; var body = "";
var type = ""; var link = url;
switch (res.type) { switch (res.type) {
case "text/html": case "text/html":
var $ = cheerio.load(res.res.text);
type = "link"; type = "link";
head = $("title").text();
body = "No description found.";
break; break;
case "image/png": case "image/png":
@ -56,7 +61,6 @@ function parse(id, url, res, client) {
case "image/jpg": case "image/jpg":
case "image/jpeg": case "image/jpeg":
type = "image"; type = "image";
body = url;
break; break;
default: default:
@ -65,8 +69,9 @@ function parse(id, url, res, client) {
client.emit("toggle", { client.emit("toggle", {
id: id, id: id,
type: type, type: type,
head: type, head: head,
body: body body: body,
link: link,
}); });
} }