<iframe> click to load

NOT lazyload; click a button instead anywhere in the whole <iframe> element so one won't mis-click; will ignore small / narrow <iframe>s.

Versione datata 05/10/2020. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        <iframe> click to load
// @name:zh-CN 手动加载 <iframe>
// @description NOT lazyload; click a button instead anywhere in the whole <iframe> element so one won't mis-click; will ignore small / narrow <iframe>s.
// @description:zh-CN 不是 lazyload;点击按钮而不是点击 <iframe> 元素,以免误触;会忽略大小较小的 <iframe> 元素。
// @namespace   RainSlide
// @author      RainSlide
// @version     1.0
// @match       *://*/*
// @grant       none
// @inject-into context
// @run-at      document-end
// ==/UserScript==

document.querySelectorAll('iframe').forEach(
	iframe =>

		// attribute
		iframe.getAttribute("src")    !== null &&
		iframe.getAttribute("srcdoc") === null &&

		// content size
		iframe.clientWidth  >= 72 &&
		iframe.clientHeight >= 72 &&
		( iframe.clientWidth + iframe.clientHeight ) >= 256 &&

		iframe.setAttribute("srcdoc",

`<style>
html, body { height: 100%; }
body {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	box-sizing: border-box;
	min-width: 5em;
	margin: 0;
	padding: .5em;
	border: 2px dashed currentColor;
}
a {
	margin-bottom: 1ex;
	word-break: break-all;
	font-family: monospace;
}
</style>
<a href="${ iframe.src }" target="_blank" rel="noreferrer noopener">${ iframe.src }</a>
<button onclick="window.frameElement.removeAttribute('srcdoc')">${
	new Map([
		["en-US", "Load"],
		["zh-CN", "加载"],
		["zh-TW", "加載"],
		["zh-HK", "加載"]
	]).get( navigator.language ) || "Load"
}</button>`

		)

);