<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.

Stan na 05-10-2020. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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>`

		)

);