From 2c7433472d712c16f79d397f414031740099b5e6 Mon Sep 17 00:00:00 2001
From: wangyantong2000 <18745996292@163.com>
Date: Mon, 11 Nov 2024 19:36:28 +0800
Subject: [PATCH 1/2] feat: add fast-pr button position
---
public_configs/fast-pr-url-rules.cjs | 20 +++++++++---
.../ContentScripts/features/fast-pr/index.tsx | 31 +++++++++++++++++--
.../ContentScripts/features/fast-pr/view.tsx | 8 +++--
3 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/public_configs/fast-pr-url-rules.cjs b/public_configs/fast-pr-url-rules.cjs
index 8c6887a5..d97ad617 100644
--- a/public_configs/fast-pr-url-rules.cjs
+++ b/public_configs/fast-pr-url-rules.cjs
@@ -6,6 +6,8 @@ const urlRules = [
const repoName = 'X-lab2017/open-digger-website';
const branch = 'master';
const platform = 'Github';
+ const horizontalRatio=0.95;
+ const verticalRatio=0.5;
let filePath = '';
if (!url.startsWith(baseUrl)) return null;
let i18n = null;
@@ -23,7 +25,7 @@ const urlRules = [
} else if (docPath.startsWith('blog/')) {
filePath = `${i18n != null ? `i18n/${i18n}docusaurus-plugin-content-` : ''}${docPath}/index.mdx`;
}
- return { filePath, repoName, branch, platform };
+ return { filePath, repoName, branch, platform,horizontalRatio,verticalRatio };
},
tests: [
[
@@ -60,10 +62,12 @@ const urlRules = [
const repoName = 'X-lab2017/oss101-bok';
const branch = 'master';
const platform = 'Github';
+ const horizontalRatio=0.95;
+ const verticalRatio=0.5;
if (!url.startsWith(baseUrl)) return null;
const docPath = url.replace(baseUrl, '').split('#')[0];
const filePath = `docs/textbook/${docPath.slice(0, -1)}.md`;
- return { filePath, repoName, branch, platform };
+ return { filePath, repoName, branch, platform,horizontalRatio,verticalRatio };
},
},
{
@@ -73,10 +77,12 @@ const urlRules = [
const repoName = 'wangyantong2000/docwebsite';
const branch = 'main';
const platform = 'Gitee';
+ const horizontalRatio=0.95;
+ const verticalRatio=0.5;
if (!url.startsWith(baseUrl)) return null;
const docPath = url.replace(baseUrl, '').split('#')[0];
const filePath = `docs/textbooks/${docPath}index.md`;
- return { filePath, repoName, branch, platform };
+ return { filePath, repoName, branch, platform,horizontalRatio,verticalRatio };
},
},
{
@@ -86,12 +92,14 @@ const urlRules = [
const repoName = 'kaiyuanshe/oss-book';
const branch = 'main';
const platform = 'Github';
+ const horizontalRatio=0.95;
+ const verticalRatio=0.95;
if (!url.startsWith(baseUrl)) return null;
let docPath = url.replace(baseUrl, '').split('#')[0];
if (docPath.startsWith('slide')) return null;
docPath = docPath.replace('.html', '');
const filePath = `src/${docPath}.md`;
- return { filePath, repoName, branch, platform };
+ return { filePath, repoName, branch, platform,horizontalRatio,verticalRatio };
},
tests: [
['https://kaiyuanshe.github.io/oss-book/Enterprise-and-Open-Source.html', 'src/Enterprise-and-Open-Source.md'],
@@ -110,6 +118,8 @@ const urlRules = [
const repoName = 'kwdb/docs';
let branch = 'master';
const platform = 'Gitee';
+ const horizontalRatio=0.95;
+ const verticalRatio=0.95;
if (!url.startsWith(baseUrl)) return null;
let docPath = url.replace(baseUrl, '').split('#')[0].replace('.html', '');
function extractVersion(str) {
@@ -132,7 +142,7 @@ const urlRules = [
}
}
const filePath = `${docPath}.md`;
- return { filePath, repoName, branch, platform };
+ return { filePath, repoName, branch, platform,horizontalRatio,verticalRatio };
},
tests: [
[
diff --git a/src/pages/ContentScripts/features/fast-pr/index.tsx b/src/pages/ContentScripts/features/fast-pr/index.tsx
index 336f7ddd..60d45a02 100644
--- a/src/pages/ContentScripts/features/fast-pr/index.tsx
+++ b/src/pages/ContentScripts/features/fast-pr/index.tsx
@@ -11,11 +11,28 @@ interface MatchedUrl {
repoName: string;
branch: string;
platform: string;
+ horizontalRatio: number;
+ verticalRatio: number;
}
-const renderTo = (container: HTMLElement, filePath: string, repoName: string, branch: string, platform: string) => {
+const renderTo = (
+ container: HTMLElement,
+ filePath: string,
+ repoName: string,
+ branch: string,
+ platform: string,
+ horizontalRatio: number,
+ verticalRatio: number
+) => {
createRoot(container).render(
-
+
);
};
@@ -27,7 +44,15 @@ const init = async (matchedUrl: MatchedUrl | null) => {
if (matchedUrl) {
const container = document.createElement('div');
container.id = featureId;
- renderTo(container, matchedUrl.filePath, matchedUrl.repoName, matchedUrl.branch, matchedUrl.platform);
+ renderTo(
+ container,
+ matchedUrl.filePath,
+ matchedUrl.repoName,
+ matchedUrl.branch,
+ matchedUrl.platform,
+ matchedUrl.horizontalRatio,
+ matchedUrl.verticalRatio
+ );
document.body.appendChild(container);
}
};
diff --git a/src/pages/ContentScripts/features/fast-pr/view.tsx b/src/pages/ContentScripts/features/fast-pr/view.tsx
index 016fa824..cb1edec4 100644
--- a/src/pages/ContentScripts/features/fast-pr/view.tsx
+++ b/src/pages/ContentScripts/features/fast-pr/view.tsx
@@ -15,8 +15,10 @@ interface Props {
originalRepo: string;
branch: string;
platform: string;
+ horizontalRatio: number;
+ verticalRatio: number;
}
-const View = ({ filePath, originalRepo, branch, platform }: Props) => {
+const View = ({ filePath, originalRepo, branch, platform, horizontalRatio, verticalRatio }: Props) => {
const [giteeToken, setGiteeToken] = useState('');
const [githubToken, setGithubToken] = useState('');
const [options, setOptions] = useState(defaults);
@@ -128,8 +130,8 @@ const View = ({ filePath, originalRepo, branch, platform }: Props) => {
// Set the initial position to the middle-right of the screen when the component loads
useEffect(() => {
- const initialX = window.innerWidth - buttonSize - padding; // 24px from the right of the screen
- const initialY = window.innerHeight / 2 - buttonSize / 2; // Center vertically
+ const initialX = (window.innerWidth - buttonSize) * horizontalRatio;
+ const initialY = (window.innerHeight - buttonSize) * verticalRatio;
setPosition({ x: initialX, y: initialY });
}, []);
// Record the starting position when the mouse is pressed
From db8853271f7e04b4d3d193871b4b9bc774b2d4d0 Mon Sep 17 00:00:00 2001
From: wangyantong2000 <18745996292@163.com>
Date: Mon, 11 Nov 2024 21:34:29 +0800
Subject: [PATCH 2/2] fix: kaiwuDB load
---
src/pages/ContentScripts/features/fast-pr/index.tsx | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/pages/ContentScripts/features/fast-pr/index.tsx b/src/pages/ContentScripts/features/fast-pr/index.tsx
index 60d45a02..a719c689 100644
--- a/src/pages/ContentScripts/features/fast-pr/index.tsx
+++ b/src/pages/ContentScripts/features/fast-pr/index.tsx
@@ -2,7 +2,6 @@ import React from 'react';
import { createRoot } from 'react-dom/client';
import features from '../../../../feature-manager';
import View from './view';
-import { handleMessage } from './handleMessage';
import i18n from '../../../../helpers/i18n';
const featureId = features.getFeatureID(import.meta.url);
const t = i18n.t;
@@ -58,7 +57,7 @@ const init = async (matchedUrl: MatchedUrl | null) => {
};
const observeUrlChanges = () => {
let lastUrl = window.location.href;
- const observer = new MutationObserver(() => {
+ const checkUrlChange = () => {
const currentUrl = window.location.href;
if (currentUrl !== lastUrl) {
lastUrl = currentUrl;
@@ -71,13 +70,13 @@ const observeUrlChanges = () => {
iframe.contentWindow.postMessage({ command: 'matchUrl', url: currentUrl }, '*');
}
}
- });
-
- //Observe changes in the main body of the document
+ };
+ const observer = new MutationObserver(checkUrlChange);
observer.observe(document.body, {
childList: true,
subtree: true,
});
+ setInterval(checkUrlChange, 1000);
};
window.addEventListener('message', (event: MessageEvent) => {