Litres Download Button

Adds a button to download an open book for reading with an active Litres subscription

  1. // ==UserScript==
  2. // @name Litres Download Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Adds a button to download an open book for reading with an active Litres subscription
  6. // @author Grok
  7. // @match https://www.litres.ru/static/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Функция для формирования URL скачивания
  15. function generateDownloadUrl() {
  16. const currentUrl = window.location.href;
  17. // Удаляем префикс /static/or4/view/or.html?baseurl=
  18. let downloadUrl = currentUrl.replace('/static/or4/view/or.html?baseurl=', '');
  19. // Удаляем параметры после &art=
  20. downloadUrl = downloadUrl.split('&art=')[0];
  21. return downloadUrl;
  22. }
  23.  
  24. // Функция для добавления кнопки
  25. function addDownloadButton() {
  26. // Проверяем, что мы на странице чтения
  27. if (!window.location.href.includes('/static/or4/view/or.html')) {
  28. console.log('Не страница чтения книги');
  29. return;
  30. }
  31.  
  32. // Формируем URL для скачивания
  33. const downloadUrl = generateDownloadUrl();
  34.  
  35. // Создаем кнопку
  36. const downloadButton = document.createElement('a');
  37. downloadButton.textContent = 'Скачать книгу';
  38. downloadButton.href = downloadUrl;
  39. downloadButton.style.position = 'fixed';
  40. downloadButton.style.top = '1px';
  41. downloadButton.style.left = '50%';
  42. downloadButton.style.transform = 'translateX(-50%)';
  43. downloadButton.style.padding = '10px 15px';
  44. downloadButton.style.backgroundColor = '#28a745';
  45. downloadButton.style.color = '#fff';
  46. downloadButton.style.textDecoration = 'none';
  47. downloadButton.style.borderRadius = '5px';
  48. downloadButton.style.zIndex = '1000';
  49. downloadButton.setAttribute('download', '');
  50.  
  51. // Добавляем кнопку на страницу
  52. document.body.appendChild(downloadButton);
  53. }
  54.  
  55. // Ждем загрузки страницы и добавляем кнопку
  56. window.addEventListener('load', addDownloadButton);
  57. })();