-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ymkjp/master
Releasing the first community edition
- Loading branch information
Showing
15 changed files
with
245 additions
and
453 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,54 @@ | ||
'use strict' | ||
// const _ = require('lodash') | ||
const app = require('./app') | ||
|
||
/** | ||
* https://developer.chrome.com/apps/declare_permissions#manifest | ||
* https://developer.chrome.com/extensions/background_pages | ||
* https://developer.chrome.com/apps/contextMenus | ||
* https://developer.chrome.com/extensions/tabs#method-update | ||
* @param w | ||
* @param chrome | ||
*/ | ||
const main = (w, chrome) => { | ||
const executeInActiveTab = (fn) => { | ||
chrome.tabs.query({ | ||
active: true, | ||
lastFocusedWindow: true | ||
}, (tabs) => { | ||
tabs.map(fn) | ||
}) | ||
} | ||
|
||
const redirect = (pageUrl) => { | ||
const url = app.createRedirectionUrl(pageUrl) | ||
if (url.href === pageUrl) { | ||
console.log('Skipping redirection as target is the same to given URL:', url) | ||
return | ||
} | ||
executeInActiveTab((tab) => { | ||
console.log('tab:', tab) | ||
chrome.tabs.update(tab.id, { | ||
url: url.href | ||
}) | ||
}) | ||
} | ||
|
||
chrome.runtime.onInstalled.addListener(() => { | ||
console.log('chrome.runtime.onInstalled:', app.scriptName) | ||
chrome.contextMenus.create({ | ||
title: 'Toggle the language switcher', | ||
contexts: ['page'], | ||
id: app.scriptName | ||
}) | ||
}) | ||
|
||
chrome.contextMenus.onClicked.addListener((info) => { | ||
console.log('chrome.contextMenus.onClicked:', info) | ||
if (info.menuItemId === app.scriptName && 'pageUrl' in info) { | ||
return redirect(info.pageUrl) | ||
} | ||
}) | ||
} | ||
|
||
main(window, chrome) |
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
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 |
---|---|---|
@@ -1,64 +1,70 @@ | ||
// @flow | ||
'use strict' | ||
/** | ||
* @TODO Localize the UI languages | ||
* 1. chrome.i18n - Google Chrome https://developer.chrome.com/extensions/i18n | ||
* 2. ContextMenu | ||
*/ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const $ = require('jquery') | ||
const ejs = require('ejs') | ||
const uuid = require('uuid/v4') | ||
const images = require('./image/base64') | ||
// const uuid = require('uuid/v4') | ||
// const images = require('./image/base64') | ||
const app = require('./app') | ||
|
||
const createLanguageSwitcherElement = () => { | ||
return ejs.render(fs.readFileSync(path.resolve('src/crx/content-language-switcher.html.ejs'), 'utf-8'), { | ||
app: app | ||
}) | ||
} | ||
// const createLanguageSwitcherElement = () => { | ||
// return ejs.render(fs.readFileSync(path.resolve('src/crx/content-language-switcher.html.ejs'), 'utf-8'), { | ||
// app: app | ||
// }) | ||
// } | ||
|
||
const createTranslationRequestElement = () => { | ||
const title = $('.page-title').text() | ||
const url = new URL(chrome.extension.getURL('form-translation-request.html')) | ||
url.searchParams.set('uuid', uuid()) | ||
url.searchParams.set('title', encodeURIComponent(title)) | ||
url.searchParams.set('url', encodeURIComponent(window.location.href)) | ||
return ejs.render(fs.readFileSync(path.resolve('src/crx/content-translation-request.html.ejs'), 'utf-8'), { | ||
app: app, | ||
url: url.href | ||
}) | ||
} | ||
// const createTranslationRequestElement = () => { | ||
// const title = $('.page-title').text() | ||
// const url = new URL(chrome.extension.getURL('form-translation-request.html')) | ||
// url.searchParams.set('uuid', uuid()) | ||
// url.searchParams.set('title', encodeURIComponent(title)) | ||
// url.searchParams.set('url', encodeURIComponent(window.location.href)) | ||
// return ejs.render(fs.readFileSync(path.resolve('src/crx/content-translation-request.html.ejs'), 'utf-8'), { | ||
// app: app, | ||
// url: url.href | ||
// }) | ||
// } | ||
|
||
const createTranslationContributorsElement = () => { | ||
return ejs.render(fs.readFileSync(path.resolve('src/crx/content-translation-contributors.html.ejs'), 'utf-8'), { | ||
app: app | ||
}) | ||
} | ||
|
||
const createSatisfactionElement = () => { | ||
const title = $('.page-title').text() | ||
const url = new URL(chrome.extension.getURL('form-satisfaction-feedback.html')) | ||
url.searchParams.set('uuid', uuid()) | ||
url.searchParams.set('title', encodeURIComponent(title)) | ||
url.searchParams.set('url', encodeURIComponent(window.location.href)) | ||
const satisfaction = images['satisfaction'].map((value, index) => { | ||
url.searchParams.set('score', 5 - index) | ||
return {...{ | ||
href: url.href | ||
}, | ||
...value} | ||
}) | ||
// console.log('satisfaction:', satisfaction) | ||
return ejs.render(fs.readFileSync(path.resolve('src/crx/content-satisfaction-feedback.html.ejs'), 'utf-8'), { | ||
app: app, | ||
satisfaction: satisfaction | ||
}) | ||
} | ||
// const createSatisfactionElement = () => { | ||
// const title = $('.page-title').text() | ||
// const url = new URL(chrome.extension.getURL('form-satisfaction-feedback.html')) | ||
// url.searchParams.set('uuid', uuid()) | ||
// url.searchParams.set('title', encodeURIComponent(title)) | ||
// url.searchParams.set('url', encodeURIComponent(window.location.href)) | ||
// const satisfaction = images['satisfaction'].map((value, index) => { | ||
// url.searchParams.set('score', 5 - index) | ||
// return {...{ | ||
// href: url.href | ||
// }, | ||
// ...value} | ||
// }) | ||
// // console.log('satisfaction:', satisfaction) | ||
// return ejs.render(fs.readFileSync(path.resolve('src/crx/content-satisfaction-feedback.html.ejs'), 'utf-8'), { | ||
// app: app, | ||
// satisfaction: satisfaction | ||
// }) | ||
// } | ||
|
||
/** | ||
* https://developer.chrome.com/extensions/content_scripts | ||
*/ | ||
$(() => { | ||
$('.page-sidebars') | ||
.prepend(createTranslationRequestElement()) | ||
.prepend(createLanguageSwitcherElement()) | ||
.append(createTranslationContributorsElement()) | ||
.append(createSatisfactionElement()) | ||
// $('.page-sidebars') | ||
// .prepend(createTranslationRequestElement()) | ||
// .prepend(createLanguageSwitcherElement()) | ||
// .append(createTranslationContributorsElement()) | ||
// .append(createSatisfactionElement()) | ||
$('.page-sidebars').append(createTranslationContributorsElement()) | ||
}) |
Oops, something went wrong.