This repository was archived by the owner on Sep 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
117 lines (109 loc) · 2.57 KB
/
background.js
File metadata and controls
117 lines (109 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import E from "/popup/common/init.js";
const e = new E();
chrome.commands.onCommand.addListener(function (command) {
e.getAccessToken().then((t) => {
e.getActiveDevice(t).then((d) => {
if (!d) return;
switch (command) {
case "toggle_play":
e.getCurrentPlayback(t).then((current) => {
current.is_playing ? e.pause(t, d.id) : e.play(t, d.id);
});
break;
case "skip_backwards":
e.prev(t, d.id);
break;
case "skip_forwards":
e.next(t, d.id);
break;
default:
break;
}
});
});
});
chrome.contextMenus.create({
id: "open_spotify_in_new_tab",
title: "🎧 Open Spotify In Tab",
contexts: ["page", "browser_action"],
});
chrome.contextMenus.create({
id: "open_spotify_in_new_window",
title: "🎵 Open Spotify In Window",
contexts: ["browser_action"],
});
chrome.contextMenus.onClicked.addListener(function (data) {
switch (data.menuItemId) {
case "open_spotify_in_new_tab":
openInTab();
break;
case "open_spotify_in_new_window":
openInWindow();
break;
case "spotify_device_info":
break;
}
});
chrome.runtime.onInstalled.addListener(function ({ OnInstalledReason }) {
if (OnInstalledReason == "install") {
openInTab();
chrome.storage.sync.set({ onstart: false, launchwindow: false });
}
});
chrome.runtime.onStartup.addListener(function () {
chrome.storage.sync.get(["onstart", "launchwindow"], function (data) {
if (data.onstart) {
if (data.launchwindow) {
openInWindow();
return;
}
openInTab();
return;
}
});
});
function openInTab() {
chrome.tabs.query(
{
currentWindow: true,
url: "https://open.spotify.com/*",
},
function (tabs) {
if (tabs.length > 0) {
chrome.tabs.update(tabs[0].id, {
active: true,
});
return;
}
chrome.tabs.create({
url: "https://open.spotify.com/",
active: true,
selected: true,
});
}
);
}
function openInWindow() {
chrome.windows.getAll(
{
populate: true,
windowTypes: ["popup"],
},
function (arr) {
var e = arr.find((e) => {
return e.tabs[0].url.match("https://open.spotify.com/*");
});
if (e) {
chrome.windows.update(e.id, { focused: true });
return;
}
chrome.windows.create({
url: "https://open.spotify.com/",
focused: true,
type: "popup",
width: 1000,
height: 1000,
});
}
);
}