Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

286 lines (247 sloc) 8.918 kB
<html>
<head>
<script type="text/javascript" src="lib/3rdparty/jquery.js"></script>
<script type="text/javascript" src="lib/options.js"></script>
<script type="text/javascript" src="lib/utils.js"></script>
<script type="text/javascript" src="lib/instaket.js"></script>
<script>
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
sendResponse(JSON.parse(sessionStorage.getItem(request.id)));
});
function log(Message){
if (Options.getBoolean("debug"))
console.log(Message);
}
function show(message, image, title) {
title = title ? title : "inagist.com";
image = image ? image : 'img/inagist48.png';
var notification = webkitNotifications.createNotification(
image, // The image.
title, // The title.
message // The body.
);
notification.show();
}
function showHtml() {
if (chrome.extension.getViews({type: "notification"}).length == 0){
var notification = webkitNotifications.createHTMLNotification(
'tweets_notifier.html'
);
notification.show();
}
}
function showTweetNotification(tweet_id, tipText){
if (sessionStorage.getItem(tweet_id) == null) {
iSocket.lookuptweet(tweet_id, function(data){
data.corelation = tipText;
sessionStorage.setItem(tweet_id, JSON.stringify(data));
chrome.i18n.getAcceptLanguages(function(langs){
if (Options.getBoolean("showUnknownLanguages") ||
typeof data.language == "undefined" ||
(typeof data.language == "string" &&
(data.language.substring(1) == 'uu' || $.inArray(data.language.substring(1), langs) > -1))){
var date = new Date(Date.parse(data.created_at));
if (tipText != undefined &&
(((new Date()).getTime() - date.getTime()) / 1000) > Options.getInt("relevanceTime"))
return;
notificationQueue.push(tweet_id);
showHtml();
}
});
});
}
}
function iconAlert(Color, Text) {
chrome.browserAction.setBadgeBackgroundColor({color: Color});
chrome.browserAction.setBadgeText({text: Text});
}
function setToolTip(Text) {
chrome.browserAction.setTitle({title: Text});
}
function sendSearch(Text) {
if ((iSocket.ws.readyState == iSocket.ws.OPEN) && Text && (Text.trim().length > 0)) {
log("Sending search terms " + Text.trim());
iSocket.search(Text.trim());
}
}
function trimElement(element) {
return element.trim();
}
function addSearchTerm(Text){
if ((typeof(Text) != 'undefined') && (Text != '')) {
var searchTerms = Options.get("searchText").split(",").map(trimElement);
searchTerms.push(Text);
Options.set("searchText", searchTerms.join(","));
}
}
function getSearchTerms(){
var searchTerms = Options.get("searchText").split(",").map(trimElement);
var ignoredTrends = [];
if (Options.get("ignoredTrends"))
ignoredTrends = Options.get("ignoredTrends").split(",").map(trimElement);
if (Options.get("autoTrackTrends") === true || Options.get("autoTrackTrends") == "true") {
for (i in autoTracked) {
if (($.inArray(autoTracked[i], searchTerms) < 0) && ($.inArray(autoTracked[i], ignoredTrends) < 0))
searchTerms.push(autoTracked[i]);
}
}
if (Options.get("autoTrackChannelTrends") === true || Options.get("autoTrackChannelTrends") == "true") {
for (i in autoTrackedChannel) {
if (($.inArray(autoTrackedChannel[i], searchTerms) < 0) && ($.inArray(autoTrackedChannel[i], ignoredTrends) < 0))
searchTerms.push(autoTrackedChannel[i]);
}
}
return searchTerms.slice(0, 20).join(", ");
}
function sendSearchTerms() {
var text = getSearchTerms();
sendSearch(text);
}
function connect() {
autoTrackedChannel = [],
autoTracked = [];
if ("WebSocket" in window) {
var url = Options.get("websocketURL");
if (Options.getBoolean("encrypt"))
url = Options.get("websocketSecureURL");
var options = {url: url, archive_limit: Options.get("tweet_archived_limit"), debug: false};
if (Options.get("autoTrackTrends"))
options.trackwords = true;
if (Options.getBoolean("debug"))
options.debug = true;
iSocket = new Instaket(connectedUser, options);
$(iSocket).bind('user_connected',function() {
iconAlert([10, 200, 10, 228], "On");
setToolTip("inagist.com - " + connectedUser);
searchTimer = setTimeout(function() {sendSearchTerms();}, 5000);
});
$(iSocket).bind('trackwords', function(event, trackwords){
if (trackwords.length > 0) {
trackwords = trackwords.map(trimElement);
for (i in trackwords) {
if ($.inArray(trackwords[i], autoTracked) < 0) {
autoTracked.push(trackwords[i]);
}
}
}
clearTimeout(searchTimer);
sendSearchTerms();
});
$(iSocket).bind('trending_personal_phrase', function(event, trending_personal_phrase) {
var tipText = " trend " + trending_personal_phrase.phrase + " for you";
if ($.inArray(trending_personal_phrase.phrase, autoTracked) < 0) {
autoTracked.push(trending_personal_phrase.phrase);
if (Options.get("autoTrackTrends") === true || Options.get("autoTrackTrends") == "true")
sendSearchTerms();
}
showTweetNotification(trending_personal_phrase.id_str, tipText);
});
$(iSocket).bind('trending_channel_phrase', function(event, trending_channel_phrase) {
var tipText = " trend " + trending_channel_phrase.phrase +
" in " + trending_channel_phrase.channel;
if ($.inArray(trending_channel_phrase.phrase, autoTrackedChannel) < 0) {
autoTrackedChannel.push(trending_channel_phrase.phrase);
if (Options.get("autoTrackChannelTrends") === true || Options.get("autoTrackChannelTrends") == "true")
sendSearchTerms();
}
showTweetNotification(trending_channel_phrase.id_str, tipText);
});
$(iSocket).bind('tweet_archived', function(event, tweet) {
showTweetNotification(tweet.id_str, undefined);
});
$(iSocket).bind('search_result', function(event, search_result) {
if (search_result.ids) {
for (var i in search_result.ids) {
showTweetNotification(search_result.ids[i], undefined);
}
} else {
var corelationText = undefined;
if (search_result.text)
corelationText = search_result.text;
showTweetNotification(search_result.id_str, corelationText);
}
});
$(iSocket).bind('connection_closed', function(){
iconAlert([200, 10, 10, 228], "Off");
setToolTip("inagist.com");
});
$(iSocket).bind('connection_errored', function() {
reConnect();
});
iSocket.connect();
} else {
show("You have no web sockets");
};
}
function disconnect() {
iSocket.disconnect();
}
function toggleConnection() {
if ((typeof iSocket == 'undefined' || typeof iSocket.ws == 'undefined') ||
(iSocket.ws.readyState === iSocket.ws.CLOSED)) {
connectedUser = Options.get("userid");
if (connectedUser && connectedUser.trim().length > 0)
connect();
} else {
disconnect();
}
}
function reConnect() {
sessionStorage.clear();
disconnect();
toggleConnection();
}
function onClickHandler(info, tab) {
var sel = info.selectionText;
if (sel != undefined){
var bg = chrome.extension.getBackgroundPage();
bg.addSearchTerm(sel);
bg.sendSearchTerms();
}
}
Options.init();
chrome.idle.onStateChanged.addListener(function(newState){
console.log("State changed to " + newState);
});
var notificationQueue = [];
var archivalQueue = [];
var iSocket = null;
var autoTracked = [];
var autoTrackedChannel = [];
var searchTimer = undefined;
var connectedUser = undefined;
chrome.browserAction.onClicked.addListener(toggleConnection);
iconAlert([200, 10, 10, 228], "Off");
if (typeof Options.get("userid") == 'undefined')
getUserDetails(
function(data){
Options.set("userid", data.user_id);
connectedUser = Options.get("userid");
connect();
},
function(){});
if (chrome.contextMenus) {
chrome.contextMenus.create({'title': "Add to In-A-Gist search",
'documentUrlPatterns': [ 'http://*/*', 'https://*/*' ],
'onclick': onClickHandler,
'contexts': ['selection']});
}
connectedUser = Options.get("userid");
if (connectedUser)
connect();
</script>
</head>
<body>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16053252-4']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.