remove ads from smbc & clear view

It might not work correctly for your device, adjust value in unzoomPage function.

当前为 2025-02-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name remove ads from smbc & clear view
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description It might not work correctly for your device, adjust value in unzoomPage function.
  6. // @author resursator
  7. // @license MIT
  8. // @match https://www.smbc-comics.com/comic/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=smbc-comics.com
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. function cleanElements() {
  14. 'use strict';
  15. const target = document.getElementById('cc-comicbody');
  16. let prevElement = target.previousElementSibling;
  17.  
  18. // Check if previous element is an anchor tag containing an image
  19. if (prevElement && prevElement.tagName === 'A' &&
  20. prevElement.querySelector('img')) {
  21. prevElement.remove();
  22. }
  23.  
  24. const comicright = document.getElementById('comicright');
  25. if (comicright) {
  26. comicright.remove();
  27. }
  28.  
  29. const comicleft = document.getElementById('comicleft');
  30. if (comicleft) {
  31. comicleft.style.width = '100%';
  32. }
  33.  
  34. if (target) {
  35. document.getElementById('cc-comic').style.width = '95%';
  36. target.style.width = '95%';
  37. target.style.marginLeft = 'auto';
  38. target.style.marginRight = 'auto';
  39. }
  40.  
  41. const buythis = document.getElementById('buythis');
  42. if (buythis) {
  43. buythis.remove();
  44. }
  45.  
  46. const jumpbar = document.getElementById('hw-jumpbar');
  47. if (jumpbar) {
  48. jumpbar.remove();
  49. }
  50.  
  51. const commentspace = document.getElementById('comment-space');
  52. if (commentspace) {
  53. commentspace.remove();
  54. }
  55.  
  56. const blogHeader = document.getElementById('blogheader');
  57. if (blogHeader) {
  58. blogHeader.style.marginLeft = '18%';
  59. }
  60. }
  61.  
  62. function fixViewport() {
  63. let meta = document.querySelector("meta[name='viewport']");
  64. if (!meta) {
  65. meta = document.createElement("meta");
  66. meta.name = "viewport";
  67. document.head.appendChild(meta);
  68. }
  69. meta.content = "width=device-width, initial-scale=1.0";
  70. }
  71.  
  72. function unzoomPage() {
  73. // change 1.3 to whatever you need, I'm not sure if it works the same on other devices
  74. let scale = 1.3 / window.devicePixelRatio;
  75. document.body.style.transform = `scale(${scale})`;
  76. document.body.style.transformOrigin = "0 0";
  77. document.body.style.width = `${100 / scale}%`;
  78. document.documentElement.style.width = "100vw";
  79. }
  80.  
  81. fixViewport();
  82. cleanElements();
  83. unzoomPage();