Kinopoisk Redirect

Show a button on the page to redirect from kinopoisk.ru to C_X

  1. // ==UserScript==
  2. // @name Kinopoisk Redirect
  3. // @namespace https://t.me/johannmosin
  4. // @version 1.1
  5. // @description Show a button on the page to redirect from kinopoisk.ru to C_X
  6. // @author Johann Mosin
  7. // @match https://www.kinopoisk.ru/*/*
  8. // @license MIT
  9. // @grant GM_addStyle
  10. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Function to create and append the button
  17. function createAndAppendButton(containerClass, providedButtonClass) {
  18. // Check if the button already exists
  19. if (document.querySelector('button.redirect-button')) {
  20. return;
  21. }
  22.  
  23. // Create a button element
  24. var button = document.createElement('button');
  25. button.textContent = 'Смотреть на C_X';
  26. button.className = 'redirect-button'; // Add a class to the button
  27.  
  28. // Copy the classes from the provided button
  29. var providedButton = document.querySelector(providedButtonClass);
  30. var classes = providedButton.className.split(' ');
  31.  
  32. // Apply the copied classes to the new button
  33. classes.forEach(function(className) {
  34. button.classList.add(className);
  35. });
  36.  
  37. // Attach an event listener to the button
  38. button.addEventListener('click', function() {
  39. // Get the current URL
  40. var currentUrl = window.location.href;
  41.  
  42. // Extract the type and id from the URL
  43. var parts = currentUrl.split('/');
  44. var type = parts[3];
  45. var id = parts[4];
  46.  
  47. // Construct the new URL
  48. var newUrl = 'https://w2.kpfr.wiki/' + type + '/' + id + '/';
  49.  
  50. // Redirect to the new URL
  51. window.location.href = newUrl;
  52. });
  53.  
  54. // Append the button to the container
  55. document.querySelector(containerClass).appendChild(button);
  56. }
  57.  
  58. // Check which container class the page contains and create the button accordingly
  59. function checkForButtons() {
  60. if (document.querySelector('div.styles_buttonsContainer__HREZO')) {
  61. createAndAppendButton('div.styles_buttonsContainer__HREZO', '.styles_button__tQYKG .style_root__BmiQ7 button');
  62. } else if (document.querySelector('div.styles_buttonsContainer__i6y3F')) {
  63. createAndAppendButton('div.styles_buttonsContainer__i6y3F', '.styles_button__Q82i0 .watch-online-button .kinopoisk-watch-online-button');
  64. }
  65. }
  66.  
  67. // Use MutationObserver to check for changes in the DOM
  68. var observer = new MutationObserver(checkForButtons);
  69. observer.observe(document.body, { childList: true, subtree: true });
  70.  
  71. // Run the checkForButtons function initially
  72. checkForButtons();
  73. })();