Nettruyen Tools

Remove ads and added zoom out options

  1. // ==UserScript==
  2. // @name Nettruyen Tools
  3. // @namespace nettruyen
  4. // @description Remove ads and added zoom out options
  5. // @version 1.1
  6. // @include https://*nettruyen*
  7. // @author kylyte
  8. // @license MIT
  9. // @run-at document-start
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=nettruyenus.com
  11. // @grant GM_addStyle
  12. // @grant GM_registerMenuCommand
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // @noframes
  16. // ==/UserScript==
  17. function removeAds() {
  18. GM_addStyle(`
  19. .reading-control > .mrb5,
  20. div.mrb10:nth-of-type(2),
  21. .hidden-sm.hidden-xs.mrb10.alert-info.alert,
  22. .top > i,
  23. .notify_block,
  24. .text-center.page-chapter,
  25. #nt_comments > div.mrt5,
  26. .facebook-like,
  27. .mrb5.text-center.container,
  28. .container div:not(.top)>div.mrb5.mrt5.text-center>a,
  29. .footer {
  30. display: none !important;
  31. }
  32. .scroll-to-fixed-fixed.chapter-nav {
  33. position: unset !important;
  34. z-index: 100 !important;
  35. box-shadow: unset !important;
  36. }
  37. `);
  38. }
  39.  
  40. const defaultSettings = {
  41. zoomFactor: 1
  42. };
  43. let settings = GM_getValue('settings', defaultSettings);
  44. function zoomOutImages() {
  45. var images = document.querySelectorAll('.box_doc img[src]');
  46. var factor = settings.zoomFactor;
  47. for (var i = 0; i < images.length; i++) {
  48. var image = images[i];
  49. image.style.width = image.naturalWidth * factor + 'px';
  50. image.style.height = image.naturalHeight * factor + 'px';
  51. }
  52. }
  53. function setZoomFactor(factor) {
  54. settings.zoomFactor = factor;
  55. GM_setValue('settings', settings);
  56. location.reload();
  57. }
  58. const zoomLevels = [1, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2];
  59. const zoomNames = ['100%', '90%', '80%', '70%', '60%', '50%', '40%', '30%', '20%'];
  60. for (var i = 0; i < zoomLevels.length; i++) {
  61. let name = (settings.zoomFactor === zoomLevels[i] ? '[x]' : '[ ]') + ' Zoom Out ' + zoomNames[i];
  62. GM_registerMenuCommand(name, setZoomFactor.bind(null, zoomLevels[i]));
  63. }
  64.  
  65. function lazyloadComment() {
  66. var tabs = document.querySelectorAll('.tab-content');
  67. tabs.forEach(function(tab) {
  68. if (tab.getBoundingClientRect().top < window.innerHeight) {
  69. loadTabContent(tab);
  70. } else {
  71. var observer = new IntersectionObserver(function(entries) {
  72. entries.forEach(function(entry) {
  73. if (entry.isIntersecting) {
  74. loadTabContent(entry.target);
  75. observer.unobserve(entry.target);
  76. }
  77. });
  78. }, {
  79. rootMargin: '0px',
  80. threshold: 0.1
  81. });
  82. observer.observe(tab);
  83. }
  84. });
  85.  
  86. function loadTabContent(tab) {
  87. console.log('Loading content for', tab);
  88. }
  89. }
  90.  
  91. removeAds();
  92. document.addEventListener('DOMContentLoaded', lazyloadComment);
  93. window.addEventListener('load', zoomOutImages);