Skip to content

Commit

Permalink
3.11.23
Browse files Browse the repository at this point in the history
  • Loading branch information
green1052 committed Jan 13, 2025
1 parent dc8335a commit e3ec3f0
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 236 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dcrefresher-reborn",
"version": "3.11.22",
"version": "3.11.23",
"description": "디시인사이드 개선 확장 프로그램",
"devDependencies": {
"@swc/core": "^1.10.7",
Expand All @@ -25,7 +25,6 @@
"vue-fragment": "1.6.0",
"vue-loader": "15.11.1",
"webextension-polyfill": "^0.12.0",
"webp-converter-browser": "^1.0.4",
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1",
"webpack-merge": "^6.0.1"
Expand Down
23 changes: 0 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions src/assets/js/editor.ts

This file was deleted.

223 changes: 31 additions & 192 deletions src/modules/write.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import * as Toast from "../components/toast";
import $ from "cash-dom";
import ky from "ky";
import {blobToWebP} from "webp-converter-browser";
import {Cash} from "cash-dom/dist/cash";
import {inject} from "../utils/inject";

export default {
name: "글쓰기",
Expand All @@ -25,18 +20,6 @@ export default {
enable: false,
default_enable: false,
settings: {
bypassUpload: {
name: "이미지 우회 업로드",
desc: "이미지 업로드를 우회합니다. (활성화 시 이미지 제한을 우회할 수 있으나 아이콘이 안 보이는 등 여러 문제가 발생할 수도 있습니다.)",
type: "check",
default: false
},
imageUpload: {
name: "이미지 업로드",
desc: "붙여넣기로 이미지를 업로드할 수 있습니다.",
type: "check",
default: false
},
bypassTitleLimit: {
name: "제목 글자수 제한 우회",
desc: "제목 글자수 제한을 우회합니다.",
Expand All @@ -61,22 +44,6 @@ export default {
type: "text",
default: ""
},
convertWebp: {
name: "WebP 변환",
desc: "이미지 업로드 기능으로 업로드시 이미지를 WebP로 변환합니다.",
type: "check",
default: false
},
convertWebpQuality: {
name: "WebP 변환 품질",
desc: "WebP 변환 품질을 설정합니다.",
type: "range",
default: 70,
min: 1,
max: 100,
step: 1,
unit: "%"
},
temporarySave: {
name: "임시 저장",
desc: "글 작성 중 내용을 임시 저장합니다.",
Expand All @@ -99,48 +66,12 @@ export default {
this.data!.temporarySave.date = 0;
};

inject("../assets/js/editor.js");

window.addEventListener("message", (event) => {
if (event.source !== window || event.data?.type !== "refresherEditorLoaded") return;


});

window.addEventListener("beforeunload", (ev) => {
if (this.status.preventExit && !$("button:hover").eq(-1).hasClass("write")) {
ev.preventDefault();
}
});

const attachImage = ($contentContainer: Cash, data: string | Record<string, string>) => {
if (!this.status.bypassUpload && typeof data === "object") {
const url = data.web__url ?? data.url;

$("#upload_status").val("Y");

window.postMessage({
type: "refresherAttachUpload",
data: {
imageurl: url,
filename: data.name,
filesize: data.size,
imagealign: "L",
originalurl: url,
thumburl: url,
file_temp_no: data.file_temp_no,
mp4: ""
}
}, "*");

return;
}

const url = typeof data === "string" ? data : data.web__url ?? data.url;

$contentContainer.append(`<p style="text-align: left"><img style="clear: none; float: none" id="tx_entry_${Math.floor(Math.random() * 90000) + 10000}_" src="${url}" class=txc-image></p>`);
};

this.memory.submitButton = filter.add<HTMLButtonElement>(
"button.write",
(element) => {
Expand All @@ -149,30 +80,19 @@ export default {
const footer = this.status.footer;
const selfImage = this.status.selfImage;

const $canvas = $("#tx_canvas_wysiwyg").contents().find("body");
const canvas = $canvas.get(0) as HTMLBodyElement;

const selectTop = () => {
if (!canvas) return;

canvas.focus();
// @ts-ignore
canvas.setSelectionRange(0, 0);
};
const $editor = $(".note-editable");

if (selfImage) {
selectTop();
attachImage($canvas, selfImage);
$("#upload_status").val("Y");
$editor.prepend(`<img src="${selfImage}">`);
}

if (header) {
selectTop();
$canvas
.prepend(`${header}`);
$editor.prepend(header);
}

if (footer) {
$canvas.append(`${footer}`);
$editor.append(footer);
}

if (this.status.bypassTitleLimit) {
Expand All @@ -190,117 +110,40 @@ export default {
);

this.memory.canvas = filter.add<HTMLIFrameElement>(
"#tx_canvas_wysiwyg",
".note-editable",
(element) => {
window.addEventListener("message", (event) => {
if (event.source !== window || event.data?.type !== "refresherEditorLoaded") return;

const $dom = $(element.contentDocument);
const $contentContainer = $dom.find("body");

if (this.status.imageUpload) {
$contentContainer.on("paste", async (ev: ClipboardEvent) => {
const data = ev.clipboardData;

if (!data || !data.files.length) return;

ev.stopPropagation();
ev.preventDefault();

Toast.show("이미지 업로드 중...", false, 1000);

const r_key = $("#r_key").val() as string;
const gall_id = $("#id").val() as string;
const gall_no = $("#gallery_no").val() as string;
const _GALLTYPE_ = $("#_GALLTYPE_").val() as string;
const post_no = $("#no").val() as string;

const form = new FormData();
form.append("r_key", r_key);
form.append("gall_id", gall_id);
form.append("gall_no", gall_no);
form.append("post_no", post_no || "");
form.append("upload_ing", "N");
form.append("_GALLTYPE_", _GALLTYPE_);
const $element = $(element);

const images = [];
if (this.status.temporarySave) {
const gallId = $("form > input[name=id]").val() as string;

for (const file of data.files) {
if (!file.type.startsWith("image/")) continue;

const image = this.status.convertWebp
? await blobToWebP(file, {
quality: this.status.convertWebpQuality / 100
})
: file;

form.set(
"files[]",
new File(
[image],
`${new Date().getTime()}.${file.name.split(".").at(-1)}`,
{
type: image.type
}
)
);

try {
const response = await ky.post("https://upimg.dcinside.com/upimg_file.php", {
searchParams: {
id: gall_id,
r_key
},
body: form,
timeout: 30000
}).json<any>();

images.push(response.files[0]);
} catch (e) {
Toast.show(String(e), true, 5000);
return;
}
}

for (const image of images) {
attachImage($contentContainer, image);
}

Toast.show("이미지 업로드 완료", false, 1000);
});
if (Date.now() - this.data!.temporarySave.date > 86400000) {
resetTemporaryData();
}

if (this.status.temporarySave) {
const gallId = $("form > input[name=id]").val() as string;

if (Date.now() - this.data!.temporarySave.date > 86400000) {
resetTemporaryData();
}
if (
this.data!.temporarySave.id === gallId &&
this.data!.temporarySave.title &&
this.data!.temporarySave.content &&
this.data!.temporarySave.date &&
confirm("이전에 작성한 글이 있습니다. 불러오시겠습니까? (취소 시 삭제)")
) {
$("#subject").val(this.data!.temporarySave.title);
$element.html(this.data!.temporarySave.content);
} else {
resetTemporaryData();
}

if (
this.data!.temporarySave.id === gallId &&
this.data!.temporarySave.title &&
this.data!.temporarySave.content &&
this.data!.temporarySave.date &&
confirm("이전에 작성한 글이 있습니다. 불러오시겠습니까? (취소 시 삭제)")
) {
$("#subject").val(this.data!.temporarySave.title);
$contentContainer.html(this.data!.temporarySave.content);
} else {
resetTemporaryData();
}
this.data!.temporarySave.id = gallId;

this.data!.temporarySave.id = gallId;
setInterval(() => {
this.data!.temporarySave.title = $("#subject").val() as string;
this.data!.temporarySave.content = $element.html() as string;
this.data!.temporarySave.date = Date.now();
}, 5000);
}

setInterval(() => {
this.data!.temporarySave.title = $("#subject").val() as string;
this.data!.temporarySave.content = $contentContainer.html() as string;
this.data!.temporarySave.date = Date.now();
}, 5000);
}

filter.remove(this.memory.canvas);
});
filter.remove(this.memory.canvas);
});
},
revoke(filter) {
Expand All @@ -321,14 +164,10 @@ export default {
canvas: string;
};
settings: {
bypassUpload: RefresherCheckSettings;
imageUpload: RefresherCheckSettings;
bypassTitleLimit: RefresherCheckSettings;
selfImage: RefresherTextSettings;
header: RefresherTextSettings;
footer: RefresherTextSettings;
convertWebp: RefresherCheckSettings;
convertWebpQuality: RefresherRangeSettings;
temporarySave: RefresherCheckSettings;
preventExit: RefresherCheckSettings;
};
Expand Down
Loading

0 comments on commit e3ec3f0

Please sign in to comment.