Skip to content

Commit 9559100

Browse files
committed
studyphim
1 parent 93473a9 commit 9559100

File tree

12 files changed

+119
-75
lines changed

12 files changed

+119
-75
lines changed

empty_script.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ export default {
2828
// run onclick in extension-popup-page context
2929
onClickExtension: () => {},
3030

31+
// run onclick in content-script context
32+
onClickContentScript: () => {},
33+
3134
// run onclick in web page context
35+
// cannot access to shared or any variable outside of webpage
3236
onClick: () => {},
3337
};
3438

popup/helpers/category.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ export const CATEGORY = {
104104
vi: `<i class="fa-brands fa-tiktok"></i> Tiktok`,
105105
},
106106
},
107-
shopee: {
108-
id: "shopee",
107+
shopping: {
108+
id: "shopping",
109109
name: {
110-
en: `<i class="fa-solid fa-cart-shopping"></i> Shopee`,
111-
vi: `<i class="fa-solid fa-cart-shopping"></i> Shopee`,
110+
en: `<i class="fa-solid fa-cart-shopping"></i> Shopping`,
111+
vi: `<i class="fa-solid fa-cart-shopping"></i> Mua sắm`,
112112
},
113113
},
114114
github: {

popup/helpers/utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import { OnClickType, ScriptType } from "../../scripts/helpers/constants.js";
2+
import { isFunction } from "../../scripts/helpers/utils.js";
3+
4+
export const canClick = (script) =>
5+
isFunction(script[OnClickType.onClick]) ||
6+
isFunction(script[OnClickType.onClickExtension]) ||
7+
isFunction(script[OnClickType.onClickContentScript]);
8+
export const canAutoRun = (script) =>
9+
ScriptType.contentScript in script || ScriptType.backgroundScript in script;
10+
export const isTitle = (script) => !(canClick(script) || canAutoRun(script));
11+
112
export async function viewScriptSource(script) {
213
localStorage.viewScriptSource_sharedData = script.id;
314

popup/index.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
Events,
32
GlobalBlackList,
43
MsgType,
54
ScriptType,
@@ -10,6 +9,7 @@ import {
109
getCurrentTab,
1110
isFunction,
1211
removeAccents,
12+
runScriptInCurrentTab,
1313
sendEventToTab,
1414
toggleActiveScript,
1515
} from "../scripts/helpers/utils.js";
@@ -22,8 +22,13 @@ import {
2222
favoriteScriptsSaver,
2323
recentScriptsSaver,
2424
} from "./helpers/storage.js";
25-
import { viewScriptSource } from "./helpers/utils.js";
26-
import { canClick, isTitle, refreshSpecialTabs, getAllTabs } from "./tabs.js";
25+
import {
26+
canAutoRun,
27+
canClick,
28+
isTitle,
29+
viewScriptSource,
30+
} from "./helpers/utils.js";
31+
import { refreshSpecialTabs, getAllTabs } from "./tabs.js";
2732
// import _ from "../md/exportScriptsToMd.js";
2833

2934
const tabDiv = document.querySelector("div.tab");
@@ -171,9 +176,17 @@ function createScriptButton(script, isFavorite = false) {
171176
const button = document.createElement("button");
172177
button.className = "tooltip";
173178
if (canClick(script)) {
174-
button.onclick = () => runScript(script, button);
179+
button.onclick = () => runScript(script);
180+
} else if (canAutoRun(script)) {
181+
button.onclick = () =>
182+
alert(
183+
t({
184+
vi: "Chức năng này tự động chạy\nTắt/Mở tự chạy bằng nút bên trái",
185+
en: "This function is Autorun\nTurn on/off autorun by click the left checkmark",
186+
})
187+
);
175188
} else {
176-
button.onclick = () => alert("empty script");
189+
alert(t({ vi: "Chức năng chưa hoàn thành", en: "Coming soon" }));
177190
}
178191

179192
// script badges
@@ -287,13 +300,14 @@ async function updateButtonChecker(script, button, val) {
287300
}
288301
}
289302

290-
async function runScript(script, button) {
303+
async function runScript(script) {
291304
let tab = await getCurrentTab();
292305
let willRun = checkBlackWhiteList(script, tab.url);
293306
if (willRun) {
294307
recentScriptsSaver.add(script);
295308
if (isFunction(script.onClickExtension)) await script.onClickExtension();
296-
if (isFunction(script.onClick))
309+
if (isFunction(script.onClick)) await runScriptInCurrentTab(script.onClick);
310+
if (isFunction(script.onClickContentScript))
297311
await sendEventToTab(tab.id, {
298312
type: MsgType.runScript,
299313
scriptId: script.id,
@@ -325,7 +339,7 @@ function initSearch() {
325339
let found = 0;
326340
let childrens = document
327341
.querySelector(".tabcontent")
328-
.querySelectorAll("button");
342+
.querySelectorAll(".buttonContainer");
329343

330344
childrens.forEach((child) => {
331345
let willShow = true;
@@ -341,7 +355,6 @@ function initSearch() {
341355
break;
342356
}
343357
}
344-
// button.style.opacity = willShow ? 1 : 0.1;
345358
child.style.display = willShow ? "block" : "none";
346359
if (willShow) found++;
347360
});

popup/tabs.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import { ScriptType } from "../scripts/helpers/constants.js";
2-
import { isFunction } from "../scripts/helpers/utils.js";
31
import { allScripts as s } from "../scripts/index.js";
42
import { CATEGORY } from "./helpers/category.js";
53
import { favoriteScriptsSaver, recentScriptsSaver } from "./helpers/storage.js";
64

75
const createTitle = (en, vi) => ({ name: { en, vi } });
8-
const canClick = (script) =>
9-
isFunction(script.onClick) || isFunction(script.onClickExtension);
10-
const isTitle = (script) =>
11-
!canClick(script) &&
12-
!(ScriptType.contentScript in script) &&
13-
!(ScriptType.backgroundScript in script);
146

157
const specialTabs = [
168
{
@@ -182,7 +174,7 @@ const tabs = [
182174
],
183175
},
184176
{
185-
...CATEGORY.shopee,
177+
...CATEGORY.shopping,
186178
scripts: [s.shopee_topVariation],
187179
},
188180
{
@@ -225,6 +217,7 @@ const tabs = [
225217
s.simpleAllowCopy,
226218
s.reEnableContextMenu,
227219
s.showHiddenFields,
220+
s.studyphim_unlimited,
228221
s.envato_previewBypass,
229222
s.viewCookies,
230223
s.removeCookies,
@@ -440,12 +433,4 @@ function getAllTabs() {
440433
return [...specialTabs, ...tabs, recommendTab];
441434
}
442435

443-
export {
444-
isTitle,
445-
canClick,
446-
refreshSpecialTabs,
447-
tabs,
448-
specialTabs,
449-
recommendTab,
450-
getAllTabs,
451-
};
436+
export { refreshSpecialTabs, tabs, specialTabs, recommendTab, getAllTabs };

scripts/content-scripts/document_start.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
(async () => {
2222
const { allScripts } = await import("../index.js");
23-
const { MsgType, Events, ScriptType } = await import(
23+
const { MsgType, Events, ScriptType, OnClickType } = await import(
2424
"../helpers/constants.js"
2525
);
2626
const { runAllScriptWithEventType, sendEventToBackground, isFunction } =
@@ -49,9 +49,9 @@
4949
let scriptId = message.scriptId;
5050
if (
5151
scriptId in allScripts &&
52-
isFunction(allScripts[scriptId].onClick)
52+
isFunction(allScripts[scriptId][OnClickType.onClickContentScript])
5353
) {
54-
allScripts[scriptId].onClick();
54+
allScripts[scriptId][OnClickType.onClickContentScript]();
5555
console.log("> Run script " + scriptId);
5656
}
5757
break;

scripts/content-scripts/scripts/studyphim.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

scripts/fb_toggleLight.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
},
1717
},
1818

19-
onClick: function () {
19+
onClickContentScript: function () {
2020
shared.toggleLight();
2121
},
2222
};

scripts/fb_toggleNewFeed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
},
1717
},
1818

19-
onClick: async function () {
19+
onClickContentScript: async function () {
2020
shared.toggleNewFeed();
2121
},
2222
};

scripts/helpers/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ export const ScriptType = {
77
backgroundScript: "backgroundScript",
88
};
99

10+
export const OnClickType = {
11+
onClick: "onClick",
12+
onClickExtension: "onClickExtension",
13+
onClickContentScript: "onClickContentScript",
14+
};
15+
1016
export const Events = {
1117
document_start: "document_start",
1218
document_idle: "document_idle",

0 commit comments

Comments
 (0)