r/Layer Cheat

Upload custom images to r/Layer's canvas.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         r/Layer Cheat
// @namespace    https://sakyum.xyz/
// @version      0.2
// @description  Upload custom images to r/Layer's canvas.
// @author       campital
// @match        *://layers-svc.reddit.com/static/layermaker/*
// @grant        GM_xmlhttpRequest
// @connect      *
// ==/UserScript==

"use strict";

let canvas = document.querySelector("layer-canvas");

let imageForm = document.createElement("form");
let imageUrlBox = document.createElement("input");
imageUrlBox.setAttribute("type", "url");
let submitBtn = document.createElement("button");
submitBtn.textContent = "Add Image";
imageForm.appendChild(document.createTextNode("Image URL: "));
imageForm.appendChild(imageUrlBox);
imageForm.appendChild(submitBtn);

var imgAbort;
imageForm.onsubmit = function(e) {
    e.preventDefault();
    if(typeof imgAbort === "function") {
        imgAbort();
    }
    imgAbort = GM_xmlhttpRequest({ method: "GET", url: imageUrlBox.value, responseType: "blob", onload: function(res) {
        let imgUri = URL.createObjectURL(res.response);
        let img = new Image;
        img.onload = function() {
            canvas.ctx.globalCompositeOperation = "source-over";
            canvas.ctx.drawImage(img, (canvas.cursor.x / canvas.width) * canvas.ctx.canvas.width,
                                 (canvas.cursor.y / canvas.height) * canvas.ctx.canvas.height);
            canvas.ctxDisplay.globalCompositeOperation = "source-over";
            canvas.ctxDisplay.drawImage(img, (canvas.cursor.x / canvas.width) * canvas.ctxDisplay.canvas.width,
                                        (canvas.cursor.y / canvas.height) * canvas.ctxDisplay.canvas.height);
            canvas.fullyUpdateMiniCanvas();
        }
        img.src = imgUri;
    }});
    imageUrlBox.value = "";
}
canvas.parentElement.appendChild(imageForm);