mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-27 08:37:49 +01:00
Release 0.0.0.4
Rate bar added Bug caused by security token resolved by removing security token Various bugs and console errors fixed More like/dislike data is now saved on scroll
This commit is contained in:
1 parent
545bd2d3eb
commit
9df69d65dd
8 files changed
+249
-148
No files matched your search
@@ -1,41 +1,61 @@
|
||||
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) => {
|
||||
sendResponse(securityToken);
|
||||
});
|
||||
// Security token causes issues if extension is reloaded/updated while several tabs are open
|
||||
// const securityToken = Math.random().toString(36).substring(2, 15);
|
||||
//
|
||||
// chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
// sendResponse(securityToken);
|
||||
// });
|
||||
|
||||
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;
|
||||
chrome.runtime.onMessageExternal.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) => {
|
||||
sendResponse(response);
|
||||
})
|
||||
.catch();
|
||||
//});
|
||||
return true;
|
||||
} else if (request.message == "send_links") {
|
||||
toSend = toSend.concat(request.videoIds.filter((x) => !sentIds.has(x)));
|
||||
if (toSend.length >= 20) {
|
||||
fetch(`${apiUrl}/votes`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(toSend),
|
||||
});
|
||||
for (const toSendUrl of toSend) {
|
||||
sentIds.add(toSendUrl);
|
||||
}
|
||||
toSend = [];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
const sentIds = new Set();
|
||||
let toSend = [];
|
||||
Reference in new issue
Block a user