Removes ads, subscription prompts, login buttons, and bypasses paywalls on The Hindu
Size
8.0 KB
Version
1.2.1
Created
Oct 28, 2025
Updated
17 days ago
1// ==UserScript==
2// @name The Hindu Ad Blocker & Paywall Bypass
3// @description Removes ads, subscription prompts, login buttons, and bypasses paywalls on The Hindu
4// @version 1.2.1
5// @match https://*.thehindu.com/*
6// @icon https://www.thehindu.com/favicon.ico
7// @grant none
8// ==/UserScript==
9(function() {
10 'use strict';
11
12 console.log('The Hindu Ad Blocker & Paywall Bypass - Starting...');
13
14 // Function to inject CSS styles
15 function addStyles() {
16 const style = document.createElement('style');
17 style.textContent = `
18 /* Hide all ad containers */
19 .dfp-ad,
20 .ad-container,
21 .advertisement,
22 .mastheAdTop,
23 .flexdfpad,
24 #secpagetopslot,
25 [id*="div-gpt-ad"],
26 [class*="dfp-ad"],
27 iframe[id*="google_ads"],
28 iframe[title*="Advertisement"],
29 iframe[title*="3rd party ad"],
30 iframe[aria-label*="Advertisement"],
31
32 /* Hide subscription and login prompts */
33 .btn-subscribe,
34 .btn-signup,
35 .thgsignin,
36 .btn-ebooks,
37 .btns-handeler,
38 .subscription-banner,
39
40 /* Hide premium labels and blocks */
41 .premium-label,
42 .premium-block,
43 .subscriber-only,
44 a[href*="/premium/"],
45
46 /* Hide paywall overlays */
47 .paywall,
48 .paywall-container,
49 [class*="paywall"],
50
51 /* Hide interstitial ads */
52 .INTERSTITIAL,
53 [data-positiontype="INTERSTITIAL"],
54
55 /* Hide sticky/floating ads */
56 .sticky-ad,
57 .floating-ad {
58 display: none !important;
59 visibility: hidden !important;
60 opacity: 0 !important;
61 height: 0 !important;
62 width: 0 !important;
63 overflow: hidden !important;
64 pointer-events: none !important;
65 }
66
67 /* Remove paywall overlays */
68 body.paywall-active {
69 overflow: auto !important;
70 }
71
72 /* Ensure content is visible */
73 .article-content,
74 .story-content,
75 .articlebodycontent,
76 #content-body-70208411,
77 [id*="content-body"],
78 [class*="content"] {
79 max-height: none !important;
80 overflow: visible !important;
81 filter: none !important;
82 -webkit-filter: none !important;
83 }
84 `;
85 document.head.appendChild(style);
86 console.log('CSS styles injected');
87 }
88
89 // Function to remove unwanted elements from DOM
90 function removeUnwantedElements() {
91 const selectors = [
92 // Ad selectors
93 '.dfp-ad',
94 '.mastheAdTop',
95 '.flexdfpad',
96 '[id*="div-gpt-ad"]',
97 'iframe[id*="google_ads"]',
98 'iframe[title*="Advertisement"]',
99 'iframe[aria-label*="Advertisement"]',
100 '.INTERSTITIAL',
101 '[data-positiontype="INTERSTITIAL"]',
102
103 // Subscription and login selectors
104 '.btns-handeler',
105 '.btn-subscribe',
106 '.btn-signup',
107 '.thgsignin',
108 '.btn-ebooks',
109
110 // Premium labels
111 '.premium-label',
112 'a[href="/premium/"]'
113 ];
114
115 let removedCount = 0;
116 selectors.forEach(selector => {
117 try {
118 const elements = document.querySelectorAll(selector);
119 elements.forEach(element => {
120 if (element && element.parentNode) {
121 element.remove();
122 removedCount++;
123 }
124 });
125 } catch (e) {
126 console.error('Error removing elements with selector:', selector, e);
127 }
128 });
129
130 if (removedCount > 0) {
131 console.log(`Removed ${removedCount} unwanted elements`);
132 }
133 }
134
135 // Function to unlock paywalled content
136 function unlockPaywalledContent() {
137 // Remove paywall classes from body
138 if (document.body) {
139 document.body.classList.remove('paywall-active', 'subscriber-only', 'premium-content');
140 }
141
142 // Remove blur and height restrictions from content
143 const contentSelectors = [
144 '.article-content',
145 '.story-content',
146 '.articlebodycontent',
147 '[id*="content-body"]',
148 '.col-xl-9.opinion'
149 ];
150
151 contentSelectors.forEach(selector => {
152 const elements = document.querySelectorAll(selector);
153 elements.forEach(element => {
154 element.style.maxHeight = 'none';
155 element.style.overflow = 'visible';
156 element.style.filter = 'none';
157 element.style.webkitFilter = 'none';
158 element.style.height = 'auto';
159 });
160 });
161
162 // Remove any overlay divs
163 const overlays = document.querySelectorAll('[class*="overlay"], [class*="modal"], [class*="popup"]');
164 overlays.forEach(overlay => {
165 const position = window.getComputedStyle(overlay).position;
166 if (position === 'fixed' || position === 'absolute') {
167 overlay.remove();
168 }
169 });
170
171 console.log('Paywall content unlocked');
172 }
173
174 // Function to clean up ads that load dynamically
175 function cleanupDynamicAds() {
176 // Remove ad iframes
177 const iframes = document.querySelectorAll('iframe');
178 iframes.forEach(iframe => {
179 const src = iframe.src || '';
180 const id = iframe.id || '';
181 const title = iframe.title || '';
182 const ariaLabel = iframe.getAttribute('aria-label') || '';
183
184 if (src.includes('doubleclick') ||
185 src.includes('googlesyndication') ||
186 src.includes('google_ads') ||
187 id.includes('google_ads') ||
188 title.includes('Advertisement') ||
189 title.includes('3rd party ad') ||
190 ariaLabel.includes('Advertisement')) {
191 iframe.remove();
192 console.log('Removed ad iframe:', id || src);
193 }
194 });
195 }
196
197 // Main initialization function
198 function init() {
199 console.log('Running initialization...');
200 addStyles();
201 removeUnwantedElements();
202 unlockPaywalledContent();
203 cleanupDynamicAds();
204 }
205
206 // Run when DOM is ready
207 if (document.readyState === 'loading') {
208 document.addEventListener('DOMContentLoaded', init);
209 } else {
210 init();
211 }
212
213 // Watch for dynamically added elements with debouncing
214 let cleanupTimeout;
215 const observer = new MutationObserver(() => {
216 clearTimeout(cleanupTimeout);
217 cleanupTimeout = setTimeout(() => {
218 removeUnwantedElements();
219 unlockPaywalledContent();
220 cleanupDynamicAds();
221 }, 1000);
222 });
223
224 // Start observing after a short delay to ensure DOM is ready
225 setTimeout(() => {
226 if (document.documentElement) {
227 observer.observe(document.documentElement, {
228 childList: true,
229 subtree: true
230 });
231 console.log('MutationObserver started');
232 }
233 }, 1000);
234
235 // Run cleanup periodically
236 setInterval(() => {
237 removeUnwantedElements();
238 cleanupDynamicAds();
239 }, 3000);
240
241 // Additional cleanup on page visibility change
242 document.addEventListener('visibilitychange', () => {
243 if (!document.hidden) {
244 setTimeout(() => {
245 removeUnwantedElements();
246 unlockPaywalledContent();
247 cleanupDynamicAds();
248 }, 500);
249 }
250 });
251
252 console.log('The Hindu Ad Blocker & Paywall Bypass - Active!');
253})();