Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
andreloureiro committed Aug 28, 2015
1 parent 04d2995 commit b327d0e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 12 deletions.
7 changes: 6 additions & 1 deletion gulpfile.js
Expand Up @@ -45,6 +45,11 @@ gulp.task('manifest', function() {
.pipe(gulp.dest('dist'));
});

gulp.task('contentJS', function() {
gulp.src(['src/content.js'])
.pipe(gulp.dest('dist'));
})

gulp.task('clean', function() {
gulp.src('dist')
.pipe(clean());
Expand All @@ -55,4 +60,4 @@ gulp.task('watch', function() {
gulp.watch(['src/**/*.js'], ['js']);
});

gulp.task('default', ['js', 'html', 'images', 'manifest', 'connect', 'watch']);
gulp.task('default', ['js', 'html', 'images', 'manifest', 'contentJS', 'connect', 'watch']);
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -34,6 +34,7 @@
},
"dependencies": {
"angular": "^1.4.4",
"angular-ui-router": "^0.2.15"
"angular-ui-router": "^0.2.15",
"lockr": "^0.8.2"
}
}
18 changes: 17 additions & 1 deletion src/app/components/main.js
Expand Up @@ -9,10 +9,13 @@ const MainComponent = () => {
bindToController: true,
scope: {},
template: `
<p ng-click="main.chromeTab()">chrome tab</p>
<h1>{{ main.title }}</h1>
<input type="text" ng-keyup="main.handleInputKeyup($event)" autofocus />
<ul>
<li ng-repeat="item in main.list">{{ item.label }}</li>
<li ng-repeat="item in main.list">{{ item.label }} -
<span ng-click="main.handleRemove(item.id)">x</span>
</li>
</ul>
<a ui-sref="settings">settings</a>
`
Expand All @@ -30,6 +33,19 @@ class MainController {
event.target.value = '';
}
}
this.handleRemove = id => {
WebmarklyService.remove(id);
this.list = WebmarklyService.list;
}

this.chromeTab = function() {
function showDOM(content) {
alert(content);
}
window.chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.sendMessage(tab.id, 'CALLED', showDOM)
})
}
}
}
MainController.$inject = ['$scope', 'WebmarklyService'];
Expand Down
33 changes: 24 additions & 9 deletions src/app/services/webmarkly.js
@@ -1,34 +1,49 @@
import angular from 'angular';

const STORAGE_LOCALSTORAGE = window.localStorage || null;
const STORAGE_EXTENSION = chrome.storage.sync || null;

const appStorage = STORAGE_LOCALSTORAGE;
import * as store from 'lockr';

class WebmarklyService {
constructor() {
this.list = [];
this.__domain = window.location.href;
this.__initialize();
}

__initialize() {
if (!!store.get('items_' + this.__domain)) {
this.__updateList();
} else {
store.set('items_' + this.__domain, []);
}
}

__updateList() {
this.list = store.get('items_' + this.__domain);
}

getAll() {
return this.list;
this.__updateList();
}

getAllByDomain(domain) {
return this.list.filter(item => item.domain == domain);
}

add(text) {
this.list.unshift({
let itemsArr = store.get('items_' + this.__domain);
itemsArr.unshift({
id: Date.now().toString(36),
label: text,
position: window.scrollY,
domain: window.location.href
});
store.set('items_' + this.__domain, itemsArr);
this.__updateList();
}

remove(id) {
this.list = this.list.filter(item => item.id != id);
let itemsArr = store.get('items_' + this.__domain);
itemsArr = itemsArr.filter(item => item.id != id);
store.set('items_' + this.__domain, itemsArr);
this.__updateList();
}

}
Expand Down
4 changes: 4 additions & 0 deletions src/content.js
@@ -0,0 +1,4 @@
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
console.log(msg);
sendResponse(document.all[0].outerHTML);
});
10 changes: 10 additions & 0 deletions src/manifest.json
Expand Up @@ -10,6 +10,16 @@
"default_popup": "index.html"
},

"background": {
"persistent": false,
"scripts": ["js/bundle.js"]
},

"content_scripts": [{
"matches": ["*://*/*"],
"js": ["content.js"]
}],

"permissions": [
"activeTab",
"storage"
Expand Down

0 comments on commit b327d0e

Please sign in to comment.