Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mugi-uno committed Oct 1, 2017
0 parents commit 98734b7
Show file tree
Hide file tree
Showing 127 changed files with 7,397 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"env", "stage-2"
]
}
13 changes: 13 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "semistandard",
"env": { "es6": true },
"plugins": ["import"],
"globals": {
"chrome": false,
"document": false
},
"rules": {
"comma-dangle": ["error", "always-multiline"],
"space-before-function-paren": ["error", "never"]
}
}
78 changes: 78 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
### https://raw.github.com/github/gitignore/0f88fa75def7ed7d96935b8630793e51953df9b0/node.gitignore

# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz


### https://raw.github.com/github/gitignore/0f88fa75def7ed7d96935b8630793e51953df9b0/Global/macos.gitignore

*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

build/
2 changes: 2 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import init from './lib/background/init';
init();
2 changes: 2 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import init from './lib/content/init';
init();
5 changes: 5 additions & 0 deletions devtools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
chrome.devtools.panels.create(
'nezumi',
'',
'panel.html'
);
2 changes: 2 additions & 0 deletions dist/background.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/background.js.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions dist/content.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/content.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions dist/devtools.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!doctype html>
<html>
<body>
<script src='./devtools.js'></script>
</body>
</html>
2 changes: 2 additions & 0 deletions dist/devtools.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/devtools.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added dist/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions dist/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"manifest_version": 2,
"name": "nezumi",
"description": "Test code generator for Capybara/RSpec.",
"version": "1.0",
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"devtools_page": "devtools.html",
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["file://*/*", "http://*/*", "https://*/*"],
"js": ["content.js"],
"run_at": "document_start"
}
],
"permissions": [
"tabs"
]
}
4 changes: 4 additions & 0 deletions dist/panel.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#container {
min-width: 300px;
min-height: 300px;
}
7 changes: 7 additions & 0 deletions dist/panel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!doctype html>
<html>
<body>
<div id="app"></div>
<script src='./panel.js'></script>
</body>
</html>
12 changes: 12 additions & 0 deletions dist/panel.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/panel.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/background/emitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { EventEmitter } from 'events';
export const emitter = new EventEmitter();
52 changes: 52 additions & 0 deletions lib/background/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { emitter } from './emitter';

export default function() {
connectToDevtool();
connectToContent();
}

const connectToDevtool = () => {
chrome.runtime.onConnect.addListener((port) => {
if (port.name !== 'devtool') return;

console.log('background <--> devtool connected.');

const sendToDevtool = (store) => {
console.log('background -> devtool', store);
port.postMessage(store);
};
emitter.on('devtool.send', sendToDevtool);
port.onDisconnect.addListener(() => emitter.removeListener('devtool.send', sendToDevtool));

port.onMessage.addListener((msg) => {
console.log('devtool -> background', msg);
emitter.emit('devtool.receive', msg);
});

// pass to content
port.onMessage.addListener((msg) => emitter.emit('content.send', Object.assign({ location: 'devtool' }, msg || {})));
});
};

const connectToContent = () => {
chrome.runtime.onConnect.addListener((port) => {
if (port.name !== 'content') return;

console.log('background <--> content connected.');

const sendToContent = (store) => {
console.log('background -> content', store);
port.postMessage(store);
};
emitter.on('content.send', sendToContent);
port.onDisconnect.addListener(() => emitter.removeListener('content.send', sendToContent));

port.onMessage.addListener((msg) => {
console.log('content -> background', msg);
emitter.emit('content.receive', msg);
});

// pass to devtool
port.onMessage.addListener((msg) => emitter.emit('devtool.send', Object.assign({ location: 'content' }, msg || {})));
});
};
2 changes: 2 additions & 0 deletions lib/content/emitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { EventEmitter } from 'events';
export const emitter = new EventEmitter();
48 changes: 48 additions & 0 deletions lib/content/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { emitter } from './emitter';
import { watcher } from './watcher/Watcher';
import * as devtoolMutationTypes from '../panel/store/mutation-types';

const devtoolHandler = (msg) => {
switch (msg.type) {
case devtoolMutationTypes.PANEL_TOGGLE_WATCHING:
watcher.toggle(msg.payload);
break;
default:
// nothing to do;
}
};

const backgroundHandler = (msg) => {
// nothing to do.
};

export default function() {
emitter.on('background.receive', (msg) => {
switch (msg.location) {
case 'devtool':
devtoolHandler(msg);
break;
case 'background':
backgroundHandler(msg);
break;
default:
// nothing to do.
}
});

document.addEventListener('DOMContentLoaded', () => {
const port = chrome.runtime.connect({name: 'content'});

const sendToBackground = (store) => {
console.log('content -> background', store);
port.postMessage(store);
};
emitter.on('background.send', sendToBackground);
port.onDisconnect.addListener(() => emitter.removeListener('background.send', sendToBackground));

port.onMessage.addListener((msg) => {
console.log('background -> content', msg);
emitter.emit('background.receive', msg);
});
});
}
35 changes: 35 additions & 0 deletions lib/content/watcher/Watcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import _ from 'lodash';
import events from './events';

class Watcher {
constructor() {
this.watching = false;
this.events = _.map(events, EventClass => new EventClass());
}

on() {
if (this.watching) return;
this.watching = true;
this.events.forEach(e => e.on());

console.log('[🐭nezumi] 👀watching start.');
}

off() {
this.watching = false;
this.events.forEach(e => e.off());

console.log('[🐭nezumi] 💤watching stop.');
}

toggle(newWatchingValue = !this.watching) {
if (newWatchingValue) {
this.on();
} else {
this.off();
}
}
}

// export singleton watcher
export const watcher = new Watcher();
28 changes: 28 additions & 0 deletions lib/content/watcher/events/Base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import $ from 'jquery';

import { emitter } from '../../emitter';
import { analyze } from '../utils/analyze';

export default class Base {
hundler = (e) => {
const analyzeResult = analyze(e.originalEvent.target);
const eventName = this.eventName();

emitter.emit('background.send', {
type: 'fire',
value: Object.assign({ event: eventName }, analyzeResult),
});
}

on() {
$(document).on(this.eventName(), this.hundler);
}

off() {
$(document).off(this.eventName(), this.hundler);
}

eventName() {
return '';
}
}
7 changes: 7 additions & 0 deletions lib/content/watcher/events/Change.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Base from './Base';

export default class Change extends Base {
eventName() {
return 'change';
}
}
7 changes: 7 additions & 0 deletions lib/content/watcher/events/Click.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Base from './Base';

export default class Click extends Base {
eventName() {
return 'click';
}
}
7 changes: 7 additions & 0 deletions lib/content/watcher/events/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Change from './Change';
import Click from './Click';

export default {
Change,
Click,
};
Loading

0 comments on commit 98734b7

Please sign in to comment.