Skip to content

Commit

Permalink
Done
Browse files Browse the repository at this point in the history
  • Loading branch information
vladislav.saifulin committed Oct 4, 2019
1 parent 640ab2c commit d697464
Show file tree
Hide file tree
Showing 12 changed files with 10,480 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## IDEs ###
*.sublime-workspace
.tag*
.tern-project
.idea

### OSX ###
.DS_Store
.AppleDouble
.LSOverride
Icon

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

dist/
node_modules/
.tmp
GumGumScreenshots_*.crx
updates.xml
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 100,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "avoid"
}
87 changes: 87 additions & 0 deletions df
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
commit 640ab2cc8521ec24ba902478236da72ae9ab59fe (HEAD -> master)
Author: vladislav.saifulin <[email protected]>
Date: Sat Oct 5 02:55:47 2019 +0300

first commit

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..bdd5def
--- /dev/null
+++ b/README.md
@@ -0,0 +1,75 @@
+# chrome-extension-template
+
+## Introduction
+
+This project aims to provide an easy to use boilerplate for chrome extensions, showcasing communication between its different scripts.
+
+Not all extensions will need of all scripts or all types of messaging. All code snippets are optional. Text and images should be replaced with your own.
+
+## Installation
+
+Clone the repo:
+
+```
+git clone [email protected]:edrpls/chrome-extension-template.git name-of-your-project
+```
+
+Set git to track your own repository instead of this one:
+
+```
+git remote set-url --delete origin [email protected]:edrpls/chrome-extension-template.git # Remove old origin
+git remote set-url --add origin [YOUR REPO URL] # Add new origin
+```
+
+Install dependencies:
+
+```
+yarn install # or npm install
+```
+
+## Usage
+
+To run a development server that will watch for file changes and rebuild the scripts, run:
+
+```
+yarn start
+```
+
+To just build the files without the development server:
+
+```
+yarn build
+```
+
+Both commands will create a `dist/` directory, it will contain the built files that should be loaded into the browser or packed.
+
+## Load into Chrome
+
+To load the built files into Chrome, open [chrome://extensions/](chrome://extensions/).
+
+Enable "Developer mode" if it's not enabled yet:
+
+![Developer Mode Checkbox](assets/dev_mode.png)
+
+Click on "Load unpacked":
+
+![Load Unpacked Button](assets/load_unpacked.png)
+
+Find the `dist/` directory on your system and open it.
+
+The extension should be now at the top of the page:
+
+![Extension Loaded](assets/ext_loaded.png)
+
+## Publishing
+
+[Follow the official docs](https://developer.chrome.com/webstore/publish) to learn how to publish a Chrome extension.
+Please note that Google has its own process to review public extensions and using this boilerplate **does not guarantee** that the extension will pass it. Passing the review process is your responsibility!
+
+## External resources
+
+* [Sample extension built with this template](https://github.com/edrpls/social-network-alert)
+
+* [Chrome Developer Documentation](https://developer.chrome.com/extensions/devguide)
+
+* [Overview slides about Chrome Extensions](https://github.com/edrpls/chrome-extensions-what-why-how)
54 changes: 54 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"manifest_version": 2,
"name": "Shortcuts for Yandex.Music™",
"version": "1.0.0",
"description": "Shortcuts support for Yandex.Music™. \nIcons made by https://www.flaticon.com/authors/smashicons from www.flaticon.com",
"icons": {
"128": "128.png"
},
"browser_action": {
"default_title": "Yandex.Music™ global shortcuts"
},
"content_scripts": [
{
"matches": [
"https://music.yandex.ru/*"
],
"js": [
"in-content.js"
]
}
],
"background": {
"scripts": [
"background.js"
],
"persistent": true
},
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'; img-src * data: 'self' 'unsafe-eval'",
"offline_enabled": true,
"permissions": [],
"commands": {
"next-track": {
"suggested_key": {
"default": "Ctrl+Shift+3"
},
"description": "Go to next",
"global": true
},
"prev-track": {
"suggested_key": {
"default": "Ctrl+Shift+1"
},
"description": "Go to previous",
"global": true
},
"toggle-pause": {
"suggested_key": {
"default": "Ctrl+Shift+2"
},
"description": "Play/pause",
"global": true
}
}
}
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "chrome-extension-template",
"version": "0.0.9",
"description": "Chrome extension boilerplate, replace all values!",
"main": "src/index.js",
"repository": "[email protected]:edrpls/chrome-extension-template.git",
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.1.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.6.1",
"copy-webpack-plugin": "^4.0.1",
"crx-webpack-plugin": "^0.1.5",
"eslint": "^4.2.0",
"eslint-plugin-react": "^7.1.0",
"rimraf": "^2.6.1",
"webpack": "^3.2.0"
},
"scripts": {
"start": "nodemon --exec yarn build",
"prebuild": "rimraf dist",
"build": "webpack"
},
"nodemonConfig": {
"ignore": [
"dist/",
"node_modules"
],
"execMap": {
"js": "node"
},
"ext": "js html css",
"verbose": true
},
"dependencies": {
"nodemon": "^1.14.12"
},
"resolutions": {
"**/event-stream": "^4.0.1"
}
}
Binary file added src/images/128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chrome.commands.onCommand.addListener(function(command) {
chrome.tabs.query({}, function(tabs){
for (let i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(tabs[i].id, command);
}
});
});
19 changes: 19 additions & 0 deletions src/js/in-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function inject(code) {
const th = document.getElementsByTagName("head")[0];
const s = document.createElement("script");
s.setAttribute("type", "text/javascript");
s.innerText = code;
th.appendChild(s);
console.log("Injected " + code);
}

chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
console.log(message);
if (message === "next-track") {
inject("externalAPI.next();");
} else if (message === "prev-track") {
inject("externalAPI.prev();");
} else if (message === "toggle-pause") {
inject("externalAPI.togglePause();");
}
});
36 changes: 36 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const Crx = require('crx-webpack-plugin');
const { version } = require('./package.json');

module.exports = {
entry: {
background: './src/js/background.js',
'in-content': './src/js/in-content.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js'
},

cache: true,
devtool: 'eval-cheap-module-source-map',

module: {
loaders: [
{
test: /\.js?$/,
include: [path.resolve(__dirname, 'src')],
loader: 'babel-loader'
}
]
},

plugins: [
new CopyWebpackPlugin([
{ from: './manifest.json' },
{ from: './src/images' },
{ from: './src/views' }
])
]
};
8 changes: 8 additions & 0 deletions ya.hotkey.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Loading

0 comments on commit d697464

Please sign in to comment.