Dark and mobile MobileRead.com

Dark theme and mobile mode for mobileread.com!

  1. // ==UserScript==
  2. // @name Dark and mobile MobileRead.com
  3. // @name:pl Ciemny i mobilny MobileRead.com
  4. // @description Dark theme and mobile mode for mobileread.com!
  5. // @description:pl Ciemny motyw i tryb mobilny dla mobileread.com!
  6. // @author juliazero
  7. // @license GPL-3.0-only
  8. // @version 1.5.52
  9. // @match https://www.mobileread.com/*
  10. // @namespace mobileread.com
  11. // @resource IMPORTED_CSS https://userstyles.world/api/style/13484.user.css?v=4.4.54
  12. // @grant GM_getResourceText
  13. // @grant GM_addStyle
  14. // @run-at document-body
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. // Load and inject CSS as a <style> element
  21. let css = GM_getResourceText("IMPORTED_CSS");
  22. // Remove the @-moz-document wrapper, but keep the inner contents
  23. css = css.replace(/@-moz-document\s+domain\([^)]+\)\s*\{([\s\S]*?)\}\s*$/, '$1');
  24. GM_addStyle(css);
  25.  
  26. // Add viewport meta tag for better mobile support
  27. const metaElement = document.createElement('meta');
  28. metaElement.name = 'viewport';
  29. metaElement.content = 'width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes';
  30. document.head.appendChild(metaElement);
  31.  
  32. // Remove " First" and "Last " from pagination links
  33. function cleanPaginationText() {
  34. document.querySelectorAll('a.smallfont').forEach(a => {
  35. for (let node of a.childNodes) {
  36. if (node.nodeType === Node.TEXT_NODE) {
  37. node.textContent = node.textContent.replace(" First", "").replace("Last ", "");
  38. }
  39. }
  40. });
  41. }
  42. cleanPaginationText();
  43. const observer = new MutationObserver(cleanPaginationText);
  44. observer.observe(document.body, { childList: true, subtree: true });
  45. })();