Spotify Text Selector and Context Menu

Позволяет выделять и копировать текст на странице Spotify и разблокирует контекстное меню / Allows selecting and copying text on Spotify pages and unlocks the context menu

  1. // ==UserScript==
  2. // @name Spotify Text Selector and Context Menu
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-09-27
  5. // @description Позволяет выделять и копировать текст на странице Spotify и разблокирует контекстное меню / Allows selecting and copying text on Spotify pages and unlocks the context menu
  6. // @author BALCETUL, z1zod
  7. // @match https://*.spotify.com/*
  8. // @icon https://www.spotify.com/favicon.ico
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. /*
  14. Copyright (c) 2024 z1zod, BALCETUL
  15.  
  16. Permission is hereby granted, free of charge, to any person obtaining a copy
  17. of this software and associated documentation files (the "Software"), to deal
  18. in the Software without restriction, including without limitation the rights
  19. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  20. copies of the Software, and to permit persons to whom the Software is
  21. furnished to do so, subject to the following conditions:
  22.  
  23. The above copyright notice and this permission notice shall be included in all
  24. copies or substantial portions of the Software.
  25.  
  26. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  29. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  30. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  31. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. SOFTWARE.
  33. */
  34.  
  35.  
  36. (function() {
  37. 'use strict';
  38.  
  39. const style = document.createElement('style');
  40. style.textContent = `
  41. ::selection {
  42. background: rgba(0, 255, 0, 0.5);
  43. color: black;
  44. }
  45.  
  46. .encore-text, .rEN7ncpaUeSGL9z0NGQR {
  47. user-select: text !important;
  48. }
  49.  
  50. .rEN7ncpaUeSGL9z0NGQR {
  51. cursor: text;
  52. }
  53. `;
  54. document.head.appendChild(style);
  55.  
  56. document.addEventListener('dragstart', function(event) {
  57. if (event.target.closest('.encore-text-headline-large, .rEN7ncpaUeSGL9z0NGQR')) {
  58. event.preventDefault();
  59. }
  60. });
  61.  
  62. function copySelectedText() {
  63. const selectedText = window.getSelection().toString();
  64. if (selectedText) {
  65. navigator.clipboard.writeText(selectedText).then(() => {
  66. console.log('Текст скопирован:', selectedText);
  67. alert('Текст скопирован в буфер обмена!');
  68. }).catch(err => {
  69. console.error('Ошибка копирования текста:', err);
  70. alert('Ошибка копирования текста.');
  71. });
  72. } else {
  73. alert('Нет выделенного текста для копирования.');
  74. }
  75. }
  76.  
  77. document.addEventListener('contextmenu', function(event) {
  78. event.stopPropagation();
  79. }, true);
  80.  
  81. document.addEventListener('keydown', function(event) {
  82. if (event.ctrlKey && event.key === 'c') {
  83. copySelectedText();
  84. }
  85. });
  86.  
  87. document.addEventListener('mouseup', function() {
  88. const selectedText = window.getSelection().toString();
  89. if (selectedText) {
  90. console.log('Выделенный текст:', selectedText);
  91. }
  92. });
  93. })();