mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-24 07:13:02 +01:00
Revert "Revert "Merge pull request #11 from mynovelhost/main""
This reverts commit 0a30c0ee05.
This commit is contained in:
1 parent
0a30c0ee05
commit
545bd2d3eb
4 files changed
+173
-160
No files matched your search
@@ -1,46 +1,41 @@
|
||||
const apiUrl = "https://return-youtube-dislike-api.azurewebsites.net";
|
||||
const securityToken = Math.random().toString(36).substring(2, 15);
|
||||
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
if (request.message === "get_auth_token") {
|
||||
// chrome.identity.getAuthToken({ interactive: true }, function (token) {
|
||||
// console.log(token);
|
||||
// chrome.identity.getProfileUserInfo(function (userInfo) {
|
||||
// console.log(JSON.stringify(userInfo));
|
||||
// });
|
||||
// });
|
||||
} else if (request.message === "log_off") {
|
||||
// console.log("logging off");
|
||||
// chrome.identity.clearAllCachedAuthTokens(() => console.log("logged off"));
|
||||
} else if (request.message == "set_state") {
|
||||
console.log(request);
|
||||
// chrome.identity.getAuthToken({ interactive: true }, function (token) {
|
||||
let token = "";
|
||||
fetch(`${apiUrl}/votes?videoId=${request.videoId}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
sendResponse(response);
|
||||
})
|
||||
.catch();
|
||||
//});
|
||||
return true;
|
||||
}
|
||||
sendResponse(securityToken);
|
||||
});
|
||||
|
||||
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
|
||||
if (changeInfo.status == "complete") {
|
||||
if (tab.url && tab.url.indexOf("youtube.") < 0) return;
|
||||
chrome.tabs.get(tabId, (tab) => {
|
||||
chrome.scripting.executeScript({
|
||||
target: { tabId: tab.id },
|
||||
files: ["script.js"],
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
chrome.runtime.onMessageExternal.addListener((request, sender, sendResponse) => {
|
||||
if (request.securityToken === securityToken) {
|
||||
if (request.message === "get_auth_token") {
|
||||
// chrome.identity.getAuthToken({ interactive: true }, function (token) {
|
||||
// console.log(token);
|
||||
// chrome.identity.getProfileUserInfo(function (userInfo) {
|
||||
// console.log(JSON.stringify(userInfo));
|
||||
// });
|
||||
// });
|
||||
} else if (request.message === "log_off") {
|
||||
// console.log("logging off");
|
||||
// chrome.identity.clearAllCachedAuthTokens(() => console.log("logged off"));
|
||||
} else if (request.message == "set_state") {
|
||||
// console.log(request);
|
||||
// chrome.identity.getAuthToken({ interactive: true }, function (token) {
|
||||
let token = "";
|
||||
fetch(`${apiUrl}/votes?videoId=${request.videoId}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
sendResponse(response);
|
||||
})
|
||||
.catch();
|
||||
//});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user