Skip to content

Commit

Permalink
🎉增加chrome插件功能
Browse files Browse the repository at this point in the history
  • Loading branch information
rowthan committed Aug 14, 2018
1 parent 0a68cd1 commit b422e97
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 1 deletion.
11 changes: 11 additions & 0 deletions extension/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extensionName": {
"message": "whats-element"
},
"extensionDescription": {
"message": "whats-element."
},
"browserActionTitle": {
"message": "click and compute."
}
}
11 changes: 11 additions & 0 deletions extension/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extensionName": {
"message": "whats-element"
},
"extensionDescription": {
"message": "whats-element."
},
"browserActionTitle": {
"message": "click and compute."
}
}
Binary file added extension/images/icon-128.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 extension/images/icon-16.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 extension/images/icon-32.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 extension/images/icon-48.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 extension/images/icon-64.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 extension/images/icon-96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"manifest_version": 2,
"name": "__MSG_extensionName__",
"short_name": "__MSG_extensionName__",
"version": "0.0.1",
"description": "__MSG_extensionDescription__",
"default_locale": "en",
"icons": {
"16": "images/icon-16.png",
"32": "images/icon-32.png",
"48": "images/icon-48.png",
"64": "images/icon-64.png",
"96": "images/icon-96.png",
"128": "images/icon-128.png"
},
"permissions": [
"contextMenus",
"activeTab",
"tabs"
],
"browser_action": {
"default_icon": {
"16": "images/icon-16.png",
"32": "images/icon-32.png",
"48": "images/icon-48.png",
"64": "images/icon-64.png",
"96": "images/icon-96.png",
"128": "images/icon-128.png"
},
"default_title": "__MSG_browserActionTitle__"
},
"commands": {
"whats_element": {
"description": "compute element",
"suggested_key": {
"default": "Ctrl+Shift+E"
}
}
},
"background": {
"scripts": ["scripts/background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": [ "<all_urls>" ],
"js": ["scripts/whatsElement.js"],
"all_frames": true
}
]
}
38 changes: 38 additions & 0 deletions extension/scripts/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function CreateContextMenus() {
chrome.contextMenus.removeAll();
chrome.contextMenus.create({
id: 'whats-element-get',
title: 'whats element(Ctrl+Shift+E)',
contexts: ["page", "frame", "selection", "link", "editable", "image", "video", "audio"]
})
})()

chrome.contextMenus.onClicked.addListener((info) => {
executeWhats()
});


chrome.browserAction.onClicked.addListener(function(tab) {
executeWhats()
});

chrome.commands.onCommand.addListener((command) => {
if(command==="whats_element"){
executeWhats()
}
});

function executeWhats(){
chrome.tabs.executeScript({
code: 'window.whats.getUniqueId();',
allFrames: true,
})
}








1 change: 1 addition & 0 deletions extension/scripts/whatsElement.js

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

3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ gulp.task('compress', function (cb) {
pump([
gulp.src('src/**/*.js'),
uglify(),
gulp.dest('dist')
gulp.dest('dist'),
gulp.dest('extension/scripts')
],
cb
);
Expand Down

0 comments on commit b422e97

Please sign in to comment.