Removes all ads and banners from GKBooks website for a cleaner reading experience
Size
5.0 KB
Version
1.0.1
Created
Nov 7, 2025
Updated
about 1 month ago
1// ==UserScript==
2// @name GKBooks Ad Remover
3// @description Removes all ads and banners from GKBooks website for a cleaner reading experience
4// @version 1.0.1
5// @match https://*.gkbooks.in/*
6// @icon https://gkbooks.in/wp-content/uploads/2025/10/cropped-android-chrome-512x512-1-32x32.png
7// ==/UserScript==
8(function() {
9 'use strict';
10
11 console.log('GKBooks Ad Remover: Starting...');
12
13 // Function to remove ads
14 function removeAds() {
15 console.log('GKBooks Ad Remover: Removing ads...');
16
17 let removedCount = 0;
18
19 // Remove Google AdSense ads
20 const adsbygoogle = document.querySelectorAll('.adsbygoogle, ins.adsbygoogle');
21 adsbygoogle.forEach(ad => {
22 ad.remove();
23 removedCount++;
24 });
25
26 // Remove Google auto-placed ads
27 const googleAutoPlaced = document.querySelectorAll('.google-auto-placed, [class*="google-anno"]');
28 googleAutoPlaced.forEach(ad => {
29 ad.remove();
30 removedCount++;
31 });
32
33 // Remove ad iframes
34 const adIframes = document.querySelectorAll('iframe[src*="doubleclick"], iframe[src*="googlesyndication"], iframe[src*="googleadservices"]');
35 adIframes.forEach(iframe => {
36 iframe.remove();
37 removedCount++;
38 });
39
40 // Remove elements with ad-related IDs and classes
41 const adContainers = document.querySelectorAll('[id*="google_ads"], [id*="aswift"], [class*="ad-container"], [class*="advertisement"]');
42 adContainers.forEach(container => {
43 container.remove();
44 removedCount++;
45 });
46
47 // Remove banner ads in navigation
48 const navAds = document.querySelectorAll('.inside-navigation .google-auto-placed');
49 navAds.forEach(ad => {
50 ad.remove();
51 removedCount++;
52 });
53
54 // Remove any remaining ad scripts
55 const adScripts = document.querySelectorAll('script[src*="adsbygoogle"], script[src*="doubleclick"]');
56 adScripts.forEach(script => {
57 script.remove();
58 removedCount++;
59 });
60
61 console.log(`GKBooks Ad Remover: Removed ${removedCount} ad elements`);
62 }
63
64 // Add CSS to hide ads immediately
65 TM_addStyle(`
66 .adsbygoogle,
67 ins.adsbygoogle,
68 .google-auto-placed,
69 .google-anno-skip,
70 .google-anno-sc,
71 .goog-rtopics,
72 [id*="aswift"],
73 [id*="google_ads"],
74 iframe[src*="doubleclick"],
75 iframe[src*="googlesyndication"],
76 iframe[src*="googleadservices"],
77 [class*="ad-container"],
78 [class*="advertisement"] {
79 display: none !important;
80 visibility: hidden !important;
81 opacity: 0 !important;
82 height: 0 !important;
83 width: 0 !important;
84 position: absolute !important;
85 left: -9999px !important;
86 }
87 `);
88
89 // Initial removal
90 removeAds();
91
92 // Remove ads after DOM is fully loaded
93 if (document.readyState === 'loading') {
94 document.addEventListener('DOMContentLoaded', removeAds);
95 }
96
97 // Remove ads after page is fully loaded (including images and scripts)
98 window.addEventListener('load', () => {
99 setTimeout(removeAds, 1000);
100 });
101
102 // Watch for dynamically added ads using MutationObserver
103 const observer = new MutationObserver((mutations) => {
104 let shouldRemove = false;
105
106 mutations.forEach((mutation) => {
107 mutation.addedNodes.forEach((node) => {
108 if (node.nodeType === 1) { // Element node
109 // Check if the added node is an ad
110 if (node.classList && (
111 node.classList.contains('adsbygoogle') ||
112 node.classList.contains('google-auto-placed') ||
113 node.tagName === 'INS' ||
114 (node.tagName === 'IFRAME' && (
115 node.src.includes('doubleclick') ||
116 node.src.includes('googlesyndication')
117 ))
118 )) {
119 shouldRemove = true;
120 }
121
122 // Check if any child elements are ads
123 if (node.querySelector && (
124 node.querySelector('.adsbygoogle') ||
125 node.querySelector('.google-auto-placed') ||
126 node.querySelector('ins.adsbygoogle')
127 )) {
128 shouldRemove = true;
129 }
130 }
131 });
132 });
133
134 if (shouldRemove) {
135 console.log('GKBooks Ad Remover: New ads detected, removing...');
136 removeAds();
137 }
138 });
139
140 // Start observing the document for changes
141 observer.observe(document.body, {
142 childList: true,
143 subtree: true
144 });
145
146 console.log('GKBooks Ad Remover: Initialized and monitoring for ads');
147})();