Skip to content

Commit 0f59d2a

Browse files
committed
view script source + youtube popup
1 parent c3ff4ce commit 0f59d2a

File tree

13 files changed

+607
-6
lines changed

13 files changed

+607
-6
lines changed

popup/helpers/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { t } from "./lang.js";
2+
13
export const getTabId = async () => {
24
let tabArray = await chrome.tabs.query({ currentWindow: true, active: true });
35
return tabArray[0].id;
@@ -44,4 +46,17 @@ export async function getCurrentURL() {
4446
return new URL(url);
4547
}
4648

49+
export function viewScriptSource(script) {
50+
localStorage.viewScriptSource_sharedData = JSON.stringify({
51+
name: t(script.name),
52+
description: t(script.description),
53+
source: script.func?.toString(),
54+
});
4755

56+
chrome.windows.create({
57+
url: chrome.runtime.getURL("viewScriptSource/index.html"),
58+
type: "popup",
59+
height: 450,
60+
width: 700,
61+
});
62+
}

popup/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { allScripts } from "../scripts/index.js";
22
import { checkForUpdate } from "./helpers/checkForUpdate.js";
33
import { getFlag, t, toggleLang } from "./helpers/lang.js";
4-
import { runScriptInCurrentTab } from "./helpers/utils.js";
4+
import { viewScriptSource, runScriptInCurrentTab } from "./helpers/utils.js";
55
import { checkBlackWhiteList } from "./helpers/scriptHelpers.js";
66
import { openModal } from "./helpers/modal.js";
77
import {
@@ -190,13 +190,18 @@ function createScriptButton(script, isFavorite = false) {
190190
if (isFunc(script)) {
191191
// add to favorite button
192192
const addFavoriteBtn = document.createElement("i");
193-
addFavoriteBtn.title = t({
194-
en: "Add to farovite",
195-
vi: "Thêm vào yêu thích",
196-
});
197193
addFavoriteBtn.className = isFavorite
198194
? "fa-solid fa-star star active"
199195
: "fa-regular fa-star star";
196+
addFavoriteBtn.title = isFavorite
197+
? t({
198+
en: "Remove from favorite",
199+
vi: "Xoá khỏi yêu thích",
200+
})
201+
: t({
202+
en: "Add to farovite",
203+
vi: "Thêm vào yêu thích",
204+
});
200205
addFavoriteBtn.onclick = (e) => {
201206
e.stopPropagation();
202207
e.preventDefault();
@@ -214,7 +219,9 @@ function createScriptButton(script, isFavorite = false) {
214219
viewSourceBtn.onclick = (e) => {
215220
e.stopPropagation();
216221
e.preventDefault();
217-
openModal(t(script.name), `<pre>${script.func?.toString()}</pre>`);
222+
223+
viewScriptSource(script);
224+
// openModal(t(script.name), `<pre>${script.func?.toString()}</pre>`);
218225
};
219226
button.appendChild(viewSourceBtn);
220227
}

popup/tabs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const tabs = [
8989
scripts: [
9090
s.youtube_downloadVideo,
9191
s.pictureInPicture,
92+
s.youtube_popupPlayer,
9293
s.youtube_toggleLight,
9394
s.youtube_viewDislikes,
9495
],

scripts/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import insta_enableDownloadImage from "./insta_enableDownloadImage.js";
8080
import youtube_viewDislikes from "./youtube_viewDislikes.js";
8181
import downDetector from "./downDetector.js";
8282
import fb_getTokenFfb from "./fb_getTokenFfb.js";
83+
import youtube_popupPlayer from "./youtube_popupPlayer.js";
8384

8485
// inject badges
8586
const allScripts = {
@@ -166,6 +167,7 @@ const allScripts = {
166167
youtube_viewDislikes: addBadge(youtube_viewDislikes, BADGES.new),
167168
downDetector: addBadge(downDetector, BADGES.new),
168169
fb_getTokenFfb: addBadge(fb_getTokenFfb, BADGES.new),
170+
youtube_popupPlayer: addBadge(youtube_popupPlayer, BADGES.new),
169171
};
170172

171173
// inject id to all scripts

scripts/youtube_popupPlayer.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export default {
2+
icon: 'https://lh3.googleusercontent.com/6PBcKpsoS15e2SUqMi6_KGBHsnvUdaRrRYXkHM3zkn5Zzj8TAEJp1_RtykaCfn1DCmyH9PJOKHrMbmtAOnQqtAU8aLs=w128-h128-e365-rj-sc0x00ffffff',
3+
name: {
4+
en: "Youtube popup player",
5+
vi: "Xem youtube trong popup",
6+
},
7+
description: {
8+
en: "Open current youtube video in new popup player",
9+
vi: "Xem video youtube hiện tại trong cửa sổ popup mới",
10+
},
11+
blackList: [],
12+
whiteList: ["www.youtube.com", "m.youtube.com"],
13+
func: function () {
14+
const urlObject = new URL(location.href);
15+
const key = urlObject.searchParams.get("v");
16+
const list = urlObject.searchParams.get("list");
17+
18+
window.open(
19+
`https://www.youtube.com/pop-up-player/${key}` +
20+
(list ? `?list=${list}&efyt_playlist=true` : ""),
21+
"",
22+
"toolbar=no,location=no,directories=no,status=no, menubar=no,height=400,width=600"
23+
);
24+
},
25+
};

viewScriptSource/index.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>Document</title>
9+
10+
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/default.min.css">
11+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script> -->
12+
<link rel="stylesheet" href="./libs/isbl-editor-dark.min.css">
13+
<script src="libs/highlight.min.js"></script>
14+
<script src="libs/javascript.min.js"></script>
15+
16+
<link rel="stylesheet" href="style.css">
17+
<script src="main.js"></script>
18+
</head>
19+
20+
<body>
21+
<button type="button" id="copy-btn">Copy source code</button>
22+
23+
<pre>
24+
<code class="language-javascript"></code>
25+
</pre>
26+
</body>
27+
28+
</html>

viewScriptSource/libs/default.min.css

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)