mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-03 19:31:20 +01:00
Revert "Merge pull request #11 from mynovelhost/main"
This reverts commit475106e25f, reversing changes made toeb1756cce9.
This commit is contained in:
1 parent
475106e25f
commit
0a30c0ee05
4 files changed
+57
-70
No files matched your search
@@ -1,12 +1,6 @@
|
|||||||
const apiUrl = "https://return-youtube-dislike-api.azurewebsites.net";
|
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) => {
|
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") {
|
if (request.message === "get_auth_token") {
|
||||||
// chrome.identity.getAuthToken({ interactive: true }, function (token) {
|
// chrome.identity.getAuthToken({ interactive: true }, function (token) {
|
||||||
// console.log(token);
|
// console.log(token);
|
||||||
@@ -18,7 +12,7 @@ chrome.runtime.onMessageExternal.addListener((request, sender, sendResponse) =>
|
|||||||
// console.log("logging off");
|
// console.log("logging off");
|
||||||
// chrome.identity.clearAllCachedAuthTokens(() => console.log("logged off"));
|
// chrome.identity.clearAllCachedAuthTokens(() => console.log("logged off"));
|
||||||
} else if (request.message == "set_state") {
|
} else if (request.message == "set_state") {
|
||||||
// console.log(request);
|
console.log(request);
|
||||||
// chrome.identity.getAuthToken({ interactive: true }, function (token) {
|
// chrome.identity.getAuthToken({ interactive: true }, function (token) {
|
||||||
let token = "";
|
let token = "";
|
||||||
fetch(`${apiUrl}/votes?videoId=${request.videoId}`, {
|
fetch(`${apiUrl}/votes?videoId=${request.videoId}`, {
|
||||||
@@ -37,5 +31,16 @@ chrome.runtime.onMessageExternal.addListener((request, sender, sendResponse) =>
|
|||||||
//});
|
//});
|
||||||
return true;
|
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"],
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
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,6 +6,7 @@
|
|||||||
"background": {
|
"background": {
|
||||||
"service_worker": "background.js"
|
"service_worker": "background.js"
|
||||||
},
|
},
|
||||||
|
"permissions": ["activeTab", "scripting"],
|
||||||
"host_permissions": ["*://*.youtube.com/*"],
|
"host_permissions": ["*://*.youtube.com/*"],
|
||||||
"action": {
|
"action": {
|
||||||
"default_popup": "popup.html"
|
"default_popup": "popup.html"
|
||||||
@@ -18,16 +19,7 @@
|
|||||||
{
|
{
|
||||||
"matches": ["*://*.youtube.com/*"],
|
"matches": ["*://*.youtube.com/*"],
|
||||||
"js": ["content-script.js"],
|
"js": ["content-script.js"],
|
||||||
"run_at": "document_start"
|
"run_at": "document_idle"
|
||||||
}
|
|
||||||
],
|
|
||||||
"externally_connectable": {
|
|
||||||
"matches": ["*://*.youtube.com/*"]
|
|
||||||
},
|
|
||||||
"web_accessible_resources": [
|
|
||||||
{
|
|
||||||
"resources": ["script.js"],
|
|
||||||
"matches": ["*://*.youtube.com/*"]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
+43
-43
@@ -1,35 +1,34 @@
|
|||||||
(function(securityToken, extensionId) {
|
function getButtons() {
|
||||||
function getButtons() {
|
|
||||||
return document
|
return document
|
||||||
.getElementById("menu-container")
|
.getElementById("menu-container")
|
||||||
?.querySelector("#top-level-buttons-computed");
|
?.querySelector("#top-level-buttons-computed");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLikeButton() {
|
function getLikeButton() {
|
||||||
return getButtons().children[0];
|
return getButtons().children[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDislikeButton() {
|
function getDislikeButton() {
|
||||||
return getButtons().children[1];
|
return getButtons().children[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoLiked() {
|
function isVideoLiked() {
|
||||||
return getLikeButton().classList.contains("style-default-active");
|
return getLikeButton().classList.contains("style-default-active");
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoDisliked() {
|
function isVideoDisliked() {
|
||||||
return getDislikeButton().classList.contains("style-default-active");
|
return getDislikeButton().classList.contains("style-default-active");
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoNotLiked() {
|
function isVideoNotLiked() {
|
||||||
return getLikeButton().classList.contains("style-text");
|
return getLikeButton().classList.contains("style-text");
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoNotDisliked() {
|
function isVideoNotDisliked() {
|
||||||
return getDislikeButton().classList.contains("style-text");
|
return getDislikeButton().classList.contains("style-text");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getState() {
|
function getState() {
|
||||||
if (isVideoLiked()) {
|
if (isVideoLiked()) {
|
||||||
return "liked";
|
return "liked";
|
||||||
}
|
}
|
||||||
@@ -37,68 +36,69 @@
|
|||||||
return "disliked";
|
return "disliked";
|
||||||
}
|
}
|
||||||
return "neutral";
|
return "neutral";
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLikes(likesCount) {
|
function setLikes(likesCount) {
|
||||||
getButtons().children[0].querySelector("#text").innerText = likesCount;
|
getButtons().children[0].querySelector("#text").innerText = likesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDislikes(dislikesCount) {
|
function setDislikes(dislikesCount) {
|
||||||
getButtons().children[1].querySelector("#text").innerText = dislikesCount;
|
getButtons().children[1].querySelector("#text").innerText = dislikesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setState() {
|
function setState() {
|
||||||
chrome.runtime.sendMessage(extensionId, {
|
chrome.runtime.sendMessage(
|
||||||
securityToken: securityToken,
|
{
|
||||||
message: "set_state",
|
message: "set_state",
|
||||||
videoId: getVideoId(),
|
videoId: getVideoId(),
|
||||||
state: getState(),
|
state: getState(),
|
||||||
},
|
},
|
||||||
function(response) {
|
function (response) {
|
||||||
if (response != undefined) {
|
if (response != undefined) {
|
||||||
const formattedDislike = numberFormat(response.dislikes);
|
const formattedDislike = numberFormat(response.dislikes);
|
||||||
// setLikes(response.likes);
|
// setLikes(response.likes);
|
||||||
console.log(response);
|
console.log(response);
|
||||||
setDislikes(formattedDislike);
|
setDislikes(formattedDislike);
|
||||||
} else {}
|
} else {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function likeClicked() {
|
function likeClicked() {
|
||||||
console.log("like" + getState());
|
console.log("like" + getState());
|
||||||
setState();
|
setState();
|
||||||
}
|
}
|
||||||
|
|
||||||
function dislikeClicked() {
|
function dislikeClicked() {
|
||||||
console.log("dislike" + getState());
|
console.log("dislike" + getState());
|
||||||
setState();
|
setState();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setInitalState() {
|
function setInitalState() {
|
||||||
setState();
|
setState();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVideoId() {
|
function getVideoId() {
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const videoId = urlParams.get("v");
|
const videoId = urlParams.get("v");
|
||||||
return videoId;
|
return videoId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoLoaded() {
|
function isVideoLoaded() {
|
||||||
const videoId = getVideoId();
|
const videoId = getVideoId();
|
||||||
return (
|
return (
|
||||||
document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null
|
document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function numberFormat(numberState) {
|
function numberFormat(numberState) {
|
||||||
const userLocales = navigator.language;
|
const userLocales = navigator.language;
|
||||||
const formatter = Intl.NumberFormat(userLocales, { notation: "compact" });
|
const formatter = Intl.NumberFormat(userLocales, { notation: "compact" });
|
||||||
return formatter.format(numberState);
|
return formatter.format(numberState);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setEventListeners(evt) {
|
function setEventListeners(evt) {
|
||||||
function checkForJS_Finish() {
|
function checkForJS_Finish() {
|
||||||
if (getButtons()?.offsetParent && isVideoLoaded()) {
|
if (getButtons()?.offsetParent && isVideoLoaded()) {
|
||||||
clearInterval(jsInitChecktimer);
|
clearInterval(jsInitChecktimer);
|
||||||
@@ -115,8 +115,8 @@
|
|||||||
if (window.location.href.indexOf("watch?") >= 0) {
|
if (window.location.href.indexOf("watch?") >= 0) {
|
||||||
var jsInitChecktimer = setInterval(checkForJS_Finish, 111);
|
var jsInitChecktimer = setInterval(checkForJS_Finish, 111);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setEventListeners();
|
setEventListeners();
|
||||||
|
|
||||||
})(document.currentScript.getAttribute("security-token"), document.currentScript.getAttribute("extension-id"));
|
//window.addEventListener("hashchange", setEventListeners, false);
|
||||||
Reference in new issue
Block a user