Skip to content

Commit

Permalink
Remove options page
Browse files Browse the repository at this point in the history
  • Loading branch information
kinglisky committed Dec 18, 2017
1 parent 5a35436 commit 901c65b
Show file tree
Hide file tree
Showing 27 changed files with 332 additions and 98 deletions.
8 changes: 8 additions & 0 deletions extension/background.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions extension/background.js.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions extension/content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>斗图插件</title>
</head>

<body>
<div id="app"></div>
<script type="text/javascript" src="vendor.js"></script><script type="text/javascript" src="main.js"></script></body>

</html>
2 changes: 2 additions & 0 deletions extension/content.js

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

1 change: 1 addition & 0 deletions extension/content.js.map

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

Binary file added extension/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions extension/main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions extension/main.js.map

Large diffs are not rendered by default.

30 changes: 25 additions & 5 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,30 @@
"permissions": [
"*://*/",
"storage",
"contextMenus"
"contextMenus",
"clipboardWrite",
"clipboardRead"
],
"content_scripts": [{
"matches": ["*://github.com/*"],
"js": ["vendor.js", "content.js"]
}]
"content_scripts": [
{
"matches": [
"*://www.baidu.com/*"
],
"js": [
"vendor.js",
"content.js"
]
}
],
"options_page": "options.html",
"browser_action": {
"default_icon": {
"19": "icon.png",
"38": "icon.png"
}
},
"web_accessible_resources": [
"content.html"
],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
2 changes: 1 addition & 1 deletion src/popup/index.html → extension/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

<body>
<div id="app"></div>
</body>
<script type="text/javascript" src="vendor.js"></script><script type="text/javascript" src="options.js"></script></body>

</html>
2 changes: 2 additions & 0 deletions extension/options.js

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

1 change: 1 addition & 0 deletions extension/options.js.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions extension/vendor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions extension/vendor.js.map

Large diffs are not rendered by default.

36 changes: 35 additions & 1 deletion src/background/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
import crun from '@/common/crun'
import cstore from '@/common/cstore'
import config from '@/common/config'
import QueryEngine from './queryEngine'
import PicBed from './picBed'
import {
merge,
fetchImgToBase64
} from './util'

let CONFIG = merge(config)

function initConfig () {
cstore.get(config).then(cfg => {
CONFIG = cfg
crun.$emit('update-config', CONFIG, true)
})
}

initConfig()

cstore.update(initConfig)

// 点击窗口图标打开窗口
chrome.browserAction.onClicked.addListener(tab => {
crun.$emit('show-app', true, true)
})

// 打开配置页面
// crun.$on('open-option-page', (params, cb) => {
// chrome.windows.create({
// url: 'options.html',
// focused: true,
// type: 'normal'
// })
// })

crun.$on('fetch-expression', (params, cb) => {
QueryEngine.sogou(params).then(cb)
})
Expand All @@ -18,5 +44,13 @@ crun.$on('url-to-base64', (url, cb) => {
})

crun.$on('uniform-url', (base64, cb) => {
PicBed.weibo(base64).then(cb, console.log)
PicBed[CONFIG.picBed](base64).then(cb)
})

crun.$on('update-config', (config, cb) => {
cstore.set(config).then(cb)
})

crun.$on('get-config', (query, cb) => {
cstore.get(query).then(cb)
})
4 changes: 4 additions & 0 deletions src/common/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
showFullLinks: false,
picBed: 'weibo'
}
19 changes: 19 additions & 0 deletions src/common/cstore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default {
get (query) {
return new Promise(resolve => {
chrome.storage.sync.get(query, res => {
resolve(res)
})
})
},

set (value) {
return new Promise(resolve => {
chrome.storage.sync.set(value, resolve)
})
},

update (fn) {
chrome.storage.onChanged.addListener(fn)
}
}
68 changes: 9 additions & 59 deletions src/content/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,81 +7,31 @@
:page.sync="page"
:loading="loading">
</expression-list>
<config></config>
<span class="icon-close close-btn" @click="toggleView(false)"></span>
</section>
</template>

<script>
import debounce from 'lodash/debounce'
import crun from '@/common/crun'
import AppHeader from './components/app-header'
import ExpressionList from './components/expression-list'
import Config from './components/config'
import toggleView from './mixins/toggleView'
import fetchExpression from './mixins/fetchExpression'
export default {
mixins: [toggleView, fetchExpression],
data () {
return {
query: '',
data: [],
size: 10,
page: 1,
total: 0,
loading: false
}
},
computed: {
params () {
const { query, page, size } = this
return { query, page, size }
}
},
watch: {
query: 'reset',
params: {
deep: true,
handler: 'fetchExpression'
}
},
created () {
crun.$on('show-app', this.toggleView)
},
methods: {
fetchExp (v) {
this.query = v
},
reset () {
this.data = []
this.page = 1
this.total = 0
},
fetchExpression () {
if (!this.query) return
this.loading = true
crun.$emit('fetch-expression', this.params)
.then(this.receiveExpression)
},
receiveExpression ({ data = [], total = 0 }) {
this.loading = false
this.total = total
this.data = this.data.concat(data)
},
toggleView (visible) {
window.parent.postMessage({
id: 'chrome-extension-aidou',
value: visible
}, '*')
}
},
components: {
AppHeader,
ExpressionList
ExpressionList,
Config,
}
}
</script>
Expand Down
12 changes: 9 additions & 3 deletions src/content/components/app-header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@


<script>
import crun from '@/common/crun'
export default {
data () {
return {
Expand All @@ -27,7 +29,7 @@ export default {
computed: {
btnList () {
const { noop } = this
const { noop, openOptionPage } = this
return [
{
icon: 'icon-shuffle',
Expand All @@ -42,15 +44,18 @@ export default {
{
icon: 'icon-settings',
text: '设置',
handler: noop
handler: openOptionPage
}
]
}
},
methods: {
noop () {
alert('fuck you')
},
openOptionPage () {
crun.$emit('open-option-page')
},
fetchExp () {
Expand Down Expand Up @@ -78,6 +83,7 @@ export default {
flex: 3;
input {
flex: 1;
display: block;
height: 100%;
border: none;
Expand Down
Loading

0 comments on commit 901c65b

Please sign in to comment.