Skip to content

Commit 21cd5ca

Browse files
author
hoang.tran12
committed
fix link button
1 parent 5a9ac26 commit 21cd5ca

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

popup/index.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import config from "../config.js";
22
import { allScripts } from "../scripts/index.js";
3-
import { isTitle, refreshSpecialTabs, specialTabs, tabs } from "./tabs.js";
3+
import {
4+
isFunc,
5+
isLink,
6+
isTitle,
7+
refreshSpecialTabs,
8+
specialTabs,
9+
tabs,
10+
} from "./tabs.js";
411
import { getFlag, t, toggleLang } from "./helpers/lang.js";
512
import { checkBlackWhiteList, runScriptInCurrentTab } from "./helpers/utils.js";
613
import {
@@ -125,9 +132,9 @@ function createScriptButton(script, isFavorite = false) {
125132
const button = document.createElement("button");
126133
button.className = "tooltip";
127134

128-
if (script.func && typeof script.func === "function") {
135+
if (isFunc(script)) {
129136
button.onclick = () => runScript(script);
130-
} else if (script.link && typeof script.link === "string") {
137+
} else if (isLink(script)) {
131138
button.onclick = () => window.open(script.link);
132139
} else {
133140
button.onclick = () => alert("empty script");
@@ -181,17 +188,19 @@ function createScriptButton(script, isFavorite = false) {
181188
button.appendChild(title);
182189

183190
// add to favorite button
184-
const addFavoriteBtn = document.createElement("i");
185-
addFavoriteBtn.className = isFavorite
186-
? "fa-solid fa-star star active"
187-
: "fa-regular fa-star star";
188-
addFavoriteBtn.onclick = (e) => {
189-
e.stopPropagation();
190-
e.preventDefault();
191-
192-
favoriteScriptsSaver.toggle(script).then(createTabs);
193-
};
194-
button.appendChild(addFavoriteBtn);
191+
if (isFunc(script)) {
192+
const addFavoriteBtn = document.createElement("i");
193+
addFavoriteBtn.className = isFavorite
194+
? "fa-solid fa-star star active"
195+
: "fa-regular fa-star star";
196+
addFavoriteBtn.onclick = (e) => {
197+
e.stopPropagation();
198+
e.preventDefault();
199+
200+
favoriteScriptsSaver.toggle(script).then(createTabs);
201+
};
202+
button.appendChild(addFavoriteBtn);
203+
}
195204

196205
// tooltip
197206
const tooltip = document.createElement("span");

popup/styles/style.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ a:hover {
9696
margin-bottom: 10px;
9797
}
9898

99-
.content .favorite {
100-
transform: scale(0);
101-
transition: all .2s;
102-
}
103-
10499
.content button {
105100
display: block;
106101
border: none;

popup/tabs.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { addBadge, BADGES } from "./helpers/badge.js";
55
import { favoriteScriptsSaver, recentScriptsSaver } from "./helpers/storage.js";
66

77
const createTitle = (en, vi) => ({ name: { en, vi } });
8-
const isTitle = (script) => !script.func && !script.file && !script.link;
8+
const isFunc = (script) => script.func && typeof script.func === "function";
9+
const isLink = (script) => script.link && typeof script.link === "string";
10+
const isTitle = (script) => !isFunc(script) && !isLink(script);
911

1012
const specialTabs = [
1113
{
@@ -184,6 +186,7 @@ const tabs = [
184186
),
185187
addBadge(
186188
{
189+
icon: "https://cdn4.iconfinder.com/data/icons/social-messaging-ui-color-shapes-2-free/128/social-facebook-square2-256.png",
187190
name: { en: "FB Media Downloader", vi: "FB Media Downloader" },
188191
description: {
189192
en: "Tool download media from facebook automatic",
@@ -193,17 +196,6 @@ const tabs = [
193196
},
194197
BADGES.hot
195198
),
196-
{
197-
name: {
198-
en: "Relational Database Tools",
199-
vi: "Giải toán môn PTTK HTTT",
200-
},
201-
description: {
202-
en: "Solve problems in relational data field",
203-
vi: "Tính toán các vấn đề trong môn phân tích thiết kế hệ thống thông tin",
204-
},
205-
link: "https://github.com/HoangTran0410/PTTK",
206-
},
207199
{ name: { en: "--- Extensions ---", vi: "--- Extensions hay ---" } },
208200
{
209201
icon: "https://lh3.googleusercontent.com/2GdtpZt9NWFkfrfLZnWL2gM2UdCOsgpQhhdxSx4wPw5Iz10NcT433g3iHyAAZ8J-ZCyz3gwLKR1kJQC0PidRVKKJ1Ws=w128-h128-e365-rj-sc0x00ffffff",
@@ -378,4 +370,4 @@ async function refreshSpecialTabs() {
378370
if (avaiab) avaiab.scripts = await getAvailableScriptsInTabs(tabs);
379371
}
380372

381-
export { isTitle, refreshSpecialTabs, tabs, specialTabs };
373+
export { isTitle, isFunc, isLink, refreshSpecialTabs, tabs, specialTabs };

0 commit comments

Comments
 (0)