Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions apps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Truncates a string to specified length.
*
* @param {string} string to truncate
* @param {int} maximum length of truncated string
* @param {bool} If true, an ellipsis will be added to the end of the truncated string
* @return {string} Retruns truncated string. If string is shorter than len, unmodified string is returned.
*/
function truncate(str, len, dots)
{
var ret = str;
if(str.length > len)
{
ret = str.substring(0, len-1);
if(dots)
ret += "...";
}

return ret;
}

/**
* Get the URL for an application icon of specified size.
*
* @param {array of IconInfo} appIcons Array of IconInfo, includes size and url.
* @param {int} size Required size.
* @return {string} Returns URL to app icon of required size. If the app does not have an icon of required size,
* the last (largest) icon found is returned.
*/

function findIcon(appIcons, size)
{
for (i in appIcons)
{
if(appIcons[i].size == size)
return appIcons[i].url;
}
return appIcons[appIcons.length-1].url;
}

/**
* Stuff to be done at launch
*/
$(document).ready(function(){
/*
* Initialization
*/
// Apps menu
if (localStorage['show_apps'] === 'true') {
$('#main').show();
chrome.management.getAll(function(list) {
c = 0;
for (var i in list)
{
var app = list[i];
if(app.isApp && app.enabled)
{
//console.log(app.name + "--" + app.id);
var appId = app.id;
var appName = app.name;
var appIcon = findIcon(app.icons, 128);
var div = document.createElement('div');
$(div).addClass('app');
//$(div).css('left', (130 + 130*c) + "px")
var a = document.createElement('a');
$(a).click(function() { chrome.management.launchApp(this.id); });
$(a).attr("href", "#");
$(a).attr("id", appId);
$(a).css('background-image',"url(" + appIcon + ")");
$(a).append(appName);
$(div).append(a);
$('#appsMenu').append(div);
c = c + 1;
}
}
c = c + 2;
$('#main').css('height', 60 + (180 * (c/7)) + 'px');
var appName = "Web Store";
var appIcon = "webstore.png";

var div = document.createElement('div');
$(div).addClass('app');
var a = document.createElement('a');
$(a).attr("href", "https://chrome.google.com/webstore");
$(a).attr("id", "pjkljhegncpnkpknbcohdijeoejaedia");
$(a).css('background-image',"url(" + appIcon + ")");
$(a).append(appName);
$(div).append(a);
$('#appsMenu').append(div);

});
}
});
66 changes: 42 additions & 24 deletions background.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<script>
var API_KEY = "YOUR_KEY_HERE";
var VISIVO_SET = "72157623563233239";
var TYPE = localStorage['type']; //'pool'; // 'pool' or 'photoset'
var SET_ID = localStorage['set_id']; //'384452@N21'; // VISIVO_SET = "72157623563233239";
var PER_PAGE = "500";
var shortTimeout = 500;
var longTimeout = 5 * 60 * 1000;
var DEBUG = false;
var DEBUG = (localStorage['debug'] === 'true');
function log (o) {
if (DEBUG) console.log(o);
}
var ownername = '';
var owner = '';

// CONFIG OPTIONS
localStorage["useSmallerImages"] = true;
localStorage["showTitle"] = false;
//localStorage["showOwner"] = true;
localStorage["showTitle"] = true;
localStorage["showOwner"] = true;

function fetchPool(poolId, callback) {
var req = new XMLHttpRequest();
Expand All @@ -25,7 +28,7 @@
"extras=url_o&" +
"per_page=" + PER_PAGE,
true);
req.onload = function () { callback(req) };
req.onload = function () { callback(req, 'photos'); };
req.send(null);
}

Expand All @@ -40,18 +43,22 @@
"extras=url_o&" +
"per_page=" + PER_PAGE,
true);
req.onload = function () { callback(req) };
req.onload = function () { callback(req, 'photoset'); };
req.send(null);
}

function fillCache(req) {
var photoset = req.responseXML.getElementsByTagName("photoset");
function fillCache(req, type) {
log(req.responseXML);
var photoset = req.responseXML.getElementsByTagName(type);
var photos = req.responseXML.getElementsByTagName("photo");
log(photos);
if (type == 'photoset'){
ownername = photoset[0].getAttribute('ownername');
owner = photoset[0].getAttribute('owner');
}

// start adding some new ones
function againAndAgain() {
var photoCache = JSON.parse(localStorage["photoCache"])
var photoCache = JSON.parse(localStorage["photoCache"]);
addOnePhoto(photos);
if (photoCache.length < 30) {
window.setTimeout(againAndAgain, shortTimeout);
Expand All @@ -76,18 +83,27 @@
} else {
img.src = photo.getAttribute("url_o");
}
document.body.appendChild(img);
var photoCache = JSON.parse(localStorage["photoCache"]);
var cached = {"src": img.src,
"title": photo.getAttribute("title"),
"id": photo.getAttribute("id")
}

cached.ownername = 'visivo';
cached.owner = 'visivo';

photoCache.push(cached);
localStorage["photoCache"] = JSON.stringify(photoCache);
if (img.src != '') {
document.body.appendChild(img);
var photoCache = JSON.parse(localStorage["photoCache"]);
var cached = {"src": img.src,
"title": photo.getAttribute("title"),
"id": photo.getAttribute("id")
};
if (localStorage['showOwner']) {
if (localStorage['type'] == 'pool'){
cached.ownername = photo.getAttribute('ownername');
cached.owner = photo.getAttribute('owner');
}
else {
cached.ownername = ownername;
cached.owner = owner;
}
} else { cached.ownername = 'visivo'; cached.owner = 'visio'; }

photoCache.push(cached);
localStorage["photoCache"] = JSON.stringify(photoCache);
}
}

function removeOnePhoto() {
Expand All @@ -105,5 +121,7 @@
"_b.jpg";
}

fetchSet(VISIVO_SET, fillCache);
</script>
if (TYPE=='pool') {fetchPool(SET_ID, fillCache);}
else {fetchSet(SET_ID, fillCache);}
//fetchSet(SET_ID, fillCache);
</script>
50 changes: 16 additions & 34 deletions flickrset.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
<head>
<title>New Tab</title>
<style>
#byline {
position: absolute;
bottom: 3%;
left: 3%;
}
#wrapper {
background-color: #EEE;
opacity: 0;
-webkit-transition-property: opacity;
-webkit-transition-duration: 0.8s;
padding: 0.4em;
border-radius: 6px;
font-family: sans-serif;
display: block;
}
a:link, a:visited {
color: #333;
text-decoration: none;
}
span.title {
font-size: large;
}
span.owner {
font-size: small;
}
</style>
<link rel="stylesheet" href="style.css" type="text/css" media="screen">
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="apps.js"></script>
</head>
<body>
<div id="main">
<div id="apps">Apps</div>
<div id="appsMenu"></div>
<div>&nbsp;</div>
</div>

<div id="byline">
<a href="#" id="wrapper">
</a>
Expand All @@ -42,10 +24,10 @@
document.body.style.backgroundSize = "cover";

var byline = document.getElementById("wrapper");
byline.href =
byline.href =
'http://www.flickr.com/photos/' + cached.owner + '/' + cached.id;

if (false && localStorage['showTitle']) {
if (localStorage['showTitle']) {
var title = document.createElement("span");
title.setAttribute("class", "title");
if (cached.title) {
Expand All @@ -58,8 +40,8 @@
title.innerHTML = "untitled";
}
byline.appendChild(title);

if (localStorage['showOwner']) {
if (localStorage['showOwner'] && cached.ownername) {
var owner = document.createElement("span");
owner.setAttribute("class", "owner");
var escapedOwnername = cached.ownername.replace(
Expand All @@ -75,8 +57,8 @@

window.onbeforeunload = function () {
document.body.onmousemove = null;
}

};
window.setTimeout(function () {
var mouseX = 0;
document.body.onmousemove = function (evt) {
Expand All @@ -87,7 +69,7 @@
byline.style.opacity = 0.6;
document.body.onmousemove = null;
}
}
};
}, 200);
</script>
</body>
Loading