Skip to content

Commit

Permalink
Add 'Recent sites'
Browse files Browse the repository at this point in the history
  • Loading branch information
z------------- committed Feb 12, 2015
1 parent 6552d5f commit 12776b8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
6 changes: 4 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
"manifest_version": 2,
"name": "New New Tab Page",
"options_page": "options/options.html",
"version": "4.2.3",
"version": "4.2.4",
"short_name": "NNTP",
"permissions": [
"topSites",
"management",
"bookmarks",
"storage"
"storage",
"sessions",
"tabs"
],
"background": {
"page": "newtab.html",
Expand Down
5 changes: 4 additions & 1 deletion newtab.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
</div>
<div id="appdrawerframe">
<div id="actualdrawer">
<div class="drawersection" id="recentsites">
<div class="drawerti" id="recmostvis">Recently Closed</div>
</div>
<div class="drawersection" id="topsites">
<div class="drawerti" id="mostvis">Top Sites</div>
<div class="drawerti" id="topmostvis">Top Sites</div>
</div>
<div class="drawersection" id="applist">
<div class="drawerti">
Expand Down
25 changes: 24 additions & 1 deletion ntp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var settings = {
appIconSize: 130,
showAppsDrawer: true,
topSiteCount: 6,
recSiteCount: 3,
showBookmarks: false,
showAllBookmarks: false,
firstRun: false,
Expand Down Expand Up @@ -325,6 +326,27 @@ function main() {
document.getElementById("sidewipe").style.width = "100%";
};
}

function getRecentSites(res) {
if (recSiteCount >= 1) {
for (var i = 0; i < recSiteCount; i++) {
var recSite = res[i].tab;

console.log(recSite);
var recentSitesList = document.getElementById("recentsites");

var recSiteElem = document.createElement("a");
recSiteElem.href = recSite.url;
recSiteElem.innerHTML = "<div class='draweritem topsite' id='l" + i + "'>" + recSite.title + "</div>";

recSiteElem.querySelector("div").style.backgroundImage = "url(" + recSite.favIconUrl + ")";

recentSitesList.appendChild(recSiteElem);
}
} else {
document.getElementById("recmostvis").style.display = "none";
}
}

function getTopSites(res) {
if (topSiteCount >= 1) {
Expand All @@ -333,7 +355,7 @@ function main() {
document.getElementById("l" + i).style.backgroundImage = "url(http://www.google.com/s2/favicons?domain=" + res[i].url.getDomain() + ")";
}
} else {
document.getElementById("mostvis").style.display = "none";
document.getElementById("topmostvis").style.display = "none";
}
}

Expand Down Expand Up @@ -391,6 +413,7 @@ function main() {

if (showAppsDrawer) {
chrome.topSites.get(getTopSites);
chrome.sessions.getRecentlyClosed(getRecentSites);
chrome.management.getAll(getApps);
document.getElementById("appsicon").style.display = "block";
document.getElementById("appsicon").onclick = function () {
Expand Down
3 changes: 3 additions & 0 deletions options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ <h2>Background</h2>

<section>
<h2>Bookmarks & App Drawer</h2>
<label>No. of recently closed sites
<input type="number" id="recsitecount" min="0" max="20">
</label>
<label>No. of top sites
<input type="number" id="topsitecount" min="0" max="20">
</label>
Expand Down
5 changes: 5 additions & 0 deletions options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var defaultSettings = {
slotCount: 3,
showAppsDrawer: true,
topSiteCount: 6,
recSiteCount: 3,
showBookmarks: false,
showAllBookmarks: false,
firstRun: false,
Expand Down Expand Up @@ -341,6 +342,9 @@ chrome.storage.sync.get(null, function (sr) {
readOption("topSiteCount", function (val) {
document.getElementById("topsitecount").value = val;
});
readOption("recSiteCount", function (val) {
document.getElementById("recsitecount").value = val;
});
readOption("showAllBookmarks", function (val) {
document.getElementById("showallbookmarks").checked = val;
});
Expand Down Expand Up @@ -384,6 +388,7 @@ document.getElementById("save").onclick = function () {
newSettings.showFBNotif = document.getElementById("shownotif").checked;
newSettings.showBookmarks = document.getElementById("showbookmarks").checked;
newSettings.topSiteCount = Number(document.getElementById("topsitecount").value);
newSettings.recSiteCount = Number(document.getElementById("recsitecount").value);
newSettings.showStumble = document.getElementById("showstumble").checked;
newSettings.showAllBookmarks = document.getElementById("showallbookmarks").checked;
newSettings.bgBlur = document.getElementById("bgblur").checked;
Expand Down

0 comments on commit 12776b8

Please sign in to comment.