├── .gitignore ├── LICENSE ├── README.md ├── lib ├── atomic-chrome.coffee └── ws-handler.coffee └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | npm-debug.log 2 | node_modules 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Daniel Perez 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Atomic Chrome 2 | 3 | ## Use Atom to edit in Chrome 4 | 5 | ![atom-icon](https://cloud.githubusercontent.com/assets/1436271/12668235/c228c514-c697-11e5-8cea-e71acabcd300.png) 6 | ![plus-icon](https://cloud.githubusercontent.com/assets/1436271/12668237/c23ab44a-c697-11e5-9076-50b70a1c3be7.png) 7 | ![chrome-icon](https://cloud.githubusercontent.com/assets/1436271/12668236/c233a4c0-c697-11e5-8bba-882291db3f65.png) 8 | 9 | ## Screencast 10 | 11 | ### GitHub issue (textarea) 12 | 13 | ![github](https://cloud.githubusercontent.com/assets/1436271/12668227/afee6a52-c697-11e5-9b19-c880a0e54132.gif) 14 | 15 | ### Gmail (contenteditable) 16 | 17 | ![gmail](https://cloud.githubusercontent.com/assets/1436271/12668226/afe32e26-c697-11e5-9814-2158e665f774.gif) 18 | 19 | ## Installation 20 | 21 | You need to install 22 | 23 | * [The Chrome Plugin](https://chrome.google.com/webstore/detail/atomic-chrome/lhaoghhllmiaaagaffababmkdllgfcmc) (Atomic Chrome from the Chrome Store) 24 | * [The Atom package](https://atom.io/packages/atomic-chrome) (`atomic-chrome` from apm) 25 | 26 | ## Usage 27 | 28 | Atom needs to be running for this to work. 29 | 30 | 1. Focus a textarea or a contenteditable element 31 | 2. Press the icon of Atomic Chrome (or the shortcut). 32 | 33 | Note that the tab will open in the first launched instance of Atom. 34 | 35 | ### How do I bind a shortcut 36 | 37 | 1. Navigate to `chrome://extensions` 38 | 2. Scroll to the bottom of the page 39 | 3. Press 'Keyboard shortcuts' 40 | 4. Set a shortcut for Atomic Chrome 41 | 42 | ## Development 43 | 44 | This repository is for the Atom plugin development. 45 | For the Chrome plugin development, see https://github.com/tuvistavie/atomic-chrome. 46 | Contributions are welcome. 47 | -------------------------------------------------------------------------------- /lib/atomic-chrome.coffee: -------------------------------------------------------------------------------- 1 | {Server} = require 'ws' 2 | WSHandler = null # defer require till necessary 3 | WS_PORT = 64292 4 | 5 | module.exports = AtomicChrome = 6 | activate: (state) -> 7 | @wss = new Server({port: WS_PORT}) 8 | 9 | @wss.on 'connection', (ws) -> 10 | WSHandler ?= require './ws-handler' 11 | new WSHandler(ws) 12 | @wss.on 'error', (err) -> 13 | console.error(err) unless err.code == 'EADDRINUSE' 14 | 15 | deactivate: -> 16 | @wss.close() 17 | 18 | config: 19 | defaultExtension: 20 | type: 'string' 21 | default: '.md' 22 | -------------------------------------------------------------------------------- /lib/ws-handler.coffee: -------------------------------------------------------------------------------- 1 | temp = require 'temp' 2 | 3 | module.exports = class WSHandler 4 | constructor: (@ws) -> 5 | @closed = false 6 | @ws.on 'message', (message) => 7 | message = JSON.parse(message) 8 | this[message.type](message.payload) if this[message.type] 9 | @ws.on 'close', () => 10 | @closed = true 11 | @changeSubscription.dispose() if @changeSubscription 12 | @destroySubscription.dispose() if @changeSubscription 13 | 14 | register: (data) -> 15 | filepath = @getFile(data) 16 | atom.focus() # activivate Atom application 17 | atom.workspace.open(filepath).then (editor) => 18 | @initEditor(editor, data) 19 | 20 | getFile: (data) -> 21 | extension = data.extension ? atom.config.get('atomic-chrome.defaultExtension') 22 | title = (data.title || '').replace(/[^a-z0-9]/gi, '_').toLowerCase() 23 | temp.path {prefix: "#{title}-", suffix: extension} 24 | 25 | initEditor: (editor, data) -> 26 | @editor = editor 27 | @updateText(data) 28 | @destroySubscription = @editor.onDidDestroy => 29 | @ws.close() unless @closed 30 | @changeSubscription = @editor.onDidChange => 31 | @sendChanges() unless @closed || @ignoreChanges 32 | @ignoreChanges = false 33 | 34 | sendChanges: -> 35 | lines = @editor.getBuffer().lines || @editor.getBuffer().getLines() 36 | message = 37 | type: 'updateText' 38 | payload: 39 | text: lines.join('\n') 40 | @ws.send JSON.stringify(message) 41 | 42 | updateText: (data) -> 43 | return unless @editor && @editor.isAlive() 44 | @ignoreChanges = true # avoid sending received changes 45 | @editor.setText(data.text) 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "atomic-chrome", 3 | "main": "./lib/atomic-chrome", 4 | "version": "0.3.3", 5 | "description": "Edit Chrome text directly from Atom", 6 | "keywords": [], 7 | "repository": "https://github.com/tuvistavie/atomic-chrome-atom", 8 | "license": "MIT", 9 | "engines": { 10 | "atom": ">=1.0.0 <2.0.0" 11 | }, 12 | "dependencies": { 13 | "temp": "^0.8.3", 14 | "ws": "^1.0.1" 15 | } 16 | } 17 | --------------------------------------------------------------------------------