Skip to content

Commit

Permalink
Merge pull request #97 from terwer/dev
Browse files Browse the repository at this point in the history
feat:#85 Google插件扩展-已兼容Chrome插件
  • Loading branch information
terwer authored Sep 25, 2022
2 parents 728c22b + e7a8c46 commit 95d0444
Show file tree
Hide file tree
Showing 23 changed files with 678 additions and 109 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"cross-fetch": "^3.1.5",
"element-plus": "^2.2.11",
"express": "^4.18.1",
"fast-xml-parser": "^4.0.10",
"highlight.js": "^11.6.0",
"js-base64": "^3.7.2",
"js-yaml": "^4.1.0",
Expand Down
44 changes: 27 additions & 17 deletions public/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,33 @@
//
// See https://developer.chrome.com/docs/extensions/reference/events/ for additional details.
chrome.runtime.onInstalled.addListener(async () => {
console.log("Installed")
console.log("Chrome Extension 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.runtime.onMessage.addListener((request, sender, sendResponse) => {
switch (request.type) {
case 'fetchChromeXmlrpc':
(async () => {
const response = await fetch(request.apiUrl, request.fetchCORSParams);
const resText = await response.text()
// console.log("chrome.runtime.onMessage.addListener fetchChromeXmlrpc response:", resText)
sendResponse(resText);
})();
break;
case 'fetchChromeJson':
(async () => {
const response = await fetch(request.apiUrl, request.fetchCORSOptions);
const resJson = await response.json()
console.log("chrome.runtime.onMessage.addListener fetchChromeJson response:", resJson)
sendResponse(resJson);
})();
break;
// 你可以定义任意内容,使用sendResponse()来返回它
case 'test':
sendResponse({'msg': 'test'});
break;
}

return true; // keep the messaging channel open for sendResponse
});

// chrome.action.onClicked.addListener((tab) => {
// if (!tab.url.includes("chrome://")) {
// chrome.scripting.executeScript({
// target: {tabId: tab.id},
// function: createPage
// });
// }
// });
1 change: 1 addition & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"activeTab",
"scripting"
],
"host_permissions": [ "*://*/*" ],
"web_accessible_resources": [
{
"resources": [
Expand Down
2 changes: 1 addition & 1 deletion src/components/tab/DynamicPlantform.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const submitForm = async (formEl: FormInstance | undefined) => {
const pkey = formData.plantformKey
// 最终存储的key
const ptypeKey = pType.value.toLowerCase() + "-" + formData.plantformKey
logUtil.logWarn("将要保存的平台key", ptypeKey)
logUtil.logInfo("将要保存的平台key", ptypeKey)
if (isDynamicKeyExists(ptypeKey)) {
ElMessage.error(t('dynamic.platform.opt.key.exist'))
return
Expand Down
2 changes: 1 addition & 1 deletion src/components/tab/PostBind.vue
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ const submitForm = async (formEl: FormInstance | undefined) => {
assignPostid(item.modelValue, customAttr, posidKey, item.posid)
});
logUtil.logWarn("PostBind保存属性到思源笔记,meta=>", customAttr);
logUtil.logInfo("PostBind保存属性到思源笔记,meta=>", customAttr);
await setPageAttrs(siyuanData.pageId, customAttr)
ElMessage.success(t('main.opt.success'))
Expand Down
12 changes: 6 additions & 6 deletions src/components/tab/main/CommonBlogMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function checkForce() {
// 别名不为空,默认不刷新
if (!forceRefresh.value) {
// ElMessage.warning(t('main.force.refresh.tip'))
logUtil.logWarn(t('main.force.refresh.tip'))
logUtil.logInfo(t('main.force.refresh.tip'))
return false
}
Expand Down Expand Up @@ -462,7 +462,7 @@ const oneclickAttr = async (hideTip?: boolean) => {
// 发布属性
await saveAttrToSiyuan(true)
logUtil.logWarn("发布属性完成")
logUtil.logInfo("发布属性完成")
isGenLoading.value = false
if (hideTip != true) {
Expand Down Expand Up @@ -523,19 +523,19 @@ const doPublish = async () => {
throw new Error("文章更新失败=>" + postid)
}
logUtil.logWarn("文章已更新,postid=>", postid)
logUtil.logInfo("文章已更新,postid=>", postid)
} else {
postid = await api.newPost(post, publish)
// 这里是发布成功之后
// 属性获取postidKey
logUtil.logWarn("当前保存的posidKey=>", commonblogCfg.posidKey)
logUtil.logInfo("当前保存的posidKey=>", commonblogCfg.posidKey)
const customAttr = {
[commonblogCfg.posidKey || ""]: postid,
};
await setPageAttrs(siyuanData.pageId, customAttr)
logUtil.logInfo("CommonblogMain发布成功,保存postid,meta=>", customAttr);
logUtil.logWarn("文章发布成功,postid=>", postid)
logUtil.logInfo("文章发布成功,postid=>", postid)
}
// 刷新属性数据
Expand Down Expand Up @@ -598,7 +598,7 @@ const doCancel = async (isInit: boolean) => {
[commonblogCfg.posidKey || ""]: ""
};
await setPageAttrs(siyuanData.pageId, customAttr)
logUtil.logWarn("MetaweblogMain取消发布,meta=>", customAttr);
logUtil.logInfo("MetaweblogMain取消发布,meta=>", customAttr);
// 刷新属性数据
if (isInit) {
Expand Down
12 changes: 6 additions & 6 deletions src/components/tab/main/MetaweblogMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ function checkForce() {
// 别名不为空,默认不刷新
if (!forceRefresh.value) {
// ElMessage.warning(t('main.force.refresh.tip'))
logUtil.logWarn(t('main.force.refresh.tip'))
logUtil.logInfo(t('main.force.refresh.tip'))
return false
}
Expand Down Expand Up @@ -548,7 +548,7 @@ const oneclickAttr = async (hideTip?: boolean) => {
// 发布属性
await saveAttrToSiyuan(true)
logUtil.logWarn("发布属性完成")
logUtil.logInfo("发布属性完成")
isGenLoading.value = false
if (hideTip != true) {
Expand Down Expand Up @@ -613,19 +613,19 @@ const doPublish = async () => {
throw new Error("文章更新失败=>" + postid)
}
logUtil.logWarn("文章已更新,postid=>", postid)
logUtil.logInfo("文章已更新,postid=>", postid)
} else {
postid = await api.newPost(post, publish)
// 这里是发布成功之后
// 属性获取postidKey
logUtil.logWarn("当前保存的posidKey=>", metaweblogCfg.posidKey)
logUtil.logInfo("当前保存的posidKey=>", metaweblogCfg.posidKey)
const customAttr = {
[metaweblogCfg.posidKey]: postid,
};
await setPageAttrs(siyuanData.pageId, customAttr)
logUtil.logInfo("MetaweblogMain发布成功,保存postid,meta=>", customAttr);
logUtil.logWarn("文章发布成功,postid=>", postid)
logUtil.logInfo("文章发布成功,postid=>", postid)
}
// 刷新属性数据
Expand Down Expand Up @@ -686,7 +686,7 @@ const doCancel = async (isInit: boolean) => {
[metaweblogCfg.posidKey]: ""
};
await setPageAttrs(siyuanData.pageId, customAttr)
logUtil.logWarn("MetaweblogMain取消发布,meta=>", customAttr);
logUtil.logInfo("MetaweblogMain取消发布,meta=>", customAttr);
// 刷新属性数据
if (isInit) {
Expand Down
22 changes: 11 additions & 11 deletions src/components/tab/main/VuepressMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ watch(() => props.isReload, async (oldValue, newValue) => {
// 初始化
await initPage()
logUtil.logWarn("VuepressMain检测到更新操作,刷新页面")
logUtil.logInfo("VuepressMain检测到更新操作,刷新页面")
})
onBeforeMount(async () => {
Expand Down Expand Up @@ -325,7 +325,7 @@ async function initPage() {
ElMessage.error("网络异常,数据获取失败")
throw new Error("网络异常,数据获取失败")
}
logUtil.logWarn("VuepressMain获取主文档", page)
logUtil.logInfo("VuepressMain获取主文档", page)
// 思源笔记数据
siyuanData.value.pageId = pageId;
Expand Down Expand Up @@ -405,7 +405,7 @@ function checkForce() {
// 别名不为空,默认不刷新
if (!forceRefresh.value) {
// ElMessage.warning(t('main.force.refresh.tip'))
logUtil.logWarn(t('main.force.refresh.tip'))
logUtil.logInfo(t('main.force.refresh.tip'))
return false
}
Expand Down Expand Up @@ -535,7 +535,7 @@ async function saveAttrToSiyuan(hideTip?: boolean) {
tags: formData.value.tag.dynamicTags.join(",")
};
await setPageAttrs(siyuanData.value.pageId, customAttr)
logUtil.logWarn("VuepressMain保存属性到思源笔记,meta=>", customAttr);
logUtil.logInfo("VuepressMain保存属性到思源笔记,meta=>", customAttr);
// 单独调用才去刷新数据,否则自行刷新数据
if (hideTip != true) {
Expand Down Expand Up @@ -706,7 +706,7 @@ async function doPublish() {
return
} else if (isOk && vuepressGithubEnabled.value) {
// api可用并且开启了发布
logUtil.logWarn("开始真正调用api发布到Github")
logUtil.logInfo("开始真正调用api发布到Github")
const vuepressCfg = getJSONConf<IVuepressCfg>(API_TYPE_CONSTANTS.API_TYPE_VUEPRESS)
Expand All @@ -716,13 +716,13 @@ async function doPublish() {
// 如果选择了自定义的目录
if (formData.value.customPath.indexOf(".md") > -1) {
docPath = formData.value.customPath
logUtil.logWarn("已经有完整路径,不拼接")
logUtil.logInfo("已经有完整路径,不拼接")
} else {
docPath = formData.value.customPath + "/" + mdFile
}
logUtil.logInfo(formData.value.customPath)
logUtil.logWarn("文章讲发布于以下路径=>", docPath)
logUtil.logInfo("文章讲发布于以下路径=>", docPath)
}
// 发布内容
Expand All @@ -734,7 +734,7 @@ async function doPublish() {
vuepressData.value.vuepressContent = md;
vuepressData.value.vuepressFullContent = mdContent;
logUtil.logWarn("即将发布的内容,mdContent=>", {"mdContent": mdContent})
logUtil.logInfo("即将发布的内容,mdContent=>", {"mdContent": mdContent})
// 发布
const res = await publishPage(vuepressCfg, docPath, mdContent)
Expand Down Expand Up @@ -764,7 +764,7 @@ async function doPublish() {
// 刷新属性数据
await initPage();
}
logUtil.logWarn("发布内容完成")
logUtil.logInfo("发布内容完成")
isPublishLoading.value = false
ElMessage.success(t('main.opt.status.publish'))
Expand All @@ -782,7 +782,7 @@ async function oneclickAttr(hideTip?: boolean) {
// 发布属性
await saveAttrToSiyuan(true)
logUtil.logWarn("发布属性完成")
logUtil.logInfo("发布属性完成")
isGenLoading.value = false
if (hideTip != true) {
Expand Down Expand Up @@ -830,7 +830,7 @@ async function doCancel(isInit: boolean) {
[POSTID_KEY_CONSTANTS.VUEPRESS_POSTID_KEY]: ""
};
await setPageAttrs(siyuanData.value.pageId, customAttr)
logUtil.logWarn("VuepressMain取消发布,meta=>", customAttr);
logUtil.logInfo("VuepressMain取消发布,meta=>", customAttr);
// 刷新属性数据
if (isInit) {
Expand Down
11 changes: 11 additions & 0 deletions src/lib/chrome/ChromeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ export function goToPage(pageUrl: string, split?: string) {
export function isInChromeExtension() {
// @ts-ignore
return typeof chrome.runtime != "undefined";
}

/**
* 向Chrome发送消息
* @param message 消息
*/
export function sendChromeMessage(message: any) {
return new Promise((resolve) => {
// @ts-ignore
chrome.runtime.sendMessage(message, resolve)
})
}
4 changes: 2 additions & 2 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function getConf(key: string): string {

const value = localStorage.getItem(key)
if (!value) {
logUtil.logWarn("未找到对应数据,key=>", key)
logUtil.logInfo("未找到对应数据,key=>", key)
return "";
}
logUtil.logInfo("从localStorage获取数据=>", value)
Expand Down Expand Up @@ -112,7 +112,7 @@ export function setJSONConf<T>(key: string, value: T): void {
*/
export function setConf(key: string, value: string): void {
if (!value || value == "") {
logUtil.logWarn("空值,不保存")
logUtil.logInfo("空值,不保存")
return
}

Expand Down
8 changes: 5 additions & 3 deletions src/lib/constants/metaweblogMethodConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ const GET_USERS_BLOGS = "blogger.getUsersBlogs"
const NEW_POST = "metaWeblog.newPost"
const EDIT_POST = "metaWeblog.editPost"
const DELETE_POST = "blogger.deletePost"
const GET_CATEGORIES = "metaWeblog.getCategories"
const GET_RECENT_POSTS = "metaWeblog.getRecentPosts"
const GET_POST = "metaWeblog.getPost"
const GET_CATEGORIES = "metaWeblog.getCategories"

export const METAWEBLOG_METHOD_CONSTANTS = {
GET_USERS_BLOGS,
NEW_POST,
EDIT_POST,
DELETE_POST,
GET_CATEGORIES,
GET_POST
GET_RECENT_POSTS,
GET_POST,
GET_CATEGORIES
}
1 change: 0 additions & 1 deletion src/lib/envUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export function getEnv(key: string) {
}
} catch (e:any) {
throw new Error(e)
// logUtil.logWarn(e)
}

return env
Expand Down
Loading

1 comment on commit 95d0444

@vercel
Copy link

@vercel vercel bot commented on 95d0444 Sep 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.