-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cph
committed
Oct 8, 2024
1 parent
21edbdf
commit ce7acc0
Showing
12 changed files
with
297 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,45 @@ | ||
chrome.action.onClicked.addListener((tab) => { | ||
chrome.tabs.sendMessage(tab.id, {action: "togglePlayer"}); | ||
}); | ||
|
||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||
if (request.action === "sendAudio") { | ||
fetch('https://app102.acapp.acwing.com.cn/api/uploadAudio', { | ||
method: 'POST', | ||
body: request.formData | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
sendResponse({success: true, data: data}); | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
sendResponse({success: false, error: error.message}); | ||
}); | ||
return true; // 保持消息通道开放 | ||
} | ||
|
||
if (request.action === "addSong") { | ||
fetch('https://app102.acapp.acwing.com.cn/api/add', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(request.data) | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
sendResponse({success: true, data: data}); | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
sendResponse({success: false, error: error.message}); | ||
}); | ||
return true; // 保持消息通道开放 | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.