2023-10-07 17:55:50 +00:00
|
|
|
const save_value = ['post-title', 'post-text', 'post-url', 'hole']
|
2023-03-12 09:54:00 +00:00
|
|
|
for (const id of save_value) {
|
|
|
|
const value = localStorage.getItem(id)
|
|
|
|
if (value)
|
|
|
|
document.getElementById(id).value = value
|
|
|
|
}
|
2022-12-29 14:20:27 +00:00
|
|
|
|
2023-03-01 21:24:15 +00:00
|
|
|
autoExpand(document.getElementById('post-text'))
|
2023-03-12 09:54:00 +00:00
|
|
|
markdown(document.getElementById("post-text"));
|
2022-08-15 06:42:59 +00:00
|
|
|
|
2024-02-18 15:43:06 +00:00
|
|
|
const save_checked = ['post-notify', 'post-new', 'post-nsfw', 'post-draft', 'post-effortpost', 'post-ghost', 'post-cw']
|
2023-03-12 09:54:00 +00:00
|
|
|
for (const key of save_checked) {
|
|
|
|
const value = localStorage.getItem(key)
|
2023-03-12 19:43:29 +00:00
|
|
|
if (value) {
|
|
|
|
const element = document.getElementById(key)
|
|
|
|
if (element) element.checked = (value == 'true')
|
|
|
|
}
|
2023-02-17 23:44:53 +00:00
|
|
|
}
|
|
|
|
|
2023-03-12 09:54:00 +00:00
|
|
|
function savetext() {
|
|
|
|
for (const id of save_value)
|
|
|
|
{
|
|
|
|
const value = document.getElementById(id).value
|
2023-09-05 23:06:46 +00:00
|
|
|
if (value || id != 'post-text')
|
|
|
|
localStorage.setItem(id, value)
|
2023-03-12 09:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const id of save_checked) {
|
|
|
|
const element = document.getElementById(id)
|
|
|
|
if (element) {
|
|
|
|
localStorage.setItem(id, element.checked)
|
|
|
|
}
|
|
|
|
}
|
2023-02-08 06:22:11 +00:00
|
|
|
}
|
2022-07-16 21:00:02 +00:00
|
|
|
|
2023-03-12 19:44:00 +00:00
|
|
|
const submitButton = document.getElementById('submit-btn')
|
2023-03-12 09:54:00 +00:00
|
|
|
|
2022-08-11 17:18:53 +00:00
|
|
|
function checkForRequired() {
|
2022-08-14 03:20:43 +00:00
|
|
|
const title = document.getElementById("post-title");
|
|
|
|
const url = document.getElementById("post-url");
|
|
|
|
const text = document.getElementById("post-text");
|
|
|
|
const image = document.getElementById("file-upload");
|
|
|
|
const image2 = document.getElementById("file-upload-submit");
|
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
if (url.value.length > 0 || image.files.length > 0 || image2.files.length > 0) {
|
|
|
|
text.required = false;
|
|
|
|
url.required=false;
|
|
|
|
} else if (text.value.length > 0 || image.files.length > 0 || image2.files.length > 0) {
|
|
|
|
url.required = false;
|
|
|
|
} else {
|
|
|
|
text.required = true;
|
|
|
|
url.required = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const isValidTitle = title.checkValidity();
|
|
|
|
const isValidURL = url.checkValidity();
|
|
|
|
const isValidText = text.checkValidity();
|
|
|
|
|
|
|
|
if (isValidTitle && (isValidURL || image.files.length > 0 || image2.files.length > 0)) {
|
2023-02-08 07:21:52 +00:00
|
|
|
submitButton.disabled = false;
|
2022-07-16 21:00:02 +00:00
|
|
|
} else if (isValidTitle && isValidText) {
|
2023-02-08 07:21:52 +00:00
|
|
|
submitButton.disabled = false;
|
2022-07-16 21:00:02 +00:00
|
|
|
} else {
|
2023-02-08 07:21:52 +00:00
|
|
|
submitButton.disabled = true;
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
checkForRequired();
|
|
|
|
|
2023-08-11 16:19:06 +00:00
|
|
|
function remove_attachment() {
|
2023-09-13 23:33:38 +00:00
|
|
|
file_upload.value = null;
|
|
|
|
file_upload.previousElementSibling.textContent = 'Select File';
|
|
|
|
document.getElementById('image-preview').classList.add('d-none');
|
|
|
|
document.getElementById('image-preview').classList.remove('mr-2');
|
2023-08-11 16:19:06 +00:00
|
|
|
document.getElementById('urlblock').classList.remove('d-none');
|
2023-09-13 23:33:38 +00:00
|
|
|
document.getElementById('remove-attachment').classList.add('d-none');
|
|
|
|
checkForRequired();
|
2023-08-11 16:19:06 +00:00
|
|
|
clear_files("attachment");
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function autoSuggestTitle() {
|
|
|
|
|
2022-12-04 15:40:32 +00:00
|
|
|
const urlField = document.getElementById("post-url");
|
2022-07-16 21:00:02 +00:00
|
|
|
|
2022-12-04 15:40:32 +00:00
|
|
|
const titleField = document.getElementById("post-title");
|
2022-07-16 21:00:02 +00:00
|
|
|
|
2022-12-04 15:40:32 +00:00
|
|
|
const isValidURL = urlField.checkValidity();
|
2022-07-16 21:00:02 +00:00
|
|
|
|
|
|
|
if (isValidURL && urlField.value.length > 0 && titleField.value === "") {
|
|
|
|
|
2022-12-04 15:40:32 +00:00
|
|
|
const x = new XMLHttpRequest();
|
2023-03-10 03:21:02 +00:00
|
|
|
x.onreadystatechange = function() {
|
2022-07-16 21:00:02 +00:00
|
|
|
if (x.readyState == 4 && x.status == 200 && !titleField.value) {
|
|
|
|
|
|
|
|
title=JSON.parse(x.responseText)["title"];
|
|
|
|
titleField.value=title;
|
|
|
|
checkForRequired()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x.open('get','/submit/title?url=' + urlField.value);
|
2022-11-12 05:46:21 +00:00
|
|
|
x.setRequestHeader('xhr', 'xhr');
|
2022-07-16 21:00:02 +00:00
|
|
|
x.send(null);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-11-09 19:26:38 +00:00
|
|
|
function ghost_toggle(t) {
|
|
|
|
const followers = document.getElementById("post-notify")
|
2023-10-07 17:55:50 +00:00
|
|
|
const hole = document.getElementById("hole")
|
2022-07-16 21:00:02 +00:00
|
|
|
if (t.checked == true) {
|
|
|
|
followers.checked = false;
|
|
|
|
followers.disabled = true;
|
2023-10-07 17:55:50 +00:00
|
|
|
hole.value = '';
|
|
|
|
hole.disabled = true;
|
2022-07-16 21:00:02 +00:00
|
|
|
} else {
|
|
|
|
followers.disabled = false;
|
2023-10-07 17:55:50 +00:00
|
|
|
hole.disabled = false;
|
2022-09-04 23:15:37 +00:00
|
|
|
}
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkRepost() {
|
|
|
|
const system = document.getElementById('system')
|
2022-11-20 16:55:26 +00:00
|
|
|
system.innerHTML = "";
|
2022-07-16 21:00:02 +00:00
|
|
|
const url = document.getElementById('post-url').value
|
2022-10-14 10:26:48 +00:00
|
|
|
const min_repost_check = 9;
|
2022-07-16 21:00:02 +00:00
|
|
|
|
2022-10-14 10:26:48 +00:00
|
|
|
if (url && url.length >= min_repost_check) {
|
2022-07-16 21:00:02 +00:00
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("post", "/is_repost");
|
|
|
|
xhr.setRequestHeader('xhr', 'xhr');
|
2022-07-23 08:57:53 +00:00
|
|
|
const form = new FormData()
|
2022-07-16 21:00:02 +00:00
|
|
|
form.append("url", url);
|
2023-06-30 21:32:57 +00:00
|
|
|
form.append("formkey", formkey());
|
2022-07-16 21:00:02 +00:00
|
|
|
|
2023-03-10 03:21:02 +00:00
|
|
|
xhr.onload=function(){
|
2022-07-16 21:00:02 +00:00
|
|
|
try {data = JSON.parse(xhr.response)}
|
2023-03-12 09:54:14 +00:00
|
|
|
catch(e) {console.error(e)}
|
2022-09-04 23:15:37 +00:00
|
|
|
|
2022-07-16 21:00:02 +00:00
|
|
|
if (data && data["permalink"]) {
|
2022-11-16 00:28:21 +00:00
|
|
|
const permalinkText = escapeHTML(data["permalink"]);
|
|
|
|
const permalinkURI = encodeURI(data["permalink"]);
|
|
|
|
if (permalinkText) {
|
2022-11-20 16:55:26 +00:00
|
|
|
system.innerHTML = `This is a repost of <a href="${permalinkURI}">${permalinkText}</a>`;
|
2022-07-16 21:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xhr.send(form)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('keydown', (e) => {
|
2023-08-06 03:33:34 +00:00
|
|
|
if (!((e.ctrlKey || e.metaKey) && e.key === "Enter"))
|
2022-09-04 23:15:37 +00:00
|
|
|
return;
|
2022-07-16 21:00:02 +00:00
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
submitButton.click();
|
2022-07-16 21:00:02 +00:00
|
|
|
});
|
|
|
|
|
2023-08-06 03:26:16 +00:00
|
|
|
document.getElementById('post-title').addEventListener('keydown', (e) => {
|
2023-08-06 03:33:34 +00:00
|
|
|
if (e.key === "Enter") e.preventDefault();
|
2023-08-06 03:26:16 +00:00
|
|
|
})
|
|
|
|
|
2022-10-11 17:13:50 +00:00
|
|
|
checkRepost();
|
2022-12-29 14:20:27 +00:00
|
|
|
|
2023-02-08 07:15:37 +00:00
|
|
|
function submit(form) {
|
2023-02-08 07:21:52 +00:00
|
|
|
submitButton.disabled = true;
|
|
|
|
|
2023-02-08 07:15:37 +00:00
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
|
2024-02-19 20:34:54 +00:00
|
|
|
//needed for uploading to submit.watchpeopledie.tv
|
2023-10-04 17:00:47 +00:00
|
|
|
xhr.withCredentials = true;
|
2023-07-01 16:34:47 +00:00
|
|
|
|
2023-02-08 07:15:37 +00:00
|
|
|
formData = new FormData(form);
|
|
|
|
|
|
|
|
formData.append("formkey", formkey());
|
|
|
|
actionPath = form.getAttribute("action");
|
|
|
|
|
|
|
|
xhr.open("POST", actionPath);
|
2023-02-27 17:25:38 +00:00
|
|
|
|
|
|
|
const upload_prog = document.getElementById('upload-prog');
|
|
|
|
xhr.upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)};
|
|
|
|
|
2023-02-08 07:15:37 +00:00
|
|
|
xhr.setRequestHeader('xhr', 'xhr');
|
|
|
|
|
2023-03-10 03:21:02 +00:00
|
|
|
xhr.onload = function() {
|
2023-02-27 17:25:38 +00:00
|
|
|
upload_prog.classList.add("d-none")
|
2023-08-11 21:50:23 +00:00
|
|
|
const success = xhr.status >= 200 && xhr.status < 300
|
2023-02-27 17:25:38 +00:00
|
|
|
|
2023-08-11 21:50:23 +00:00
|
|
|
if (success) {
|
2023-03-09 05:52:20 +00:00
|
|
|
const res = JSON.parse(xhr.response)
|
|
|
|
const post_id = res['post_id'];
|
|
|
|
|
|
|
|
if (res['success']) {
|
2023-03-12 09:54:00 +00:00
|
|
|
for (const id of save_value) {
|
|
|
|
localStorage.setItem(id, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const id of save_checked) {
|
|
|
|
const value = (id == "post-notify")
|
|
|
|
localStorage.setItem(id, value)
|
|
|
|
}
|
2023-08-07 13:09:46 +00:00
|
|
|
|
2023-08-11 16:19:06 +00:00
|
|
|
clear_files("attachment")
|
|
|
|
clear_files("textarea")
|
2023-03-09 05:52:20 +00:00
|
|
|
}
|
2023-02-10 17:02:45 +00:00
|
|
|
|
2023-02-08 07:15:37 +00:00
|
|
|
location.href = "/post/" + post_id
|
|
|
|
} else {
|
2023-02-08 16:50:02 +00:00
|
|
|
submitButton.disabled = false;
|
2023-08-11 21:50:23 +00:00
|
|
|
const data = JSON.parse(xhr.response);
|
|
|
|
showToast(success, getMessageFromJsonData(success, data));
|
2023-02-08 07:15:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
xhr.send(formData);
|
|
|
|
}
|
2023-08-07 13:09:46 +00:00
|
|
|
|
2023-08-08 10:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//SAVE FILES
|
|
|
|
|
2023-09-29 01:10:05 +00:00
|
|
|
const indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
|
2023-08-08 10:55:14 +00:00
|
|
|
|
|
|
|
const open = indexedDB.open("files", 1);
|
|
|
|
|
|
|
|
open.onupgradeneeded = () => {
|
|
|
|
const db = open.result;
|
|
|
|
db.createObjectStore("files", {keyPath:"kind"});
|
|
|
|
db.close();
|
2023-08-07 13:09:46 +00:00
|
|
|
}
|
|
|
|
|
2023-08-08 10:55:14 +00:00
|
|
|
function submit_save_files(kind, files) {
|
|
|
|
const open = indexedDB.open("files", 1);
|
|
|
|
open.onsuccess = () => {
|
|
|
|
const db = open.result;
|
|
|
|
const tx = db.transaction("files", "readwrite");
|
|
|
|
const store = tx.objectStore("files");
|
2023-08-07 13:09:46 +00:00
|
|
|
|
2023-08-08 10:55:14 +00:00
|
|
|
tx.oncomplete = () => {
|
|
|
|
db.close();
|
|
|
|
};
|
2023-08-07 13:09:46 +00:00
|
|
|
|
2023-08-08 10:55:14 +00:00
|
|
|
store.put({kind:kind, files:files});
|
|
|
|
}
|
2023-08-07 13:09:46 +00:00
|
|
|
}
|
|
|
|
|
2023-08-08 10:55:14 +00:00
|
|
|
|
|
|
|
//RESTORE FILES
|
|
|
|
|
|
|
|
function submit_restore_files(kind, id) {
|
|
|
|
const open = indexedDB.open("files", 1);
|
|
|
|
open.onsuccess = () => {
|
|
|
|
const db = open.result;
|
|
|
|
const tx = db.transaction("files", "readwrite");
|
|
|
|
const store = tx.objectStore("files");
|
|
|
|
|
|
|
|
tx.oncomplete = () => {
|
|
|
|
db.close();
|
|
|
|
};
|
|
|
|
|
|
|
|
const get_files = store.get(kind);
|
|
|
|
|
|
|
|
get_files.onsuccess = () => {
|
|
|
|
let files = get_files.result
|
|
|
|
if (!files) return
|
|
|
|
files = files.files
|
|
|
|
|
|
|
|
const list = new DataTransfer();
|
|
|
|
for (const file of files) {
|
|
|
|
list.items.add(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById(id).files = list.files
|
|
|
|
|
|
|
|
if (kind == "attachment") {
|
2023-08-08 14:20:42 +00:00
|
|
|
display_url_image()
|
2023-08-08 10:55:14 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
oldfiles["post-text"] = new DataTransfer();
|
|
|
|
for (const file of files) {
|
|
|
|
oldfiles["post-text"].items.add(file);
|
2023-09-07 15:26:31 +00:00
|
|
|
}
|
2023-08-08 10:55:14 +00:00
|
|
|
}
|
|
|
|
};
|
2023-08-07 13:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-08 10:55:14 +00:00
|
|
|
submit_restore_files("attachment", "file-upload")
|
|
|
|
submit_restore_files("textarea", "file-upload-submit")
|
|
|
|
|
|
|
|
|
|
|
|
//CLEAR FILES
|
|
|
|
|
2023-08-11 16:19:06 +00:00
|
|
|
function clear_files(kind) {
|
2023-08-08 10:55:14 +00:00
|
|
|
const open = indexedDB.open("files", 1);
|
|
|
|
open.onsuccess = () => {
|
|
|
|
const db = open.result;
|
|
|
|
const tx = db.transaction("files", "readwrite");
|
|
|
|
const store = tx.objectStore("files");
|
|
|
|
|
|
|
|
tx.oncomplete = () => {
|
|
|
|
db.close();
|
|
|
|
};
|
|
|
|
|
2023-08-11 16:19:06 +00:00
|
|
|
store.delete(kind);
|
2023-08-08 10:55:14 +00:00
|
|
|
}
|
|
|
|
}
|