YandexGPT

YandexGPT для обобщения статей и текстов.

  1. // ==UserScript==
  2. // @name YandexGPT
  3. // @namespace your-namespace
  4. // @version 1.0
  5. // @description YandexGPT для обобщения статей и текстов.
  6. // @match *://*/*
  7. // @grant GM_xmlhttpRequest
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Create a floating button
  15. var floatingButton = document.createElement('div');
  16. floatingButton.style.position = 'fixed';
  17. floatingButton.style.bottom = '20px';
  18. floatingButton.style.right = '20px';
  19. floatingButton.style.width = '100px';
  20. floatingButton.style.height = '40px';
  21. floatingButton.style.backgroundColor = 'blue';
  22. floatingButton.style.borderRadius = '5px';
  23. floatingButton.style.cursor = 'move';
  24. floatingButton.style.color = 'white';
  25. floatingButton.style.textAlign = 'center';
  26. floatingButton.style.lineHeight = '40px';
  27. floatingButton.style.zIndex = '9999';
  28. floatingButton.textContent = 'Summarize';
  29. document.body.appendChild(floatingButton);
  30.  
  31. // Make the button draggable
  32. var isDragging = false;
  33. var startOffsetX = 0;
  34. var startOffsetY = 0;
  35.  
  36. floatingButton.addEventListener('mousedown', function(event) {
  37. if (event.target === floatingButton) {
  38. isDragging = true;
  39. startOffsetX = event.clientX - floatingButton.offsetLeft;
  40. startOffsetY = event.clientY - floatingButton.offsetTop;
  41. }
  42. });
  43.  
  44. document.addEventListener('mousemove', function(event) {
  45. if (isDragging) {
  46. var newX = event.clientX - startOffsetX;
  47. var newY = event.clientY - startOffsetY;
  48. floatingButton.style.left = newX + 'px';
  49. floatingButton.style.top = newY + 'px';
  50. }
  51. });
  52.  
  53. document.addEventListener('mouseup', function() {
  54. isDragging = false;
  55. });
  56.  
  57. // Add click event to the floating button
  58. floatingButton.addEventListener('click', function() {
  59. // Send a request to the API
  60. GM_xmlhttpRequest({
  61. method: 'POST',
  62. url: 'https://300.ya.ru/api/sharing-url',
  63. headers: {
  64. 'Content-Type': 'application/json',
  65. 'Authorization': 'OAuth <token>' // Замените <token> своим фактическим токеном для авторизации.
  66. },
  67. data: JSON.stringify({ 'article_url': window.location.href }),
  68. onload: function(response) {
  69. var data = JSON.parse(response.responseText);
  70. if (data.status === 'success') {
  71. var sharingUrl = data.sharing_url;
  72.  
  73. // Open the sharing URL in a new tab or popup window
  74. var openMethod = 'newTab'; // Change this to 'popupWindow' if you want to open a popup window instead
  75.  
  76. if (openMethod === 'newTab') {
  77. window.open(sharingUrl, '_blank');
  78. } else if (openMethod === 'popupWindow') {
  79. window.open(sharingUrl, '_blank', 'width=500,height=600');
  80. window.close();
  81. }
  82. } else {
  83. console.error('Error in request:', response.status);
  84. var errorMessage = response.status + ': ' + data.status + ', ' + data.message + ' Please try entering your link or text manually in the opened window';
  85. var errorElement = document.getElementById('error-message');
  86. errorElement.innerHTML = '';
  87. var errorSpan = document.createElement('span');
  88. errorSpan.style.color = 'blue';
  89. errorSpan.textContent = errorMessage;
  90.  
  91. // Open the page for manual link entry
  92. window.open('https://300.ya.ru', '_blank', 'width=500,height=600');
  93.  
  94. errorElement.appendChild(errorSpan);
  95. }
  96. },
  97. onerror: function(response) {
  98. console.error('Error in request:', response.status);
  99. }
  100. });
  101. });
  102. })();