Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve 'trusted-create-element' — allow creation of inner elements for created iframe #459

Open
Yuki2718 opened this issue Oct 15, 2024 · 0 comments
Assignees
Labels
enhancement Improvement of existent feature Priority: P4

Comments

@Yuki2718
Copy link

Yuki2718 commented Oct 15, 2024

wiki.yjsnpi.nu removes images if they detect blocker on any subpages having images (ex. https://wiki.yjsnpi.nu/wiki/%E3%81%9B%E3%81%84%E3%82%84), and if I understand correctly, they check not only iframes created by i-mobile.co.jp script but also their inner elements having .creative class with this code (it's under cat-and-mouse game, the code may change):

Code
if (document.getElementsByName('noad').length !== 1) {
		let detected = false;

		if (!detected) {
			const iframes = document.querySelectorAll('iframe');
			iframes.forEach((iframe) => {
				const computedStyle = window.getComputedStyle(iframe, null);
				if (computedStyle.display === 'none' || computedStyle.height === '0px') { detected = true; return; }
			});
		}

		if (detected) {
			const elms = document.querySelectorAll('span:has(>img), .page-' + RLCONF['wgArticleId'] + ' img, a:has(>img)');
			elms.forEach((elm) => { elm.style.height = '0'; });
			elms.forEach((elm) => { elm.style.opacity = '0'; });
			elms.forEach((elm) => { elm.style.visibility = 'hidden'; })
			elms.forEach((elm) => { elm.style.display = 'none'; });
			elms.forEach((elm) => { elm.remove(); });
			document.querySelector('.mw-page-container, #content').style.backgroundColor = '#fdfdfd';
		}

		if (!detected) {
			new MutationObserver((mutationList, observer) => {
				if (document.getElementById('comments-loading') === null) {
					let detected = false;
					if (document.querySelectorAll('iframe').length === 0) { detected = true; }
					const im = document.querySelectorAll('.im');
					if (im.length === 0) { detected = true; }
					im.forEach((im) => {
						const iframes = im.querySelectorAll('iframe');
						if (iframes.length === 0) { detected = true; return; }
						iframes.forEach((iframe) => {
							const contentDocument = iframe.contentDocument;
							if (contentDocument.querySelector('.creative') === null) { detected = true; return; }
						});
						if (detected) { return; }
					});
					if (detected) {
						const elms = document.querySelectorAll('span:has(>img), .page-' + RLCONF['wgArticleId'] + ' img, a:has(>img)');
						elms.forEach((elm) => { elm.style.height = '0'; });
						elms.forEach((elm) => { elm.style.opacity = '0'; });
						elms.forEach((elm) => { elm.style.visibility = 'hidden'; })
						elms.forEach((elm) => { elm.style.display = 'none'; });
						elms.forEach((elm) => { elm.remove(); });
						document.querySelector('.mw-page-container, #content').style.backgroundColor = '#fdfdfd';
					}
					observer.disconnect();
				}
			}).observe(document.getElementById('bodyContent'), { attributes: false, childList: true, subtree: true });
		}
	}
@slavaleleka slavaleleka added the enhancement Improvement of existent feature label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existent feature Priority: P4
Projects
None yet
Development

No branches or pull requests

4 participants