Greasy Fork daha iyi yapın
// ==UserScript==
// @name Greasy Fork
// @namespace http://tampermonkey.net/
// @version 1
// @description Greasy Fork daha iyi yapın
// @author Atilla
// @match https://greasyfork.org/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
// @grant GM_setClipboard
// @run-at document-idle
// @license MIT
// ==/UserScript==
(async () => {
"use strict";
// 1. Tembel Yükleme (Lazy Loading) Optimizasyonu
const applyLazyLoading = (root = document) => {
const targets = root.querySelectorAll(
'img:not([loading="lazy"]), video:not([loading="lazy"]), iframe:not([loading="lazy"])',
);
targets.forEach((element) => element.setAttribute("loading", "lazy"));
};
applyLazyLoading();
// 2. Otomatik Tamamlama Kapatma Optimizasyonu
const disableAutocomplete = (root = document) => {
const inputs = root.querySelectorAll('input:not([autocomplete="off"])');
inputs.forEach((input) => input.setAttribute("autocomplete", "off"));
};
disableAutocomplete();
// DOM Değişikliklerini Tek Bir MutationObserver İle Yönetme
const observer = new MutationObserver((mutations) => {
let shouldUpdateLazy = false;
let shouldUpdateAuto = false;
mutations.forEach((mutation) => {
if (mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === Node.ELEMENT_NODE) {
if (
!shouldUpdateLazy &&
(node.matches("img, video, iframe") ||
node.querySelector("img, video, iframe"))
) {
shouldUpdateLazy = true;
}
if (
!shouldUpdateAuto &&
(node.matches("input") || node.querySelector("input"))
) {
shouldUpdateAuto = true;
}
}
});
}
});
if (shouldUpdateLazy) applyLazyLoading();
if (shouldUpdateAuto) disableAutocomplete();
});
observer.observe(document.body, { childList: true, subtree: true });
// 3. Kodu Kopyala Butonu Ekleme
const jsInstallAnchor = document.querySelector("a[data-install-format='js']");
if (jsInstallAnchor) {
const copyButtonDiv = document.getElementById("install-area");
if (copyButtonDiv) {
const copyButton = document.createElement("a");
copyButton.classList.add("install-link");
copyButton.style.cursor = "pointer";
copyButton.textContent = "Kodu Kopyala";
const copyHelpButton = document.createElement("a");
copyHelpButton.classList.add("install-help-link");
copyHelpButton.textContent = "\u{1F4CB}";
copyHelpButton.style.cursor = "pointer";
copyButtonDiv.prepend(copyButton);
copyButton.after(copyHelpButton);
const handleCopyClick = async (event) => {
event.preventDefault();
const url = jsInstallAnchor.href;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP hatası! Durum: ${response.status}`);
}
const rawCode = await response.text();
GM_setClipboard(rawCode);
alert("Ham JAVASCRIPT Kopyalandı!");
} catch (error) {
alert(`Veri çekilirken hata oluştu: ${error.message}`);
}
};
copyButton.addEventListener("click", handleCopyClick);
}
}
// 4. Otomatik Kod Uyarılarının Kaldırılması (Message Event Delegation)
window.addEventListener("message", () => {
const alertModals = document.querySelectorAll(
"#installation-instructions-modal-css, #installation-instructions-modal-js",
);
alertModals.forEach((modal) => modal.remove());
});
// 5. Kod Renklendirmesini Sıfırlayan Stil Ekleme
const noColorStyle = document.createElement("style");
noColorStyle.id = "prettify-reset-style";
noColorStyle.textContent =
".prettyprint, .prettyprint * { color: inherit !important; background-color: transparent !important; border: none !important; font-weight: normal !important; font-style: normal !important; }";
document.head.append(noColorStyle);
// 6. Ekran Genişliği Kontrolü ve Debounce Mekanizması
const checkWidthAndReload = async () => {
if (window.innerWidth < 1018) {
document.body.textContent =
"Bu sitede bu kod çalışmaz! Sayfa yenileniyor...2";
await new Promise((resolve) => setTimeout(resolve, 2000));
location.reload();
}
};
// İlk yüklemedeki kontrol
await checkWidthAndReload();
// Resize olayını stabilize etmek için debounce fonksiyonu
const debounce = (func, delay) => {
let timeoutId;
return (...args) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => func(...args), delay);
};
};
window.addEventListener("resize", debounce(checkWidthAndReload, 250));
})();