Skip to content

Commit 789bda2

Browse files
committed
✨ 根据安装url生成安装主页按钮 #134
1 parent 81a589e commit 789bda2

File tree

6 files changed

+64
-3
lines changed

6 files changed

+64
-3
lines changed

build/assets/logo/github.png

958 Bytes
Loading

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scriptcat",
3-
"version": "0.11.4",
3+
"version": "0.12.0",
44
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
55
"author": "CodFrm",
66
"license": "GPLv3",

src/app/const.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const ExtVersion = "0.11.4";
1+
export const ExtVersion = "0.12.0";
22

33
export const ExtServer = "https://ext.scriptcat.org/";
44

src/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "ScriptCat",
4-
"version": "0.11.4",
4+
"version": "0.12.0",
55
"author": "CodFrm",
66
"description": "脚本猫,一个用户脚本管理器,支持后台脚本、定时脚本、页面脚本,可编写脚本每天帮你自动处理事务.",
77
"options_ui": {

src/pages/options/routes/ScriptList.tsx

+60
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
IconCode,
3131
IconCommon,
3232
IconEdit,
33+
IconGithub,
3334
IconHome,
3435
IconLink,
3536
IconMenu,
@@ -75,6 +76,60 @@ import { scriptListSort } from "./utils";
7576

7677
type ListType = Script & { loading?: boolean };
7778

79+
// 安装url转home主页
80+
function installUrlToHome(installUrl: string) {
81+
try {
82+
// 解析scriptcat
83+
if (installUrl.indexOf("scriptcat.org") !== -1) {
84+
const id = installUrl.split("/")[5];
85+
return (
86+
<Button
87+
type="text"
88+
iconOnly
89+
size="small"
90+
target="_blank"
91+
href={`https://scriptcat.org/script-show-page/${id}`}
92+
>
93+
<img width={16} height={16} src="/assets/logo.png" alt="" />
94+
</Button>
95+
);
96+
}
97+
if (installUrl.indexOf("greasyfork.org") !== -1) {
98+
const id = installUrl.split("/")[4];
99+
return (
100+
<Button
101+
type="text"
102+
iconOnly
103+
size="small"
104+
target="_blank"
105+
href={`https://greasyfork.org/scripts/${id}`}
106+
>
107+
<img width={16} height={16} src="/assets/logo/gf.png" alt="" />
108+
</Button>
109+
);
110+
}
111+
if (installUrl.indexOf("raw.githubusercontent.com") !== -1) {
112+
const repo = `${installUrl.split("/")[3]}/${installUrl.split("/")[4]}`;
113+
return (
114+
<Button
115+
type="text"
116+
iconOnly
117+
size="small"
118+
target="_blank"
119+
href={`https://github.com/${repo}`}
120+
style={{
121+
color: "var(--color-text-1)",
122+
}}
123+
icon={<IconGithub />}
124+
/>
125+
);
126+
}
127+
} catch (e) {
128+
// ignore error
129+
}
130+
return undefined;
131+
}
132+
78133
function getValues(script: Script) {
79134
const { config } = script;
80135
return (IoC.instance(ValueManager) as ValueManager)
@@ -392,8 +447,13 @@ function ScriptList() {
392447
key: "home",
393448
width: 100,
394449
render(col, item: Script) {
450+
let home;
451+
if (!item.metadata.homepageurl) {
452+
home = installUrlToHome(item.downloadUrl || "");
453+
}
395454
return (
396455
<Space size="mini">
456+
{home && <Tooltip content="脚本主页">{home}</Tooltip>}
397457
{item.metadata.homepage && (
398458
<Tooltip content="脚本主页">
399459
<Button

webpack.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const config: Configuration = {
111111
{ from: `${src}/manifest.json`, to: `${dist}/ext` },
112112
{ from: `${assets}/_locales`, to: `${dist}/ext/_locales` },
113113
{ from: `${assets}/logo.png`, to: `${dist}/ext/assets` },
114+
{ from: `${assets}/logo`, to: `${dist}/ext/assets/logo` },
114115
],
115116
}),
116117
new CleanWebpackPlugin(),

0 commit comments

Comments
 (0)