This repository has been archived by the owner on Oct 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from grooves/master
Release 1.0.4
- Loading branch information
Showing
26 changed files
with
275 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[![wercker status](https://app.wercker.com/status/77b18717dfdfc349ba494ba51dcf8d6e/s "wercker status")](https://app.wercker.com/project/bykey/77b18717dfdfc349ba494ba51dcf8d6e) | ||
[![Coverage Status](https://coveralls.io/repos/grooves/forkwell_for_chrome/badge.svg?branch=master)](https://coveralls.io/r/grooves/forkwell_for_chrome?branch=master) | ||
|
||
# forkwell_for_chrome | ||
|
||
Chrome extention for Forkwell Jobs. If you access a web site managed a company published Forkwell Jobs, this extention shows its job posting. | ||
|
||
## Setup | ||
|
||
### create extention | ||
|
||
you need to install `nodejs` for using `npm`. | ||
|
||
``` | ||
$ npm install -g gulp | ||
$ cd ${PROJECT_ROOT} | ||
$ gulp | ||
# => create `dist` directory | ||
``` | ||
|
||
## Install | ||
|
||
### production | ||
|
||
TODO: write chrome web store url | ||
|
||
### development | ||
|
||
Drag and drop `${PROJECT_ROOT}/dist` directroy into `chrome://extensions/` page. | ||
|
||
## Contributing | ||
|
||
If you have a problem, please create an issue or a pull request. | ||
|
||
1. Fork it | ||
1. Create your feature branch (git checkout -b my-new-feature) | ||
1. Commit your changes (git commit -am 'Add some feature') | ||
1. Push to the branch (git push origin my-new-feature) | ||
1. Create new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,4 @@ | ||
fetchFromForkwellJobs = -> | ||
host = 'https://jobs.forkwell.com' | ||
url = "#{host}/api/v1/chrome/services.json" | ||
$.getJSON url, (json) -> | ||
chrome.storage.local.set json | ||
global.$ = require 'jquery' | ||
|
||
updatePopupByUrl = (url) -> | ||
chrome.storage.local.get 'services', (items) -> | ||
origin = $('<a>', href: url)[0].origin | ||
jobs = items.services[origin] | ||
if jobs | ||
chrome.storage.local.set | ||
popup: jobs | ||
chrome.browserAction.setBadgeText | ||
text: "#{jobs.length}" | ||
else | ||
chrome.storage.local.set | ||
popup: null | ||
chrome.browserAction.setBadgeText | ||
text: '' | ||
|
||
fetchFromForkwellJobs() | ||
|
||
setInterval fetchFromForkwellJobs, 1000 * 60 * 60 * 24 | ||
|
||
chrome.tabs.onActivated.addListener (activeInfo) -> | ||
chrome.tabs.get activeInfo.tabId, (tab) -> | ||
updatePopupByUrl tab.url | ||
BackgroundView = require './views/background_view' | ||
new BackgroundView().render() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Popup | ||
fetchJobs: (callback) -> | ||
chrome.storage.local.get 'popup', (items) -> | ||
callback items.popup | ||
|
||
setJobs: (jobs) -> | ||
if jobs | ||
@jobs = jobs | ||
@badgeText = "#{jobs.length}" | ||
else | ||
@jobs = null | ||
@badgeText = '' | ||
|
||
chrome.storage.local.set popup: @jobs | ||
chrome.browserAction.setBadgeText text: @badgeText | ||
|
||
module.exports = Popup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Service | ||
@fetch: -> | ||
host = 'https://jobs.forkwell.com' | ||
url = "#{host}/api/v1/chrome/services.json" | ||
$.getJSON url, (json) -> | ||
chrome.storage.local.set json | ||
|
||
@findJobsByUrl: (url, callback) -> | ||
chrome.storage.local.get 'services', (items) => | ||
jobs = items.services[@getOrigin(url)] | ||
callback jobs | ||
|
||
@getOrigin: (url) -> | ||
$('<a>', href: url)[0].origin | ||
|
||
module.exports = Service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
global.$ = global.jQuery = require 'jquery' | ||
global._ = require 'underscore' | ||
require 'bootstrap' | ||
|
||
$ -> | ||
chrome.storage.local.get 'popup', (items) -> | ||
if items.popup | ||
for job in items.popup | ||
$('#jobs').append new JobView(job).render().el | ||
else | ||
$('#jobs').append new NotFoundView().render().el | ||
PopupView = require './views/popup_view' | ||
new PopupView().render() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Service = require '../models/service' | ||
Popup = require '../models/popup' | ||
|
||
class BackgroundView | ||
INTERVAL_TIME = 1000 * 60 * 60 * 24 | ||
|
||
render: -> | ||
Service.fetch() | ||
setInterval (-> Service.fetch()), INTERVAL_TIME | ||
|
||
chrome.tabs.onActivated.addListener (activeInfo) -> | ||
chrome.tabs.get activeInfo.tabId, (tab) -> | ||
Service.findJobsByUrl tab.url, (jobs) -> | ||
popup = new Popup() | ||
popup.setJobs jobs | ||
|
||
chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) -> | ||
Service.findJobsByUrl tab.url, (jobs) -> | ||
popup = new Popup() | ||
popup.setJobs jobs | ||
|
||
module.exports = BackgroundView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ class JobView | |
render: -> | ||
@el.html(compiled @json) | ||
@ | ||
|
||
module.exports = JobView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ class NotFoundView | |
render: -> | ||
@el.html(compiled()) | ||
@ | ||
|
||
module.exports = NotFoundView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
JobView = require './job_view' | ||
NotFoundView = require './not_found_view' | ||
Popup = require '../models/popup' | ||
|
||
class PopupView | ||
render: -> | ||
popup = new Popup() | ||
popup.fetchJobs (jobs) -> | ||
if jobs | ||
for job in jobs | ||
$('#jobs').append new JobView(job).render().el | ||
else | ||
$('#jobs').append new NotFoundView().render().el | ||
|
||
module.exports = PopupView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
global.assert = require 'power-assert' | ||
global.sinon = require 'sinon' | ||
global.context = describe | ||
|
||
global.$ = require('jquery')(require('jsdom').jsdom().parentWindow) | ||
global._ = require 'underscore' | ||
|
||
global.chrome = | ||
storage: | ||
local: | ||
set: -> | ||
get: -> | ||
browserAction: | ||
setBadgeText: -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'test/helper' | ||
Popup = require 'src/coffee/models/popup' | ||
|
||
describe 'Popup', -> | ||
describe '#setJobs', -> | ||
popup = null | ||
|
||
beforeEach -> | ||
sinon.spy chrome.storage.local, 'set' | ||
sinon.spy chrome.browserAction, 'setBadgeText' | ||
popup = new Popup() | ||
afterEach -> | ||
chrome.storage.local.set.restore() | ||
chrome.browserAction.setBadgeText.restore() | ||
|
||
context 'when args have a job', -> | ||
jobs = [{title: 'title'}] | ||
|
||
beforeEach -> popup.setJobs(jobs) | ||
|
||
it 'should update jobs and badgeText', -> | ||
assert popup.jobs is jobs | ||
assert popup.badgeText is '1' | ||
|
||
it 'should update storage to jobs', -> | ||
assert chrome.storage.local.set.args[0][0].popup is jobs | ||
|
||
it 'should update badgeText to "1"', -> | ||
assert chrome.browserAction.setBadgeText.args[0][0].text is '1' | ||
|
||
context 'when args is undefined', -> | ||
beforeEach -> popup.setJobs undefined | ||
|
||
it 'should update jobs to null, and badgeText to ""', -> | ||
assert popup.jobs is null | ||
assert popup.badgeText is '' | ||
|
||
it 'should update storage to null', -> | ||
assert chrome.storage.local.set.args[0][0].popup is null | ||
|
||
it 'should update badgeText to ""', -> | ||
assert chrome.browserAction.setBadgeText.args[0][0].text is '' |
Oops, something went wrong.