mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-03 11:21:20 +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
+32
-19
No files matched your search
@@ -1,6 +1,12 @@
|
||||
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);
|
||||
});
|
||||
|
||||
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);
|
||||
@@ -12,7 +18,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
// console.log("logging off");
|
||||
// chrome.identity.clearAllCachedAuthTokens(() => console.log("logged off"));
|
||||
} else if (request.message == "set_state") {
|
||||
console.log(request);
|
||||
// console.log(request);
|
||||
// chrome.identity.getAuthToken({ interactive: true }, function (token) {
|
||||
let token = "";
|
||||
fetch(`${apiUrl}/votes?videoId=${request.videoId}`, {
|
||||
@@ -31,16 +37,5 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
//});
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
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"],
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
chrome.runtime.sendMessage({}, (securityToken) => {
|
||||
var script = document.createElement('script');
|
||||
script.setAttribute("security-token", securityToken);
|
||||
script.setAttribute("extension-id", chrome.runtime.id);
|
||||
script.src = chrome.runtime.getURL('script.js');
|
||||
script.onload = function() {
|
||||
this.remove();
|
||||
};
|
||||
(document.head || document.documentElement).appendChild(script);
|
||||
});
|
||||
@@ -6,7 +6,6 @@
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
},
|
||||
"permissions": ["activeTab", "scripting"],
|
||||
"host_permissions": ["*://*.youtube.com/*"],
|
||||
"action": {
|
||||
"default_popup": "popup.html"
|
||||
@@ -19,7 +18,16 @@
|
||||
{
|
||||
"matches": ["*://*.youtube.com/*"],
|
||||
"js": ["content-script.js"],
|
||||
"run_at": "document_idle"
|
||||
"run_at": "document_start"
|
||||
}
|
||||
],
|
||||
"externally_connectable": {
|
||||
"matches": ["*://*.youtube.com/*"]
|
||||
},
|
||||
"web_accessible_resources": [
|
||||
{
|
||||
"resources": ["script.js"],
|
||||
"matches": ["*://*.youtube.com/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
(function(securityToken, extensionId) {
|
||||
function getButtons() {
|
||||
return document
|
||||
.getElementById("menu-container")
|
||||
@@ -47,8 +48,8 @@ function setDislikes(dislikesCount) {
|
||||
}
|
||||
|
||||
function setState() {
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
chrome.runtime.sendMessage(extensionId, {
|
||||
securityToken: securityToken,
|
||||
message: "set_state",
|
||||
videoId: getVideoId(),
|
||||
state: getState(),
|
||||
@@ -59,8 +60,7 @@ function setState() {
|
||||
// setLikes(response.likes);
|
||||
console.log(response);
|
||||
setDislikes(formattedDislike);
|
||||
} else {
|
||||
}
|
||||
} else {}
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -119,4 +119,4 @@ function setEventListeners(evt) {
|
||||
|
||||
setEventListeners();
|
||||
|
||||
//window.addEventListener("hashchange", setEventListeners, false);
|
||||
})(document.currentScript.getAttribute("security-token"), document.currentScript.getAttribute("extension-id"));
|
||||
Reference in new issue
Block a user