Skip to content

Commit

Permalink
feat:#85 Google插件扩展-发布脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Sep 20, 2022
1 parent 61ce753 commit 3432b46
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ dist-ssr
*.private.env.json
__snapshots__
test/data/
extension/
3 changes: 3 additions & 0 deletions deploy.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pwd
yarn build
# 删除Chrome插件专属文件
Remove-Item ./dist/background.js
Remove-Item ./dist/manifest.json

Remove-Item ../my-note-docker/workspace/SiYuan/data/widgets/sy-post-publisher -Recurse -Force -Confirm:$false
mkdir ../my-note-docker/workspace/SiYuan/data/widgets/sy-post-publisher
Expand Down
3 changes: 3 additions & 0 deletions deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pwd
yarn build
# 删除Chrome插件专属文件
rm ./dist/background.js
rm ./dist/manifest.json

rm -rf ../my-note-docker/workspace/SiYuan/data/widgets/sy-post-publisher/
mkdir ../my-note-docker/workspace/SiYuan/data/widgets/sy-post-publisher
Expand Down
9 changes: 9 additions & 0 deletions ext.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pwd
yarn build
# 删除siyuan挂件专属文件
rm ./dist/widget.json

rm -rf ./extension/*
mkdir extension
cp -r ./dist/* ./extension/
echo "Chrome插件发布完毕."
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>sy-post-publisher</title>
<title>思源笔记辅助工具 - 支持博客式制度浏览,文章发布</title>
</head>
<body>
<div id="app"></div>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"deploy-win": "pwsh deploy.ps1",
"wd": "yarn deploy-win",
"vdev": "vercel dev --listen 5005",
"vbuild": "vercel build"
"vbuild": "vercel build",
"ext": "bash ext.sh"
},
"dependencies": {
"@intlify/vite-plugin-vue-i18n": "^6.0.1",
Expand Down
7 changes: 7 additions & 0 deletions public/READNE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# todo

## doc

https://developer.chrome.com/docs/extensions/

https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/examples
30 changes: 30 additions & 0 deletions public/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Extension event listeners are a little different from the patterns you may have seen in DOM or
// Node.js APIs. The below event listener registration can be broken in to 4 distinct parts:
//
// * chrome - the global namespace for Chrome's extension APIs
// * runtime – the namespace of the specific API we want to use
// * onInstalled - the event we want to subscribe to
// * addListener - what we want to do with this event
//
// See https://developer.chrome.com/docs/extensions/reference/events/ for additional details.
chrome.runtime.onInstalled.addListener(async () => {
console.log("Installed")
});

function createPage() {
// While we could have used `let url = "index.html"`, using runtime.getURL is a bit more robust as
// it returns a full URL rather than just a path that Chrome needs to be resolved contextually at
// runtime.
let url = chrome.runtime.getURL("index.html");
window.open(url)
console.log(`Created tab`);
}

chrome.action.onClicked.addListener((tab) => {
// if (!tab.url.includes("chrome://")) {
chrome.scripting.executeScript({
target: {tabId: tab.id},
function: createPage
});
// }
});
25 changes: 25 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "思源笔记辅助工具",
"version": "1.1.3",
"manifest_version": 3,
"author": "terwer",
"description": "思源笔记辅助工具,支持博客式制度浏览,文章发布。",
"background": {
"service_worker": "background.js"
},
"permissions": [
"activeTab",
"scripting"
],
"web_accessible_resources": [
{
"resources": [
"index.html"
],
"matches": [
"<all_urls>"
]
}
],
"action": {}
}
36 changes: 18 additions & 18 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<!--
<publish-service v-if="isAuth"/>
<no-auth v-else/>
-->
<Index/>
</template>

<script lang="ts" setup>
Expand All @@ -9,8 +12,9 @@ import {getBooleanEnv, getEnv} from "./lib/envUtil";
import logUtil from "./lib/logUtil";
import {getQueryString} from "./lib/util";
import {getWidgetId} from "./lib/platform/siyuan/siyuanUtil";
import Index from "./components/Index.vue"
const isAuth = ref(false)
// const isAuth = ref(false)
onMounted(async () => {
logUtil.logWarn("MODE=>", import.meta.env.MODE)
Expand All @@ -24,27 +28,23 @@ onMounted(async () => {
// }
// 挂件模式不校验
const widgetResult = await getWidgetId()
if (widgetResult.isInSiyuan) {
isAuth.value = true
return
}
// 非挂件模式需要校验
const optPwd = getEnv("VITE_OPT_PWD") || ""
const pwd = getQueryString("pwd") || ""
if (pwd != "" && pwd == optPwd) {
isAuth.value = true
}
// const widgetResult = await getWidgetId()
// if (widgetResult.isInSiyuan) {
// isAuth.value = true
// return
// }
//
// // 非挂件模式需要校验
// const optPwd = getEnv("VITE_OPT_PWD") || ""
// const pwd = getQueryString("pwd") || ""
// if (pwd != "" && pwd == optPwd) {
// isAuth.value = true
// }
})
</script>

<script lang="ts">
import PublishService from "./components/PublishService.vue";
import NoAuth from "./components/NoAuth.vue";
export default {
name: 'App',
components: {PublishService, NoAuth}
name: 'App'
}
</script>
16 changes: 16 additions & 0 deletions src/components/Index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div>
<h1>Index</h1>
<a href="./index.html?pwd=123456&id=20220917154709-4aqccxm"></a>
</div>
</template>

<script lang="ts">
export default {
name: "Index.vue"
}
</script>

<style scoped>
</style>

0 comments on commit 3432b46

Please sign in to comment.