Skip to content

Commit

Permalink
Merge pull request #7 from ymkjp/master
Browse files Browse the repository at this point in the history
Releasing the first community edition
  • Loading branch information
ymkjp authored Jan 8, 2019
2 parents 3bb4630 + 3382354 commit 5bc9c06
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 453 deletions.
6 changes: 2 additions & 4 deletions .idea/codeStyles/Project.xml

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

5 changes: 4 additions & 1 deletion .idea/encodings.xml

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

6 changes: 3 additions & 3 deletions config/secret.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"firebase": {
"apiKey": "",
"authDomain": "test-b574f.firebaseapp.com",
"databaseURL": "https://test-b574f.firebaseio.com",
"projectId": "test-b574f",
"authDomain": "icac-shipt43.firebaseapp.com",
"databaseURL": "https://icac-shipt43.firebaseio.com/",
"projectId": "icac-shipt43",
"storageBucket": "",
"messagingSenderId": ""
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "icac",
"version": "1.2.0",
"version": "3.0.0",
"description": "[![Build Status](https://travis-ci.org/announce/icac.svg?branch=master)](https://travis-ci.org/announce/icac)",
"scripts": {
"test": "npm-run-all clean lint bundle",
Expand All @@ -19,7 +19,8 @@
"watch:crx:js": "onchange --delay 100 '*.json' 'src/**/*.*js' 'script/**/*.js' -- npm-run-all lint:js bundle:crx:js bundle:crx:ejs notify",
"watch:crx:manifest": "onchange --delay 1000 'src/crx/manifest.json' -- npm-run-all lint:js bundle:crx:manifest notify",
"watch:crx:assets": "onchange --delay 1000 'src/**/*.{html,css,json}' 'src/**/image' -- npm-run-all lint:css bundle:crx:assets notify",
"watch:shell": "onchange --delay 1000 'script/**/*.*sh' -- npm-run-all lint:shell notify",
"watch:config": "onchange --delay 1000 'config/**/*.{js,json}' -- npm-run-all lint:css bundle:crx:assets notify",
"watch:shell": "onchange --delay 1000 'script/**/*.*sh' -- npm-run-all bundle:crx:secret notify",
"watch:md": "onchange --delay 1000 '*.md' -- npm-run-all lint:md notify",
"build": "npm-run-all clean image bundle compress",
"notify": "./script/notify.bash $?",
Expand Down Expand Up @@ -52,7 +53,6 @@
"ejs": "^2.6.1",
"ejs-cli": "^2.0.1",
"eslint-plugin-flowtype": "^2.50.0",
"firebase": "^5.4.1",
"flow-bin": "^0.79.1",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
Expand Down
23 changes: 23 additions & 0 deletions src/crx/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,26 @@ export const MEEPLE: Object = {
mogawa: chrome.extension.getURL('image/Meeples-Vania.png'),
ahirama: chrome.extension.getURL('image/Meeples-Angie.png')
}

export const scriptName = 'github.com/announce/icac'

const CAC_DOMAIN = 'confluence.atlassian.com'
const PREFIX_JA = 'ja.'

export const createRedirectionUrl = (pageUrl: string): URL => {
const url = new URL(pageUrl)
if (url.host.lastIndexOf(CAC_DOMAIN) < 0) {
return url
}
switch (url.host) {
case CAC_DOMAIN:
// @TODO Store prefix preference https://developer.chrome.com/extensions/options
url.host = PREFIX_JA + CAC_DOMAIN
break
default:
url.host = CAC_DOMAIN
break
}
console.log('createRedirectionUrl:', url.href)
return url
}
54 changes: 54 additions & 0 deletions src/crx/background.js
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)
2 changes: 1 addition & 1 deletion src/crx/content-satisfaction-feedback.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
$s.attr('data-src', color)
})
// @TODO + Use local storage to show the previous feedback when the customer revisits
// @TODO Use local storage to show the previous feedback when the customer revisits
// @TODO Let the similes say "Thank you"
window.open(href, name, `resizable,scrollbars,width=${width},height=${height}`)
}
Expand Down
90 changes: 48 additions & 42 deletions src/crx/content.js
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())
})
Loading

0 comments on commit 5bc9c06

Please sign in to comment.