Skip to content

Commit 7dee7b9

Browse files
authored
Merge pull request #9 from Turtle-Hwan/feat/samehost
Feat/samehost
2 parents b9bd15d + 1f755b4 commit 7dee7b9

File tree

8 files changed

+112
-71
lines changed

8 files changed

+112
-71
lines changed

dist/index.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

+35-35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/manifest.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 3,
33
"name": "LinKU",
44
"description": "건국대학교 학생들을 위한 건국대, 건대 교내외 페이지 모음 링쿠, LinKU",
5-
"version": "1.1.45",
5+
"version": "1.2.10",
66
"action": {
77
"default_popup": "index.html"
88
},
@@ -12,5 +12,9 @@
1212
"48": "assets/icon48.png",
1313
"64": "assets/icon64.png",
1414
"128": "assets/icon128.png"
15-
}
15+
},
16+
"permissions": [
17+
"activeTab",
18+
"scripting"
19+
]
1620
}

public/manifest.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 3,
33
"name": "LinKU",
44
"description": "건국대학교 학생들을 위한 건국대, 건대 교내외 페이지 모음 링쿠, LinKU",
5-
"version": "1.1.45",
5+
"version": "1.2.10",
66
"action": {
77
"default_popup": "index.html"
88
},
@@ -12,5 +12,9 @@
1212
"48": "assets/icon48.png",
1313
"64": "assets/icon64.png",
1414
"128": "assets/icon128.png"
15-
}
15+
},
16+
"permissions": [
17+
"activeTab",
18+
"scripting"
19+
]
1620
}

src/components/LinkGroup.tsx

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Search, Settings } from "lucide-react";
22
import { Input } from "@/components/ui/input";
33
import { LinkuLogoSvg } from "@/assets";
4-
import React, { Suspense } from "react";
4+
import React, { Suspense, use } from "react";
55
import ImageCarousel from "./ImageCarousel";
66
import { LinkList, LinkList_long } from "@/constants/LinkList";
7-
// import { getCurrentTab } from "@/utils/chrome";
7+
import { getCurrentTab } from "@/utils/chrome";
88

99
const LinkGroup = () => {
1010
return (
@@ -64,12 +64,11 @@ const Header = () => {
6464
);
6565
};
6666

67+
const tabPromise = getCurrentTab();
68+
6769
const Grid = () => {
68-
// const HOSTNAME = "localhost";
69-
// console.log(window.location.hostname);
70-
// getCurrentTab().then((tab) => {
71-
// console.log(tab);
72-
// });
70+
const tab = use(tabPromise);
71+
const tabHostname = new URL(tab.url ?? "").hostname;
7372

7473
return (
7574
<div className="Link__Grid grid grid-cols-6 gap-4 p-4">
@@ -80,11 +79,7 @@ const Grid = () => {
8079
<LinkGroup.GridItemLong key={idx} item={item} />
8180
))}
8281

83-
{/* {idx === 7 && <LinkGroup.GridItemSameHost key={idx} item={item} />}
84-
<LinkGroup.GridItem key={idx} item={item} /> */}
85-
86-
{new URL(item.link).hostname === window.location.hostname &&
87-
item.samehost ? (
82+
{new URL(item.link).hostname === tabHostname && item.samehost ? (
8883
<LinkGroup.GridItemSameHost key={idx} item={item} />
8984
) : (
9085
<LinkGroup.GridItem key={idx} item={item} />
@@ -143,8 +138,11 @@ const GridItemSameHost = ({ item }) => {
143138
console.log(item);
144139
return (
145140
<div className="col-span-2 flex flex-row items-center justify-start rounded-lg hover:bg-gray-100 transition-colors border border-gray-200">
146-
<button className="w-full h-full py-2 px-4 bg-[#00913A] text-white rounded-lg hover:bg-[#007a30] transition-colors cursor-pointer">
147-
{item.samehost}
141+
<button
142+
className="w-full h-full py-2 px-4 bg-[#00913A] text-white rounded-lg hover:bg-[#007a30] transition-colors cursor-pointer text-sm"
143+
onClick={item.samehost.onClick}
144+
>
145+
{item.samehost.content}
148146
</button>
149147

150148
{/* <button

src/constants/LinkList.ts

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { HelloLmsPng } from "@/assets";
2+
import { executeScript, getCurrentTab, updateTabUrl } from "@/utils/chrome";
3+
import { sugangRefreshBtn } from "@/utils/sugang";
24
import {
35
BellRing,
46
University,
@@ -23,6 +25,12 @@ export const LinkList = [
2325
icon: University,
2426
label: "홈페이지",
2527
link: "https://www.konkuk.ac.kr/konkuk/index.do",
28+
samehost: {
29+
content: "상용 SW 대여",
30+
onClick: () => {
31+
updateTabUrl("https://grad.konkuk.ac.kr/kuinc/15905/subview.do");
32+
},
33+
},
2634
},
2735
{
2836
icon: BellRing,
@@ -37,14 +45,40 @@ export const LinkList = [
3745
},
3846

3947
//
40-
{ icon: Trophy, label: "위인전", link: "https://wein.konkuk.ac.kr" },
48+
{
49+
icon: Trophy,
50+
label: "위인전",
51+
link: "https://wein.konkuk.ac.kr",
52+
samehost: {
53+
content: "K-Cube 대여",
54+
onClick: () => {
55+
updateTabUrl(
56+
"https://wein.konkuk.ac.kr/ptfol/cmnt/cube/findCubeResveStep1.do"
57+
);
58+
},
59+
},
60+
},
4161

42-
{ icon: Clock, label: "수강신청", link: "https://sugang.konkuk.ac.kr" },
62+
{
63+
icon: Clock,
64+
label: "수강신청",
65+
link: "https://sugang.konkuk.ac.kr",
66+
samehost: {
67+
content: "수강인원 새로고침",
68+
onClick: () => {
69+
getCurrentTab().then((tab) => {
70+
executeScript(tab.id ?? 0, sugangRefreshBtn);
71+
});
72+
},
73+
},
74+
},
4375
{
4476
icon: MapPinned,
4577
label: "캠퍼스맵",
4678
link: "https://research.konkuk.ac.kr/campusMap/konkuk/view.do#this",
47-
samehost: "종강 == 법학관",
79+
samehost: {
80+
content: "종강 == 법학관",
81+
},
4882
},
4983

5084
//
@@ -112,5 +146,3 @@ export const LinkList_long = [
112146
link: "https://library.konkuk.ac.kr/",
113147
},
114148
];
115-
116-
// 정보통신처 상용 소프트웨어 무료 대여 https://grad.konkuk.ac.kr/kuinc/15905/subview.do

src/utils/chrome.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
1-
export async function getCurrentTab() {
2-
const queryOptions = { active: true, lastFocusedWindow: true };
1+
// activeTab permission
2+
export const getCurrentTab = async () => {
3+
const queryOptions = { active: true, currentWindow: true };
34
const [tab] = await chrome.tabs.query(queryOptions);
45
return tab;
5-
}
6+
};
67

7-
export async function executeScript(tabId: number, func: () => void) {
8+
export const updateTabUrl = (url: string) => {
9+
chrome.tabs.update({ url: url });
10+
};
11+
12+
export const executeScript = async (tabId: number, func: () => void) => {
813
try {
914
const result = await chrome.scripting.executeScript({
1015
target: { tabId, allFrames: true },
11-
func,
16+
func: func,
1217
});
13-
console.log("Injection Success", result);
18+
// console.log("Injection Success", result);
1419
return result;
1520
} catch (err) {
1621
console.log("err", err);
1722
throw err;
1823
}
19-
}
24+
};
2025

21-
export async function executeScriptFile(tabId: number, files: string[]) {
26+
export const executeScriptFile = async (tabId: number, files: string[]) => {
2227
try {
2328
const result = await chrome.scripting.executeScript({
2429
target: { tabId, allFrames: true },
2530
files,
2631
});
27-
console.log("Injection Success", result);
32+
// console.log("Injection Success", result);
2833
return result;
2934
} catch (err) {
3035
console.log("err", err);
3136
throw err;
3237
}
33-
}
38+
};

src/utils/sugang.ts

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ export function sugangRefreshBtn() {
22
const refreshBtn = document.querySelectorAll<HTMLButtonElement>(
33
"#btnRefresh.btn-sm.btn-sub.btn-mode"
44
);
5-
console.log("sugangRefresh Btn func : ", refreshBtn);
6-
75
refreshBtn.forEach((btn) => {
86
btn.click();
97
});

0 commit comments

Comments
 (0)