r/Layer Cheat

Upload custom images to r/Layer's canvas.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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);