Kaynağa Gözat

Merge branch 'Anarios:main' into main

Nikita Krupin 3 yıl önce
ebeveyn
işleme
505eab1daa

+ 15 - 11
Extensions/UserScript/Return Youtube Dislike.user.js

@@ -1,18 +1,22 @@
 // ==UserScript==
 // @name         Return YouTube Dislike
 // @namespace    https://www.returnyoutubedislike.com/
-// @version      0.6
+// @homepage     https://www.returnyoutubedislike.com/
+// @version      0.6.1
+// @encoding     utf-8
 // @description  Return of the YouTube Dislike, Based off https://www.returnyoutubedislike.com/
+// @icon         https://github.com/Anarios/return-youtube-dislike/raw/main/Icons/Return%20Youtube%20Dislike%20-%20Transparent.png
 // @author       Anarios & JRWR
-// @match      *://*.youtube.com/*
-// @compatible chrome
-// @compatible firefox
-// @compatible opera
-// @compatible safari
-// @compatible edge
-// @downloadURL https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
-// @updateURL https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
-// @grant GM.xmlHttpRequest
+// @match        *://*.youtube.com/*
+// @compatible   chrome
+// @compatible   firefox
+// @compatible   opera
+// @compatible   safari
+// @compatible   edge
+// @downloadURL  https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
+// @updateURL    https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
+// @grant        GM.xmlHttpRequest
+// @run-at       document-end
 // ==/UserScript==
 function cLog(text, subtext = '') {
   subtext = subtext.trim() === '' ? '' : `(${subtext})`;
@@ -127,7 +131,7 @@ function setState() {
       if (result) {
         cLog("response from youtube:");
         cLog(JSON.stringify(result));
-        if (result.likes || result.dislikes) {
+        if (result.likes && result.dislikes) {
           const formattedDislike = numberFormat(result.dislikes);
           setDislikes(formattedDislike);
           createRateBar(result.likes, result.dislikes);

+ 1 - 1
Extensions/chrome/manifest.json

@@ -1,7 +1,7 @@
 {
   "name": "Return YouTube Dislike",
   "description": "Returns ability to see dislikes",
-  "version": "1.0.0.2",
+  "version": "1.1.0.0",
   "manifest_version": 3,
   "background": {
     "service_worker": "return-youtube-dislike.background.js"

+ 98 - 27
Extensions/chrome/popup.css

@@ -1,44 +1,115 @@
 /* Variables */
 :root {
-    --background: #111;
-    --primary: #ff4444;
-    --secondary: #272727;
-    --white: #fff;
+  --primary: #cc2929;
+  --accent: #581111;
+
+  --background: #111;
+  --secondary: #272727;
+  --tertiary: #333333;
+  --lightGrey: #999;
+  --white: #fff;
 }
 
 /* Window Styling */
-html,body {
-    background-color: var(--background);
-    color: var(--white);
-    min-width: 300px;
-    padding: 0.5em;
-    font-family: Arial, Helvetica, sans-serif;
-    font-size: 14px;
+html,
+body {
+  background-color: var(--background);
+  color: var(--white);
+  min-width: 300px;
+  padding: 0.5em;
+  font-family: Arial, Helvetica, sans-serif;
+  font-size: 14px;
 }
 
 h1 {
-    font-size: 26px;
+  font-size: 26px;
 }
 
 button {
-    color: var(--white);
-    background: var(--secondary);
-    cursor: pointer;
-    padding: 5px 16px;
-    border: none;
-    border-radius: 4px;
-    font-weight: 500;
-    box-shadow: 0 2px 4px -1px rgb(0 0 0 / 20%), 0 4px 5px 0 rgb(0 0 0 / 14%), 0 1px 10px 0 rgb(0 0 0 / 12%);
+  color: var(--white);
+  background: var(--secondary);
+  cursor: pointer;
+  padding: 5px 16px;
+  border: none;
+  border-radius: 4px;
+  font-weight: 500;
+  box-shadow: 0 2px 4px -1px rgb(0 0 0 / 20%), 0 4px 5px 0 rgb(0 0 0 / 14%),
+    0 1px 10px 0 rgb(0 0 0 / 12%);
 }
 
 #advancedToggle {
-    margin-top: 1em;
-    margin-bottom: 2em;
+  margin-top: 1em;
+  margin-bottom: 2em;
 }
 
 #advancedSettings {
-    display: none;
-    border: 2px solid var(--secondary);
-    border-radius: 4px;
-    padding: 0.5em;
-}
+  display: none;
+  border: 2px solid var(--secondary);
+  border-radius: 0.5rem;
+  padding: 1rem;
+}
+
+#advancedLegend {
+  color: var(--tertiary) !important;
+  /* margin: auto; */ /* Center the label */
+  /* padding: .25rem .5rem; */
+  /* border-radius: .25rem; */
+  /* border: .25rem solid var(--secondary); */
+}
+
+/*   Switches   */
+.switch {
+  position: relative;
+  display: inline-block;
+  width: 30px;
+  height: 17px;
+  margin-bottom: 1rem;
+}
+
+.switch:last-of-type {
+  margin-bottom: 0;
+}
+
+.switch input {
+  display: none;
+}
+
+.slider {
+  position: absolute;
+  cursor: pointer;
+  top: 0;
+  left: 0;
+  right: 0;
+  bottom: 0;
+  background: var(--secondary);
+  transition: 0.4s;
+  border-radius: 34px;
+}
+
+.slider:before {
+  position: absolute;
+  content: "";
+  height: 13px;
+  width: 13px;
+  left: 2px;
+  bottom: 2px;
+  background: var(--lightGrey);
+  transition: 0.4s;
+  border-radius: 50%;
+}
+
+input:checked + .slider {
+  background: var(--accent);
+}
+
+input:checked + .slider:before {
+  transform: translateX(13px);
+  background: var(--primary);
+}
+
+.switchLabel {
+  margin-left: 0.5rem;
+  width: 250px !important;
+  transform: translateX(35px);
+  display: inline-block;
+}

+ 19 - 10
Extensions/chrome/popup.html

@@ -1,13 +1,11 @@
 <!DOCTYPE html>
 <html lang="en">
   <head>
-    <meta content="text/html; charset=utf-8">
+    <meta content="text/html; charset=utf-8" />
     <title>Return YouTube Dislike</title>
-    <link rel="stylesheet" href="popup.css">
+    <link rel="stylesheet" href="popup.css" />
   </head>
   <body>
-
-
     <center>
       <img src="icons/icon48.png" alt="Logo" />
       <h1>Return YouTube Dislike</h1>
@@ -18,15 +16,26 @@
       <button id="link_discord">Discord</button>
 
       <br>
-<!--      <button id="advancedToggle">Show Advanced</button>-->
+      <button id="advancedToggle">Show Settings</button>
+      <br>
 
     </center>
 
-    <div id="advancedSettings">
-      Lorem ipsum dolor sit amet consectetur adipisicing elit. Nemo laboriosam, veritatis sint dolores assumenda harum quidem molestiae ad repellendus aliquid?
-    </div>
-
-
+    <fieldset id="advancedSettings">
+      <legend id="advancedLegend">Settings</legend>
+
+      <label class="switch">
+        <input type="checkbox" id="disable_ratio_bar" />
+        <span class="slider" />
+        <span class="switchLabel">Lorem ipsum dolor sit amet</span> </label
+      ><br />
+
+      <label class="switch">
+        <input type="checkbox" id="disable_api_unlisted" />
+        <span class="slider" />
+        <span class="switchLabel">Lorem ipsum dolor sit amet</span> </label
+      ><br />
+    </fieldset>
   </body>
   <script src="popup.js"></script>
 </html>

+ 14 - 16
Extensions/chrome/popup.js

@@ -1,33 +1,33 @@
 /*   Config   */
 const config = {
   advanced: false,
-  showAdvancedMessage: "Show Advanced",
-  hideAdvancedMessage: "Hide Advanced",
+  showAdvancedMessage: "Show Settings",
+  hideAdvancedMessage: "Hide Settings",
 
   links: {
-    website: 'https://returnyoutubedislike.com',
-    github: 'https://github.com/Anarios/return-youtube-dislike',
-    discord: 'https://discord.gg/mYnESY4Md5'
+    website: "https://returnyoutubedislike.com",
+    github: "https://github.com/Anarios/return-youtube-dislike",
+    discord: "https://discord.gg/mYnESY4Md5",
   },
 };
 
 /*   Links   */
-document.getElementById('link_website').addEventListener('click', () => {
-  chrome.tabs.create({url: config.links.website});
+document.getElementById("link_website").addEventListener("click", () => {
+  chrome.tabs.create({ url: config.links.website });
 });
 
-document.getElementById('link_github').addEventListener('click', () => {
-  chrome.tabs.create({url: config.links.github});
+document.getElementById("link_github").addEventListener("click", () => {
+  chrome.tabs.create({ url: config.links.github });
 });
 
-document.getElementById('link_discord').addEventListener('click', () => {
-  chrome.tabs.create({url: config.links.discord});
+document.getElementById("link_discord").addEventListener("click", () => {
+  chrome.tabs.create({ url: config.links.discord });
 });
 
 /*   Advanced Toggle   */
-const advancedToggle = document.getElementById('advancedToggle');
-advancedToggle.addEventListener('click', () => {
-  const adv = document.getElementById('advancedSettings');
+const advancedToggle = document.getElementById("advancedToggle");
+advancedToggle.addEventListener("click", () => {
+  const adv = document.getElementById("advancedSettings");
   if (config.advanced) {
     adv.style.display = "none";
     advancedToggle.innerHTML = config.showAdvancedMessage;
@@ -39,8 +39,6 @@ advancedToggle.addEventListener('click', () => {
   }
 });
 
-
-
 /* popup-script.js 
 document.querySelector('#login')
 .addEventListener('click', function () {

+ 27 - 5
Extensions/chrome/return-youtube-dislike.script.js

@@ -1,4 +1,8 @@
 (function (extensionId) {
+  let storedData = {
+    dislikes: 0
+  };
+
   function cLog(message, writer) {
     message = `[return youtube dislike]: ${message}`;
     if (writer) {
@@ -9,10 +13,13 @@
   }
 
   function getButtons() {
-    if (document.getElementById("menu-container").offsetParent === null) {
+
+    //---   If Menu Element Is Displayed:   ---//
+    if (document.getElementById('menu-container').offsetParent === null) {
       return document.querySelector(
         "ytd-menu-renderer.ytd-watch-metadata > div"
       );
+    //---   If Menu Element Isnt Displayed:   ---//
     } else {
       return document
         .getElementById("menu-container")
@@ -44,6 +51,7 @@
     return getDislikeButton().classList.contains("style-text");
   }
 
+
   function getState() {
     if (isVideoLiked()) {
       return "liked";
@@ -54,14 +62,16 @@
     return "neutral";
   }
 
+  //---   Sets The Likes And Dislikes Values   ---//
   function setLikes(likesCount) {
     getButtons().children[0].querySelector("#text").innerText = likesCount;
   }
-
   function setDislikes(dislikesCount) {
     getButtons().children[1].querySelector("#text").innerText = dislikesCount;
   }
 
+
+
   function setState() {
     let statsSet = false;
     chrome.runtime.sendMessage(
@@ -75,9 +85,10 @@
           cLog("response from youtube:");
           cLog(JSON.stringify(response));
           try {
-            if (response.likes || response.dislikes) {
+            if (response.likes && response.dislikes) {
               const formattedDislike = numberFormat(response.dislikes);
               setDislikes(formattedDislike);
+              storedData.dislikes = parseInt(response.dislikes);
               createRateBar(response.likes, response.dislikes);
               statsSet = true;
             }
@@ -110,12 +121,23 @@
   }
 
   function likeClicked() {
-    // console.log("like" + getState());
+    console.log("Dislike State:", getState());
     // setState();
   }
 
   function dislikeClicked() {
-    // console.log("dislike" + getState());
+    let state = getState();
+
+    console.log("Dislike State:",state);
+
+    if (state == 'disliked') {
+      storedData.dislikes++;
+      setDislikes(numberFormat( storedData.dislikes))
+    } else if (state == 'neutral') {
+      storedData.dislikes--;
+      setDislikes(numberFormat(storedData.dislikes))
+    }
+
     // setState();
   }
 

+ 1 - 1
Extensions/firefox/manifest.json

@@ -1,7 +1,7 @@
 {
   "name": "Return YouTube Dislike",
   "description": "Returns ability to see dislikes",
-  "version": "1.0.0.2",
+  "version": "1.1.0.0",
   "manifest_version": 2,
   "background": {
     "scripts": ["return-youtube-dislike.background.js"]

+ 56 - 1
Extensions/firefox/popup.css

@@ -1,8 +1,11 @@
 /* Variables */
 :root {
+    --primary: #CC2929;
+    --accent: #581111;
+
     --background: #111;
-    --primary: #ff4444;
     --secondary: #272727;
+    --lightGrey: #999;
     --white: #fff;
 }
 
@@ -42,4 +45,56 @@ button {
     border-radius: 4px;
     padding: 0.5em;
     margin-right: 1em; /* FIREFOX ONLY */
+}
+
+/*   Switches   */
+.switch {
+    position: relative;
+    display: inline-block;
+    width: 30px;
+    height: 17px;
+    margin-bottom: 0.5em;
+}
+
+.switch input {
+    display: none;
+}
+
+.slider {
+    position: absolute;
+    cursor: pointer;
+    top: 0;
+    left: 0;
+    right: 0;
+    bottom: 0;
+    background: var(--secondary);
+    transition: .4s;
+    border-radius: 34px;
+}
+
+.slider:before {
+    position: absolute;
+    content: '';
+    height: 13px;
+    width: 13px;
+    left: 2px;
+    bottom: 2px;
+    background: var(--lightGrey);
+    transition: .4s;
+    border-radius: 50%;
+}
+
+input:checked+.slider {
+    background: var(--accent);
+}
+
+input:checked+.slider:before {
+    transform: translateX(13px);
+    background: var(--primary);
+}
+
+.switchLabel {
+    width: 250px !important;
+    transform: translateX(35px);
+    display: inline-block;
 }

+ 15 - 2
Extensions/firefox/popup.html

@@ -18,12 +18,25 @@
       <button id="link_discord">Discord</button>
 
       <br>
-<!--      <button id="advancedToggle">Show Advanced</button>-->
+<!--      <button id="advancedToggle">Show Settings</button>-->
+      <br>
 
     </center>
 
     <div id="advancedSettings">
-      Lorem ipsum dolor sit amet consectetur adipisicing elit. Nemo laboriosam, veritatis sint dolores assumenda harum quidem molestiae ad repellendus aliquid?
+
+      <label class="switch">
+        <input type="checkbox" id="disable_ratio_bar" />
+        <span class="slider" />
+        <span class="switchLabel">Lorem ipsum dolor sit amet</span>
+    </label><br>
+
+    <label class="switch">
+        <input type="checkbox" id="disable_api_unlisted" />
+        <span class="slider" />
+        <span class="switchLabel">Lorem ipsum dolor sit amet</span>
+    </label><br>
+
     </div>
 
 

+ 2 - 2
Extensions/firefox/popup.js

@@ -1,8 +1,8 @@
 /*   Config   */
 const config = {
   advanced: false,
-  showAdvancedMessage: "Show Advanced",
-  hideAdvancedMessage: "Hide Advanced",
+  showAdvancedMessage: "Show Settings",
+  hideAdvancedMessage: "Hide Settings",
 
   links: {
     website: 'https://returnyoutubedislike.com',

+ 32 - 18
Extensions/firefox/return-youtube-dislike.script.js

@@ -1,3 +1,9 @@
+if (!storedData) {
+  var storedData = {
+    dislikes: 0,
+  };
+}
+
 function cLog(message, writer) {
   message = `[return youtube dislike]: ${message}`;
   if (writer) {
@@ -8,8 +14,10 @@ function cLog(message, writer) {
 }
 
 function getButtons() {
+  //---   If Menu Element Is Displayed:   ---//
   if (document.getElementById("menu-container").offsetParent === null) {
     return document.querySelector("ytd-menu-renderer.ytd-watch-metadata > div");
+    //---   If Menu Element Isnt Displayed:   ---//
   } else {
     return document
       .getElementById("menu-container")
@@ -51,10 +59,10 @@ function getState() {
   return "neutral";
 }
 
+//---   Sets The Likes And Dislikes Values   ---//
 function setLikes(likesCount) {
   getButtons().children[0].querySelector("#text").innerText = likesCount;
 }
-
 function setDislikes(dislikesCount) {
   getButtons().children[1].querySelector("#text").innerText = dislikesCount;
 }
@@ -71,9 +79,10 @@ function setState() {
         cLog("response from youtube:");
         cLog(JSON.stringify(response));
         try {
-          if (response.likes || response.dislikes) {
+          if (response.likes && response.dislikes) {
             const formattedDislike = numberFormat(response.dislikes);
             setDislikes(formattedDislike);
+            storedData.dislikes = parseInt(response.dislikes);
             createRateBar(response.likes, response.dislikes);
             statsSet = true;
           }
@@ -95,6 +104,7 @@ function setState() {
       cLog(JSON.stringify(response));
       if (response != undefined && !statsSet) {
         const formattedDislike = numberFormat(response.dislikes);
+        storedData.dislikes = response.dislikes;
         // setLikes(response.likes);
         console.log(response);
         setDislikes(formattedDislike);
@@ -105,13 +115,18 @@ function setState() {
   );
 }
 
-function likeClicked() {
-  // console.log("like" + getState());
-  // setState();
-}
+function likeClicked() {}
 
 function dislikeClicked() {
-  // console.log("dislike" + getState());
+  let state = getState();
+  if (state == "disliked") {
+    storedData.dislikes++;
+    setDislikes(numberFormat(storedData.dislikes));
+  } else if (state == "neutral") {
+    storedData.dislikes--;
+    setDislikes(numberFormat(storedData.dislikes));
+  }
+
   // setState();
 }
 
@@ -138,19 +153,19 @@ function roundDown(num) {
   const int = Math.floor(Math.log10(num) - 2);
   const decimal = int + (int % 3 ? 1 : 0);
   const value = Math.floor(num / 10 ** decimal);
-  return value * (10 ** decimal);
+  return value * 10 ** decimal;
 }
 
 function numberFormat(numberState) {
   const userLocales = navigator.language;
 
   const formatter = Intl.NumberFormat(userLocales, {
-    notation: 'compact',
+    notation: "compact",
     minimumFractionDigits: 1,
-    maximumFractionDigits: 1
+    maximumFractionDigits: 1,
   });
 
-  return formatter.format(roundDown(numberState)).replace(/\.0|,0/, '');
+  return formatter.format(roundDown(numberState)).replace(/\.0|,0/, "");
 }
 
 function setEventListeners(evt) {
@@ -242,13 +257,13 @@ function sendVideoIds() {
       "yt-simple-endpoint ytd-compact-video-renderer"
     )
   )
-  .concat(
-    Array.from(
-      document.getElementsByClassName("yt-simple-endpoint ytd-thumbnail")
+    .concat(
+      Array.from(
+        document.getElementsByClassName("yt-simple-endpoint ytd-thumbnail")
+      )
     )
-  )
-  .filter((x) => x.href && x.href.indexOf("/watch?v=") > 0)
-  .map((x) => getVideoId(x.href));
+    .filter((x) => x.href && x.href.indexOf("/watch?v=") > 0)
+    .map((x) => getVideoId(x.href));
   browser.runtime.sendMessage({
     message: "send_links",
     videoIds: ids,
@@ -258,4 +273,3 @@ function sendVideoIds() {
 setEventListeners();
 
 setTimeout(() => sendVideoIds(), 1500);
-