This repository has been archived by the owner on Apr 4, 2021. 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.
- Loading branch information
0 parents
commit 703e025
Showing
27 changed files
with
4,184 additions
and
0 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,5 @@ | ||
{ | ||
"presets": [ | ||
"es2015" | ||
] | ||
} |
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,35 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Dependency directory | ||
node_modules | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
build/ | ||
|
||
.DS_Store | ||
.idea |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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,28 @@ | ||
const INITIATE_TRACKING = (orginalAction) => (dispatch) => { | ||
|
||
const query = {currentWindow: true, active: true} | ||
|
||
console.log('INITIATE_TRACKING') | ||
|
||
chrome.tabs.query(query, (tabs) => { | ||
|
||
console.log('tabs', tabs) | ||
|
||
if (tabs.length !== 1) { | ||
console.error('tabs.length !== 1', tabs.length) | ||
} | ||
|
||
dispatch({ | ||
type: 'START_TRACKING', | ||
tab: tabs[0] | ||
}) | ||
}) | ||
|
||
return { | ||
type: 'INITIATE_TRACKING', | ||
}; | ||
} | ||
|
||
export default { | ||
INITIATE_TRACKING | ||
} |
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,119 @@ | ||
import {createStore, applyMiddleware} from 'redux' | ||
import thunk from 'redux-thunk'; | ||
import {wrapStore, alias} from 'react-chrome-redux' | ||
|
||
import rootReducer from './reducers' | ||
import aliases from './aliases'; | ||
|
||
|
||
const middlewares = [ | ||
alias(aliases), | ||
thunk | ||
]; | ||
|
||
const store = createStore(rootReducer, applyMiddleware(...middlewares)) | ||
|
||
wrapStore(store, { | ||
portName: 'port-6tbx4n2UxrcL' | ||
}) | ||
|
||
const TIME_LIMIT = 10 | ||
|
||
function tabLoadedAction(tabId, changeInfo, tab) { | ||
const lastActiveItem = store.getState()['activeItem'] | ||
const tracking = store.getState()['tracking'] | ||
|
||
return { | ||
type: 'TAB_LOADED', | ||
tabId, | ||
changeInfo, | ||
tab, | ||
lastActiveItem, | ||
tracking, | ||
now: new Date() | ||
}; | ||
} | ||
|
||
function timeUpAction() { | ||
const lastActiveItem = store.getState()['activeItem'] | ||
|
||
const myAudio = new Audio() | ||
myAudio.src = "solemn.mp3" | ||
myAudio.play() | ||
|
||
return { | ||
type: 'TIME_UP', | ||
lastActiveItem, | ||
now: new Date() | ||
}; | ||
} | ||
|
||
|
||
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { | ||
// See https://developer.chrome.com/extensions/tabs#event-onUpdated | ||
|
||
if (changeInfo.status !== 'complete') { | ||
return | ||
} | ||
|
||
store.dispatch(tabLoadedAction(tabId, changeInfo, tab)) | ||
} | ||
) | ||
|
||
chrome.tabs.onActivated.addListener(({tabId, windowId}) => { | ||
// console.log("onActivated", {tabId, windowId}) | ||
store.dispatch({ | ||
type: 'TAB_ACTIVATED', | ||
tabId, | ||
windowId, | ||
}) | ||
|
||
}) | ||
|
||
store.subscribe(function updateIconOnStateChange() { | ||
const {tracking, currentTab} = store.getState(); | ||
|
||
const path = ( | ||
tracking && | ||
currentTab.tabId === tracking.tabId && | ||
currentTab.windowId === tracking.windowId | ||
? 'purple.png' | ||
: 'grey.png' | ||
) | ||
|
||
chrome.browserAction.setIcon({path}) | ||
}) | ||
|
||
function updateBadge() { | ||
const {activeItem, inboxItems} = store.getState() | ||
const now = new Date() | ||
|
||
if (!activeItem) { | ||
return | ||
} | ||
const {url, loadedAt} = activeItem | ||
|
||
if (!inboxItems[url]) { | ||
return | ||
} | ||
const secondsSpentBefore = inboxItems[url].secondsSpent | ||
const secondsSpentNow = Math.round((now.getTime() - loadedAt.getTime()) / 1000) | ||
|
||
|
||
const timeSpent = (secondsSpentBefore + secondsSpentNow); | ||
let badgeText = (timeSpent).toString() + "s" | ||
chrome.browserAction.setBadgeText({text: badgeText}) | ||
|
||
if (TIME_LIMIT <= timeSpent) { | ||
chrome.browserAction.setBadgeBackgroundColor({color: 'red'}) | ||
} else { | ||
chrome.browserAction.setBadgeBackgroundColor({color: 'green'}) | ||
} | ||
|
||
|
||
if (TIME_LIMIT <= timeSpent && timeSpent < TIME_LIMIT + 1) { | ||
store.dispatch(timeUpAction()) | ||
} | ||
|
||
} | ||
setInterval(updateBadge, 1000) |
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 @@ | ||
const initialState = null; | ||
|
||
export default (state = initialState, action) => { | ||
switch (action.type) { | ||
case 'TAB_LOADED': | ||
let {tabId, changeInfo, tracking, tab, now} = action | ||
|
||
if (tracking && tracking.tabId === tab.id) { | ||
// only care about URL changes from the tracked tab | ||
let {url, title} = tab | ||
|
||
state = { | ||
loadedAt: now, | ||
url | ||
} | ||
} | ||
|
||
return state; | ||
default: | ||
return state; | ||
} | ||
}; |
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,20 @@ | ||
const initialState = false; | ||
|
||
export default (state = initialState, action) => { | ||
switch (action.type) { | ||
case 'START_TRACKING': | ||
return { | ||
tabId: action.tab.id, | ||
windowId: action.tab.windowId, | ||
}; | ||
|
||
case 'TAB_ACTIVATED': | ||
return { | ||
tabId: action.tabId, | ||
windowId: action.windowId, | ||
}; | ||
|
||
default: | ||
return state; | ||
} | ||
}; |
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,67 @@ | ||
const initialState = {} | ||
const inboxItemDefaultState = {title: 'UNKNOWN', secondsSpent: 0} | ||
|
||
function initializeInboxItemOnFirstOccurrence(state, url, title) { | ||
if (!state[url]) { | ||
state = { | ||
...state, | ||
[url]: { | ||
...inboxItemDefaultState, | ||
title, | ||
}, | ||
} | ||
} | ||
return state; | ||
} | ||
|
||
export default (state = initialState, action) => { | ||
switch (action.type) { | ||
case 'START_TRACKING': { | ||
const {url, title} = action.tab | ||
|
||
state = initializeInboxItemOnFirstOccurrence(state, url, title); | ||
|
||
return state; | ||
} | ||
|
||
case 'TAB_LOADED': { | ||
const {tabId, changeInfo, tab, now, tracking, lastActiveItem:blurredItemInfo} = action | ||
const {url, title} = tab | ||
|
||
console.log('TAB_LOADED', {url, title}) | ||
|
||
state = initializeInboxItemOnFirstOccurrence(state, url, title); | ||
|
||
if (tracking && tracking.tabId === tab.id) { | ||
|
||
if (blurredItemInfo) { | ||
const blurredUrl = blurredItemInfo.url | ||
|
||
state = { | ||
...state, | ||
[blurredUrl]: blurredInboxItem(state[blurredUrl], blurredItemInfo, now), | ||
} | ||
} | ||
|
||
console.log('state', state) | ||
} else { | ||
//console.log('ignored TAB_LOADED from non-tracked tab') | ||
} | ||
return state | ||
} | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
function blurredInboxItem(state, blurredItemInfo, now) { | ||
const blurredWasLoadedAt = blurredItemInfo.loadedAt | ||
|
||
const secondsSpent = Math.round((now.getTime() - blurredWasLoadedAt.getTime()) / 1000) | ||
const prevInboxItem = state || inboxItemDefaultState | ||
|
||
return { | ||
...prevInboxItem, | ||
secondsSpent: prevInboxItem.secondsSpent + secondsSpent, | ||
} | ||
} |
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 @@ | ||
import {combineReducers} from 'redux'; | ||
|
||
import inboxItems from './inboxItems'; | ||
import activeItem from './activeItem'; | ||
import tracking from './tracking'; | ||
import currentTab from './currentTab'; | ||
|
||
export default combineReducers({ | ||
inboxItems, | ||
activeItem, | ||
tracking, | ||
currentTab | ||
}); | ||
|
||
// | ||
// export default (state = {}, action) => { | ||
// | ||
// return { | ||
// activeItem: activeItem(state.activeItem, action), | ||
// inboxItems: inboxItems(state.inboxItems, action), | ||
// } | ||
// } |
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,21 @@ | ||
const initialState = false; | ||
|
||
export default (state = initialState, action) => { | ||
switch (action.type) { | ||
case 'START_TRACKING': | ||
console.log('START_TRACKING') | ||
|
||
return { | ||
tabId: action.tab.id, | ||
windowId: action.tab.windowId, | ||
}; | ||
|
||
case 'STOP_TRACKING': | ||
|
||
console.log('STOP_TRACKING') | ||
|
||
return false; | ||
default: | ||
return state; | ||
} | ||
}; |
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,33 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
|
||
entry: [ | ||
'./event/src/index.js' | ||
], | ||
|
||
output: { | ||
filename: 'event.js', | ||
path: path.join(__dirname, '../', 'build') | ||
}, | ||
|
||
resolve: { | ||
extensions: ['', '.js', '.json'], | ||
modulesDirectories: ['node_modules'] | ||
}, | ||
|
||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.(js)?$/, | ||
loader: 'babel', | ||
exclude: /(node_modules)/, | ||
include: path.join(__dirname, 'src'), | ||
query: { | ||
presets: ['es2015', 'react'], | ||
plugins: ['transform-object-rest-spread'] | ||
} | ||
} | ||
] | ||
} | ||
}; |
Oops, something went wrong.