Skip to content

Instantly share code, notes, and snippets.

@gaeulbyul
Last active August 4, 2022 16:04
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gaeulbyul/4f622ba80513e0f4d0dd3f13dcd085db to your computer and use it in GitHub Desktop.
Save gaeulbyul/4f622ba80513e0f4d0dd3f13dcd085db to your computer and use it in GitHub Desktop.
트윗덱(or 트윗덱 플레이어)에 이미지를 붙여넣기하여 업로드하는 스크립트.
// ==UserScript==
// @name TweetDeck Paste Image
// @namespace gaeulbyul.userscript
// @description 트윗덱에 클립보드 붙여넣기(Ctrl-V)로 이미지를 업로드하는 기능을 추가한다.
// @author Gaeulbyul
// @license WTFPL
// @include https://tweetdeck.twitter.com/
// @version 0.3b3
// @run-at document-end
// @grant none
// ==/UserScript==
void (function ($) {
var catcher = $("<div>")
.attr("contenteditable", true)
.css("opacity", 0)
.appendTo(document.body)
.focus();
function dataURIToBlob(dataURI) {
var [mimeString, encodedData] = dataURI.split(",");
var byteString;
if (dataURI.split(",")[0].indexOf("base64") >= 0) {
byteString = atob(encodedData);
} else {
byteString = unescape(encodedData);
}
var type = mimeString.match(/^data:(.+);/)[1];
var ia = new Uint8Array(byteString.length);
for (let i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
var blob = new Blob([ia], { type });
return blob;
}
function waitClipboard() {
var cer = catcher[0];
var child = cer.childNodes && cer.childNodes[0];
if (child) {
if (child.tagName === "IMG") {
var file = dataURIToBlob(child.src);
pasteFile([file]);
}
cer.innerHTML = "";
} else {
setTimeout(waitClipboard, 100);
}
}
function pasteFile(files) {
// 트윗 입력창을 닫은 이후에 멘션 안 남게
if (!$(".app-content").hasClass("is-open")) {
$(document).trigger("uiComposeTweet", { type: "tweet" });
}
$(document).trigger("uiFilesAdded", { files });
}
$(document.body).on("paste", function (event) {
if ($(".js-add-image-button").hasClass("is-disabled")) return;
try {
var clipdata = event.originalEvent.clipboardData;
var items = clipdata.items;
var item = items[0];
} catch (e) {
catcher.focus();
setTimeout(waitClipboard, 300);
return;
}
if (item.kind !== "file") return;
var file = [item.getAsFile()];
pasteFile(file);
});
})(
window.webpackJsonp.push([
[],
{
$(m, e, r) {
return (m.exports = r(0));
},
},
[["$"]],
])
);
@JuicyJuuce
Copy link

Does this script still work? I just tried it with no success.

I'm using the latest Tampermonkey on the latest Chrome.

@gaeulbyul
Copy link
Author

@JuicyJuuce Hello! I just updated it to make it works again. does it works now?

@JuicyJuuce
Copy link

Unfortunately it still isn't working. If you want, you can contact me on Discord to troubleshoot: JuicyJuuce#3493

@sharusen
Copy link

편리한 코드 감사합니다.
직접 printscreen으로 캡쳐했을때는 붙여넣기가 잘 됩니다.
하지만 이미지 복사를 선택해서 할때는 붙여넣기가 안되는 것 같은데
시간이 남으시면 한번 봐주셨으면합니다.

@aproid
Copy link

aproid commented Aug 4, 2022

https://gist.github.com/aproid/ce625108534d6f8b73b51a7ea8750dc9
이미지 복사도 가능하게 코드 변경하였습니다. 감사히 잘 쓰겠습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment