VK Video - Добавить кнопки "Не интересно" и "Не рекомендовать автора"

Добавляет кнопки "Не интересно" и "Не рекомендовать автора" под каждым видео на VK Видео

  1. // ==UserScript==
  2. // @name VK Video - Добавить кнопки "Не интересно" и "Не рекомендовать автора"
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Добавляет кнопки "Не интересно" и "Не рекомендовать автора" под каждым видео на VK Видео
  6. // @author You
  7. // @match https://vkvideo.ru/*
  8. // @icon https://vk.com/images/icons/favicons/fav_vk_video_2x.ico
  9. // @grant none
  10. // @run-at document-end
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. function addButtons() {
  18. const videoCards = document.querySelectorAll('.VideoCard');
  19.  
  20. videoCards.forEach(card => {
  21. // Check if buttons already exist
  22. if (card.querySelector('.custom-buttons-added')) {
  23. return;
  24. }
  25.  
  26. const infoContent = card.querySelector('.VideoCard__infoContent');
  27. if (!infoContent) {
  28. return;
  29. }
  30.  
  31. const actionsContainer = document.createElement('div');
  32. actionsContainer.style.marginTop = '8px';
  33. actionsContainer.classList.add('custom-buttons-added'); // Add a class to prevent duplicates
  34.  
  35.  
  36. const notInterestedBtn = document.createElement('button');
  37. notInterestedBtn.textContent = 'Не интересно';
  38. applyButtonStyle(notInterestedBtn);
  39. notInterestedBtn.addEventListener('click', (event) => {
  40. event.preventDefault(); // Prevent default link behavior
  41. event.stopPropagation(); // Prevent event bubbling
  42.  
  43. const videoId = card.dataset.id;
  44. const ownerId = card.dataset.ownerId;
  45.  
  46. // Call the correct function with ownerId and videoId
  47. if (typeof VideoShowcase !== 'undefined' && typeof VideoShowcase.setNotRecommendOwner === 'function') {
  48. VideoShowcase.setNotRecommendOwner(ownerId, videoId.split("_")[1]); //video ID is after _
  49. console.log(`"Не интересно" clicked for video ID: ${videoId}, owner ID: ${ownerId}`);
  50. } else {
  51. console.error("VideoShowcase.setNotRecommendOwner is not available.");
  52. }
  53. });
  54.  
  55.  
  56. const notRecommendBtn = document.createElement('button');
  57. notRecommendBtn.textContent = 'Не рекомендовать автора';
  58. applyButtonStyle(notRecommendBtn);
  59. notRecommendBtn.addEventListener('click', (event) => {
  60. event.preventDefault(); // Prevent default link behavior
  61. event.stopPropagation(); //Prevent event bubbling
  62.  
  63. if (window.VideoShowcase && window.VideoShowcase.setNotRecommendOwner) {
  64. const videoId = card.dataset.id;
  65. const ownerId = card.dataset.ownerId;
  66. window.VideoShowcase.setNotRecommendOwner(ownerId, videoId.split("_")[1]); // Call the function with owner and video id
  67. console.log(`"Не рекомендовать автора" clicked for video ID: ${videoId}, owner ID: ${ownerId}`);
  68.  
  69. } else
  70. {
  71. console.error("VideoShowcase.setNotRecommendOwner is not available.");
  72. }
  73. });
  74.  
  75. actionsContainer.appendChild(notInterestedBtn);
  76. actionsContainer.appendChild(notRecommendBtn);
  77. infoContent.appendChild(actionsContainer);
  78. });
  79. }
  80.  
  81. function applyButtonStyle(button) {
  82. button.style.marginRight = '8px';
  83. button.style.padding = '4px 8px';
  84. button.style.border = '1px solid #ccc';
  85. button.style.borderRadius = '4px';
  86. button.style.backgroundColor = 'transparent';
  87. button.style.cursor = 'pointer';
  88. button.style.fontSize = '13px'; // Match VK's font size
  89. button.style.color = 'var(--vkui--color_text_subhead)'; // Use VKUI variable for color
  90. }
  91.  
  92.  
  93. // Initial run
  94. addButtons();
  95.  
  96. // Observe for changes in the DOM (e.g., infinite scrolling, SPA navigation)
  97. const observer = new MutationObserver(addButtons);
  98. observer.observe(document.body, {
  99. childList: true,
  100. subtree: true
  101. });
  102.  
  103. //One time button check after full page load, to catch any missed by the observer
  104. window.addEventListener('load', () => {
  105. setTimeout(addButtons, 500); //wait a bit for full render
  106. });
  107.  
  108.  
  109. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址