Skip to content

Commit f69d3c9

Browse files
committed
Version 0.0.1
- Safari like new tab page - Icons from mat/besticon
0 parents  commit f69d3c9

13 files changed

+205
-0
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"react"
4+
]
5+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/*
2+
*.xpi

.jpmignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.git/
2+
.gitignore
3+
.DS_Store
4+
.jpmignore
5+
node_modules/
6+
app/
7+
.babelrc
8+
manifest.json
9+
*.xpi

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#React New Tab
2+
New tab extension built using react

app/bookmarks.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var React = require('react');
2+
var ReactDOM = require('react-dom');
3+
// var fetchFavicon = require('@meltwater/fetch-favicon').fetchFavicon
4+
5+
var ListView = React.createClass({
6+
render: function() {
7+
var bks = this.props.bookmarks;
8+
console.log(bks);
9+
var items = (bks.map(function(b) {
10+
console.log(b);
11+
if(b.url != undefined){
12+
return (<div className='col-xs-4 col-sm-3 col-md-2 col-lg-2' style={{paddingTop: '1%', paddingBottom: '1%' }}><Bookmark title={b.title} url={b.url} /></div>);
13+
}
14+
}));
15+
16+
return (<div className=''> {items} </div>);
17+
}
18+
});
19+
20+
var Bookmark = React.createClass({
21+
render: function () {
22+
return (
23+
<a href={this.props.url} className='btn btn-block'>
24+
<Favicon url={this.props.url} />
25+
<p style={{overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'no-wrap'}}>{this.props.title}</p>
26+
</a>
27+
);
28+
}
29+
});
30+
31+
var Favicon = React.createClass({
32+
render: function () {
33+
var url = "https://icons.better-idea.org/icon?size=64&url=" + this.props.url;
34+
return (
35+
<span>
36+
<img src={url} id={url} width="128" height="128" className="img-thumbnail"/></span>
37+
);
38+
}
39+
});
40+
41+
self.port.emit("get_bookmarks");
42+
self.port.on("bookmarks", function(bookmarks){
43+
ReactDOM.render(<ListView bookmarks={bookmarks} />, document.getElementById('app'));
44+
});

app/css/bootstrap.min.css

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<meta http-equiv="Cache-control" content="public">
3+
<head>
4+
<link rel="stylesheet" href="css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
5+
</head>
6+
<body>
7+
<div class = 'container' id = 'app'></div>
8+
</body>
9+
</html>

data/bookmarks.js

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data/css/bootstrap.min.css

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<meta http-equiv="Cache-control" content="public">
3+
<head>
4+
<link rel="stylesheet" href="css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
5+
</head>
6+
<body>
7+
<div class = 'container' id = 'app'></div>
8+
<script type="text/javascript" src="bookmarks.js"></script></body>
9+
</html>

index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var self = require('sdk/self');
2+
var tabs = require("sdk/tabs");
3+
var mod = require("sdk/page-mod");
4+
const ntp = require('resource:///modules/NewTabURL.jsm');
5+
6+
ntp.NewTabURL.override(self.data.url("index.html"));
7+
mod.PageMod({
8+
include: [self.data.url("index.html")],
9+
contentScriptFile: self.data.url("bookmarks.js"),
10+
onAttach: startListening
11+
});
12+
13+
function startListening(worker_listen){
14+
worker_listen.port.on("get_bookmarks", function () {
15+
let { search, TOOLBAR } = require("sdk/places/bookmarks");
16+
search(
17+
[{ query: "", group: TOOLBAR }]
18+
).on("end", function (item) {
19+
worker_listen.port.emit("bookmarks", item);
20+
});
21+
});
22+
23+
worker_listen.port.on("getFavicon", function(url){
24+
var img_id = url;
25+
console.log(img_id);
26+
let { getFavicon } = require("sdk/places/favicon");
27+
getFavicon(url).then(function(favicon_url){
28+
console.log("-----"+img_id+"-----");
29+
worker_listen.port.emit("favicon", favicon_url, img_id);
30+
}).catch(function(error){
31+
console.log(error);
32+
favicon_url = self.data.url("img/default.png");
33+
worker_listen.port.emit("favicon", favicon_url, img_id);
34+
})
35+
});
36+
}
37+
38+
// chrome.bookmarks.getSubTree('0', function(bookmarks){
39+
// console.log(bookmarks);
40+
// // ReactDOM.render(<ListView bookmarks={bookmarks} />, document.getElementById('app'));
41+
// });
42+

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"title": "React New Tab",
3+
"name": "react-new-tab-firefox",
4+
"version": "0.0.1",
5+
"description": "New tab extension built using react",
6+
"main": "index.js",
7+
"author": "Ramkumar",
8+
"engines": {
9+
"firefox": ">=38.0a1",
10+
"fennec": ">=38.0a1"
11+
},
12+
"license": "MIT",
13+
"keywords": [
14+
"jetpack"
15+
],
16+
"dependencies": {
17+
"react": "^15.3.2",
18+
"react-dom": "^15.3.2"
19+
},
20+
"devDependencies": {
21+
"babel-core": "^6.18.0",
22+
"babel-loader": "^6.2.7",
23+
"babel-preset-react": "^6.16.0",
24+
"html-webpack-plugin": "^2.24.0",
25+
"webpack": "^1.13.3"
26+
}
27+
}

webpack.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var HtmlWebpackPlugin = require('html-webpack-plugin');
2+
var HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
3+
template: __dirname + '/app/index.html',
4+
filename: __dirname + '/data/index.html',
5+
inject: 'body'
6+
});
7+
8+
9+
module.exports = {
10+
entry: [
11+
'./app/bookmarks.js'
12+
],
13+
output: {
14+
path: __dirname + '/data',
15+
filename: 'bookmarks.js'
16+
},
17+
module: {
18+
loaders: [
19+
{test: /\.js$/, exclude: /node_modules/, loader: "babel-loader"}
20+
]
21+
},
22+
plugins: [HtmlWebpackPluginConfig]
23+
}

0 commit comments

Comments
 (0)