mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-06-10 07:19:26 +02:00
Add Submit Direct to GitHub and Copy button
This commit is contained in:
parent
5992be6391
commit
c5dfb76160
|
@ -11,6 +11,9 @@ window.instanceId = instanceId
|
||||||
const instanceSubreddit = "placeAtlas2"
|
const instanceSubreddit = "placeAtlas2"
|
||||||
window.instanceSubreddit = instanceSubreddit
|
window.instanceSubreddit = instanceSubreddit
|
||||||
|
|
||||||
|
const instanceRepo = "https://github.com/placeAtlas/atlas"
|
||||||
|
window.instanceRepo = instanceRepo
|
||||||
|
|
||||||
const pageTitle = "The 2022 r/place Atlas"
|
const pageTitle = "The 2022 r/place Atlas"
|
||||||
window.pageTitle = pageTitle
|
window.pageTitle = pageTitle
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,10 @@ const periodsAdd = document.getElementById('periodsAdd')
|
||||||
|
|
||||||
const exportButton = document.getElementById("exportButton")
|
const exportButton = document.getElementById("exportButton")
|
||||||
const cancelButton = document.getElementById("cancelButton")
|
const cancelButton = document.getElementById("cancelButton")
|
||||||
const exportDirectPostButton = document.getElementById("exportDirectPost")
|
const redditPostButton = document.getElementById("exportRedditPost")
|
||||||
let exportDirectPostTooltip = null
|
let redditPostTooltip = null
|
||||||
|
const githubPostButton = document.getElementById("exportGithubPost")
|
||||||
|
let githubPostTooltip = null
|
||||||
|
|
||||||
const exportModalElement = document.getElementById("exportModal")
|
const exportModalElement = document.getElementById("exportModal")
|
||||||
const exportModal = new bootstrap.Modal(exportModalElement)
|
const exportModal = new bootstrap.Modal(exportModalElement)
|
||||||
|
@ -86,6 +88,17 @@ baseInputField.type = "text"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// https://gist.github.com/codeguy/6684588?permalink_comment_id=3243980#gistcomment-3243980
|
||||||
|
function slugify(text) {
|
||||||
|
return text
|
||||||
|
.normalize('NFKD')
|
||||||
|
.toLowerCase()
|
||||||
|
.trim()
|
||||||
|
.replace(/\s+/g, '-')
|
||||||
|
.replace(/[^\w\-]+/g, '')
|
||||||
|
.replace(/\-+/g, '-');
|
||||||
|
}
|
||||||
|
|
||||||
window.initDraw = initDraw
|
window.initDraw = initDraw
|
||||||
function initDraw() {
|
function initDraw() {
|
||||||
// Adds exit draw button and removes list button
|
// Adds exit draw button and removes list button
|
||||||
|
@ -303,43 +316,76 @@ function initDraw() {
|
||||||
return exportObject
|
return exportObject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.getElementById("exportCopy").addEventListener("click", () => {
|
||||||
|
navigator.clipboard.writeText(exportArea.value)
|
||||||
|
})
|
||||||
|
|
||||||
function exportJson() {
|
function exportJson() {
|
||||||
const exportObject = generateExportObject()
|
const exportObject = generateExportObject()
|
||||||
|
const prettyJsonString = JSON.stringify(exportObject, null, "\t")
|
||||||
|
const miniJsonString = JSON.stringify(exportObject)
|
||||||
|
|
||||||
let prettyJsonString = JSON.stringify(exportObject, null, "\t")
|
// Export area
|
||||||
prettyJsonString = " " + prettyJsonString.split("\n").join("\n ")
|
|
||||||
exportArea.value = prettyJsonString
|
|
||||||
let directPostJsonString = prettyJsonString
|
|
||||||
|
|
||||||
let directPostUrl = `https://www.reddit.com/r/${instanceSubreddit}/submit?selftext=true&title=`
|
|
||||||
if (exportObject.id === 0) directPostUrl += `✨%20${encodeURIComponent(exportObject.name)}`
|
|
||||||
else directPostUrl += `✏%20${encodeURIComponent(exportObject.name)}`
|
|
||||||
directPostUrl += "&text="
|
|
||||||
|
|
||||||
if (directPostJsonString.length + directPostJsonString > 7579) {
|
exportArea.value = " " + prettyJsonString.split("\n").join("\n ")
|
||||||
directPostJsonString = " " + JSON.stringify(exportObject)
|
|
||||||
}
|
|
||||||
if (exportArea.value > 40000) {
|
if (exportArea.value > 40000) {
|
||||||
exportArea.value = " " + JSON.stringify(exportObject)
|
exportArea.value = " " + miniJsonString
|
||||||
}
|
}
|
||||||
directPostUrl += encodeURIComponent(directPostJsonString)
|
|
||||||
|
// Reddit
|
||||||
|
|
||||||
if (directPostUrl.length > 7579) {
|
let redditPostJsonString = " " + prettyJsonString.split("\n").join("\n ")
|
||||||
// exportDirectPostButton.classList.add("disabled")
|
let redditPostUrl = `https://www.reddit.com/r/${instanceSubreddit}/submit?selftext=true&title=`
|
||||||
// exportDirectPostButton.ariaDisabled = true
|
if (exportObject.id === 0) redditPostUrl += `✨%20${encodeURIComponent(exportObject.name)}`
|
||||||
exportDirectPostButton.dataset.bsToggle = "tooltip"
|
else redditPostUrl += `✏%20${encodeURIComponent(exportObject.name)}`
|
||||||
exportDirectPostButton.dataset.bsTitle = "This may not work due to the length of the entry. If needed, please copy manually."
|
redditPostUrl += "&text="
|
||||||
if (!exportDirectPostTooltip) exportDirectPostTooltip = new bootstrap.Tooltip(exportDirectPostButton)
|
|
||||||
} else {
|
if (encodeURIComponent(redditPostJsonString).length > 7579 - redditPostUrl.length) {
|
||||||
// exportDirectPostButton.classList.remove("disabled")
|
redditPostJsonString = " " + miniJsonString
|
||||||
// exportDirectPostButton.ariaDisabled = false
|
|
||||||
exportDirectPostButton.dataset.bsTitle = ""
|
|
||||||
}
|
}
|
||||||
exportDirectPostButton.href = directPostUrl
|
|
||||||
|
redditPostUrl += encodeURIComponent(redditPostJsonString)
|
||||||
|
if (encodeURIComponent(redditPostUrl).length > 7579) {
|
||||||
|
// redditPostButton.classList.add("disabled")
|
||||||
|
// redditPostButton.ariaDisabled = true
|
||||||
|
redditPostButton.dataset.bsToggle = "tooltip"
|
||||||
|
redditPostButton.dataset.bsTitle = "This may not work due to the length of the entry. If needed, please copy manually."
|
||||||
|
if (!redditPostTooltip) redditPostTooltip = new bootstrap.Tooltip(redditPostButton)
|
||||||
|
} else {
|
||||||
|
// redditPostButton.classList.remove("disabled")
|
||||||
|
// redditPostButton.ariaDisabled = false
|
||||||
|
redditPostButton.dataset.bsTitle = ""
|
||||||
|
}
|
||||||
|
redditPostButton.href = redditPostUrl
|
||||||
|
|
||||||
if (exportObject.id === 0) document.getElementById("redditFlair").textContent = "New Entry"
|
if (exportObject.id === 0) document.getElementById("redditFlair").textContent = "New Entry"
|
||||||
else document.getElementById("redditFlair").textContent = "Edit Entry"
|
else document.getElementById("redditFlair").textContent = "Edit Entry"
|
||||||
|
|
||||||
|
// GitHub
|
||||||
|
|
||||||
|
let githubPostJsonString = prettyJsonString
|
||||||
|
let githubPostUrl = `${instanceRepo}/new/cleanup/data/patches?filename=gh-${[...Array(4)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')}-${slugify(exportObject.name)}.json&value=`
|
||||||
|
|
||||||
|
if (encodeURIComponent(githubPostJsonString).length > 8192 - githubPostUrl.length) {
|
||||||
|
githubPostJsonString = miniJsonString
|
||||||
|
}
|
||||||
|
|
||||||
|
githubPostUrl += encodeURIComponent(githubPostJsonString)
|
||||||
|
if (githubPostUrl.length > 8192) {
|
||||||
|
// githubPostButton.classList.add("disabled")
|
||||||
|
// githubPostButton.ariaDisabled = true
|
||||||
|
githubPostButton.dataset.bsToggle = "tooltip"
|
||||||
|
githubPostButton.dataset.bsTitle = "This may not work due to the length of the entry. If needed, please copy manually."
|
||||||
|
if (!githubPostTooltip) githubPostTooltip = new bootstrap.Tooltip(githubPostButton)
|
||||||
|
} else {
|
||||||
|
// githubPostButton.classList.remove("disabled")
|
||||||
|
// githubPostButton.ariaDisabled = false
|
||||||
|
githubPostButton.dataset.bsTitle = ""
|
||||||
|
}
|
||||||
|
githubPostButton.href = githubPostUrl
|
||||||
|
|
||||||
|
console.log(githubPostUrl)
|
||||||
|
|
||||||
exportModal.show()
|
exportModal.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -347,13 +347,17 @@ <h5 class="modal-title" id="exportModalLabel">Export Entry</h5>
|
||||||
<p>
|
<p>
|
||||||
If you want to use Reddit, use the <span class="badge bg-primary">Post Direct to Reddit</span> button or manually copy the text below and submit it as a new text post to <a href="https://www.reddit.com/r/placeAtlas2/" target="_blank" rel="noopener noreferrer">r/placeAtlas2</a> on Reddit.
|
If you want to use Reddit, use the <span class="badge bg-primary">Post Direct to Reddit</span> button or manually copy the text below and submit it as a new text post to <a href="https://www.reddit.com/r/placeAtlas2/" target="_blank" rel="noopener noreferrer">r/placeAtlas2</a> on Reddit.
|
||||||
Don't forget to flair it with the <span class="badge rounded-pill bg-primary"><i class="bi bi-tag" aria-hidden="true"></i> <span id="redditFlair">New Entry</span></span> flair.</p>
|
Don't forget to flair it with the <span class="badge rounded-pill bg-primary"><i class="bi bi-tag" aria-hidden="true"></i> <span id="redditFlair">New Entry</span></span> flair.</p>
|
||||||
<p>If you want to use GitHub, read <a href="https://github.com/placeAtlas/atlas/blob/master/CONTRIBUTING.md#through-github" target="_blank" rel="noopener noreferrer">the contributing guide</a> to submit a patch.</p>
|
<p>
|
||||||
|
If you want to use GitHub, use the <span class="badge bg-primary">Submit Direct to GitHub</span> button, or read <a href="https://github.com/placeAtlas/atlas/blob/master/CONTRIBUTING.md#through-github" target="_blank" rel="noopener noreferrer">the contributing guide</a> to submit a patch.
|
||||||
|
</p>
|
||||||
<p>We will then check it and add it to the Atlas.</p>
|
<p>We will then check it and add it to the Atlas.</p>
|
||||||
<textarea class="form-control flex-grow-1" cols="40" rows="20" id="exportString" title="Raw JSON string" readonly></textarea>
|
<textarea class="form-control flex-grow-1" cols="40" rows="20" id="exportString" title="Raw JSON string" readonly></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Done</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Done</button>
|
||||||
<a id="exportDirectPost" class="btn btn-primary" href="#" target="_blank" rel="noopener noreferrer">Post Direct to Reddit</a>
|
<button id="exportCopy" type="button" class="btn btn-secondary">Copy</button>
|
||||||
|
<a id="exportGithubPost" class="btn btn-primary" href="#" target="_blank" rel="noopener noreferrer">Submit Direct on GitHub</a>
|
||||||
|
<a id="exportRedditPost" class="btn btn-primary" href="#" target="_blank" rel="noopener noreferrer">Post Direct on Reddit</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue