Skip to content

Commit

Permalink
- Deal with only the active window's tabs
Browse files Browse the repository at this point in the history
- Fix remote web page
  • Loading branch information
sergi committed Feb 19, 2014
1 parent 58f30bd commit 2b2a3ed
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 31 deletions.
Binary file added data/grenade-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
1 change: 1 addition & 0 deletions data/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="pure-nr-min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Tab Grenade</title>
Expand Down
4 changes: 1 addition & 3 deletions data/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Parse.initialize("dibRma54UIQ0UYErXdDV0EPdk32AtUSEBQll0Lc7",
var tabsByTime;
var TabGroup = Parse.Object.extend("TabGroup");
var tpl = document.getElementById('link_template').innerHTML;
console.log(tpl)

document.addEventListener('click', function(e) {
var obj;
Expand All @@ -19,7 +18,6 @@ document.addEventListener('click', function(e) {
if (t.classList.contains('open_page')) {
var group = new TabGroup();
obj = tabsByTime[id];
obj.time = null;
group.set("tabs", obj);
group.save(null, {
success: function(data) {
Expand Down Expand Up @@ -60,7 +58,7 @@ self.port.on("allTabs", tabs => {
key: key,
content: tabsByTime[key],
formattedTime: formattedTime,
len: len + ( len > 1 ? ' tabs' : ' tab')
tabLen: len + ( len > 1 ? ' tabs' : ' tab')
});
}).join('');
});
Expand Down
30 changes: 17 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tab Grenade</title>

<link rel="stylesheet" type="text/css" href="data/pure-nr-min.css">
<link rel="stylesheet" type="text/css" href="data/style.css">
<title>Tab Grenade</title>

<script src="data/moment.min.js"></script>
<script src="data/mustache.js"></script>
<script src="//www.parsecdn.com/js/parse-1.2.16.min.js"></script>
<script src="data/parse-1.2.16.min.js"></script>
<script>
Parse.initialize("dibRma54UIQ0UYErXdDV0EPdk32AtUSEBQll0Lc7",
"iwP0ckwxi7g8ZVWVaJwoel61ckdoUbPPuj2OPPXR");

var timeFormat = 'MMMM Do YYYY, h:mm:ss a'
var urlId = window.location.pathname.trim()
var timeFormat = 'MMMM Do YYYY, h:mm:ss a';
var urlId = window.location.pathname.trim();
urlId = urlId.substr(1, urlId.length)
</script>
<script id="link_template" type="text/html">
<ul>
<h1>{{tabLen}}</h1>

<div class="info_block" data-id="{{key}}">
<div class="created_on">Created on {{formattedTime}}</div>
<div class="restore_all">Open all</div>
<!--<div class="delete_all">Remove all</div>-->
<div class="open_page">Share as web page</div>
</div>
{{#content}}
<li style="list-style-image: url('https://www.google.com/s2/favicons?domain={{domain}}');"><a href="{{{url}}}" target="_blank">{{title}}</a></li>
<li style="list-style-image: url('https://www.google.com/s2/favicons?domain={{domain}}');">
<a href="{{{url}}}" target="_blank">{{title}}</a>
</li>
{{/content}}
</ul>
</script>
Expand All @@ -39,12 +42,13 @@ <h1>{{tabLen}}</h1>

<div id="container"></div>
<script>
var tpl = document.getElementById('link_template').innerHTML;
var TabGroup = Parse.Object.extend("TabGroup");
var query = new Parse.Query(TabGroup);
query.get(urlId, {
success: function(gameScore) {
var tabs = gameScore.attributes.tabs
var tabsByTime = tabs.reduce((prev, curr) => {
var tabs = gameScore.attributes.tabs;
var tabsByTime = tabs.reduce(function(prev, curr) {
if (!prev[curr.time])
prev[curr.time] = [];

Expand All @@ -55,15 +59,15 @@ <h1>{{tabLen}}</h1>
return prev;
}, {});

var sortedKeys = Object.keys(tabsByTime).map(x=>parseInt(x)).sort((a, b) => {
var sortedKeys = Object.keys(tabsByTime).sort(function(a, b) {
return a - b;
}).reverse();

document.getElementById("container").innerHTML = sortedKeys.map(function(key) {
var len = tabsByTime[key].length;
var formattedTime = moment(parseInt(key)).format(timeFormat);
var a = document.createElement('a');
tabsByTime[key] = tabsByTime[key].map(t => {
tabsByTime[key] = tabsByTime[key].map(function(t) {
a.href = t.url;
t.domain = a.hostname;
return t;
Expand All @@ -73,7 +77,7 @@ <h1>{{tabLen}}</h1>
key: key,
content: tabsByTime[key],
formattedTime: formattedTime,
len: len + ( len > 1 ? ' tabs' : ' tab')
tabLen: len + ( len > 1 ? ' tabs' : ' tab')
});
}).join('');
},
Expand Down
17 changes: 6 additions & 11 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var widgets = require("sdk/widget");
var queue = require("./queue");
var storage = require("./async_storage").asyncStorage;
var tabs = require("sdk/tabs");
var windows = require("sdk/windows").browserWindows;
var self = require("sdk/self");
let { getFavicon } = require("sdk/places/favicon");

var tabs = windows.activeWindow.tabs;

if (!storage.tabsSaved) {
storage.tabsSaved = [];
Expand Down Expand Up @@ -49,19 +50,12 @@ function runScript(tab) {
inBackground: true
});
});

worker.port.on('get_favicon', function(url) {
getFavicon(url).then(function(fiUrl) {
console.log(fiUrl); // https://mozorg.cdn.mozilla.net/media/img/favicon.ico
worker.port.emit("favicon_url", [url, fiUrl]);
});
});
}

var widget = widgets.Widget({
id: 'tab-grenade',
label: 'Tab Grenade',
contentURL: self.data.url('grenade.png'),
contentURL: self.data.url('grenade-32.png'),

onClick: function() {
var time = Date.now();
Expand All @@ -74,7 +68,8 @@ var widget = widgets.Widget({
storage.setItem(time, tabsToClose.map(t => {
return {
title: t.title,
url: t.url
url: t.url,
time: time
}
}), function() {
tabs.open({
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "tabgrenade",
"license": "MPL 2.0",
"license": "MPL 2.0",
"author": "Sergi Mansilla (https://sergimansilla.com) <[email protected]>",
"version": "0.1",
"icon": "data/grenade.png",
"version": "0.4",
"icon": "data/grenade-32.png",
"fullName": "Tab Grenade",
"id": "jid1-gzlHTgBCb5hzkA",
"id": "jid1-gzlHTgBCb5hzkA",
"description": "Tab Grenade is a Firefox Browser extension that creates a persistent list of all your open tabs and then closes them all"
}

0 comments on commit 2b2a3ed

Please sign in to comment.