Invidious Like and Dislike Count

Restore like and dislike count for any Invidious Instance

当前为 2024-02-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Invidious Like and Dislike Count
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Restore like and dislike count for any Invidious Instance
  6. // @author KMan005
  7. // @match https://iv.ggtyler.dev/*
  8. // @grant GM_xmlhttpRequest
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Get the video ID from the URL
  16. const urlParams = new URLSearchParams(window.location.search);
  17. const videoId = urlParams.get('v');
  18.  
  19. // Fetch the like and dislike count
  20. GM_xmlhttpRequest({
  21. method: "GET",
  22. url: `https://returnyoutubedislikeapi.com/votes?videoId=${videoId}`,
  23. headers: {
  24. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9",
  25. "Pragma": "no-cache",
  26. "Cache-Control": "no-cache",
  27. "Connection": "keep-alive"
  28. },
  29. onload: function(response) {
  30. const data = JSON.parse(response.responseText);
  31. const likeCount = data.likes;
  32. const dislikeCount = data.dislikes;
  33.  
  34. // Display the like count on the webpage within the specified <p> element
  35. const likesElement = document.getElementById('likes');
  36. likesElement.innerHTML = `<i class="icon ion-ios-thumbs-up"></i> ${likeCount}`;
  37.  
  38. // Display the dislike count on the webpage within the specified <p> element
  39. const dislikesElement = document.getElementById('dislikes');
  40. dislikesElement.textContent = `Dislikes: ${dislikeCount}`;
  41.  
  42. // Ensure visibility and display properties stay consistent for both elements
  43. likesElement.style.visibility = 'visible';
  44. likesElement.style.display = 'block';
  45. dislikesElement.style.visibility = 'visible';
  46. dislikesElement.style.display = 'block';
  47. }
  48. });
  49.  
  50. // Apply CSS styles to the specified <p> elements
  51. const styleElement = document.createElement('style');
  52. styleElement.textContent = `
  53. p#likes, p#dislikes {
  54. display: block;
  55. visibility: visible;
  56. unicode-bidi: plaintext;
  57. text-align: start;
  58. margin-block-start: 1em;
  59. margin-block-end: 1em;
  60. margin-inline-start: 0px;
  61. margin-inline-end: 0px;
  62. overflow-wrap: break-word;
  63. word-wrap: break-word;
  64. font-family: sans-serif;
  65. }
  66. `;
  67. document.head.appendChild(styleElement);
  68. })();