ENSShared

Shared code for my scripts

Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta // @require https://update.greasyfork.org/scripts/446540/1061588/ENSShared.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

const c = document.createElement("canvas");
const ctx = c.getContext("2d");

const imageToBlob = (imageURL) => {
	const img = new Image;
	img.crossOrigin = "";
	img.src = imageURL;
	return new Promise(resolve => {
		img.onload = function () {
			c.width = this.naturalWidth;
			c.height = this.naturalHeight;
			ctx.drawImage(this, 0, 0);
			c.toBlob((blob) => {
				resolve(blob)
			}, "image/png", 0.75);
		};
	})
}

const toggleAttribute = (elem, attr, val) => {
	const tgattr = (elem, attr, val) => {
		if (elem.hasAttribute(attr)) {
			let atrval = elem.getAttribute(attr);
			if (atrval.includes(val)) {
				let rep = atrval.replace(val, '');
				!rep.length ? elem.removeAttribute(attr) : elem.setAttribute(attr, rep);
			} else elem.setAttribute(attr, elem.getAttribute(attr) + val);
		} else elem.setAttribute(attr, val);
	}

	if (elem instanceof Array) {
		for (let key in elem) {
			tgattr(elem[key], attr, val);
		}
	} else tgattr(elem, attr, val);
}

const awaitSelector = (selector) => {
	return new Promise((resolve) => {
		const nodes = [];
		setInterval(() => {
			if (nodes.length !== 0) {
				clearInterval(tm);
				resolve(nodes);
			}
			nodes.splice(nodes.length, 0, ...document.querySelectorAll(selector));
		}, 100);
	});
}