Implement URL sharing

This commit is contained in:
Misode
2019-06-19 18:41:56 +02:00
parent 1e9b9a223a
commit 8160cf5eb5
2 changed files with 22 additions and 2 deletions
+3 -1
View File
@@ -37,7 +37,7 @@
</div>
</div>
<div class="col-12 col-lg-5">
<div class="mb-3 float-lg-right">
<div class="mb-3 float-lg-right menu-right">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Indentation</span>
@@ -47,9 +47,11 @@
<option value="4">4 Spaces</option>
<option value="tab">Tabs</option>
</select>
<button id="linkSource" type="button" class="btn btn-secondary ml-3" onclick="linkSource(this)">Link</button>
<button type="button" class="btn btn-secondary ml-3" onclick="copySource(this)">Copy</button>
</div>
</div>
<textarea id="copyTextarea" rows="1" class="form-control mb-3 d-none"></textarea>
<textarea id="source" class="form-control code" onchange="updateSouce()" rows="20" spellcheck="false"></textarea>
</div>
</div>
+19 -1
View File
@@ -3,9 +3,10 @@ $("#source").val('');
$('#luckBased').prop('checked', false);
$('#tableType').val("minecraft:generic");
$('#indentationSelect').val("2");
let indentation = 2;
let luck_based = false;
let nodes = '.loot-table, .pool, .entry, .child, .term, .terms, .function, .condition, .modifier, .operation';
const nodes = '.loot-table, .pool, .entry, .child, .term, .terms, .function, .condition, .modifier, .operation';
let table = {
type: "minecraft:generic",
pools: []
@@ -13,6 +14,12 @@ let table = {
addPool();
addEntry($('#structure .pool').get());
const params = new URLSearchParams(window.location.search);
if (params.has('q')) {
$('#source').val(params.get('q'));
updateSouce();
}
function updateTableType() {
table.type = $('#tableType').val();
invalidated();
@@ -23,6 +30,17 @@ function updateLuckBased() {
invalidated();
}
function linkSource() {
let link = window.location.origin + window.location.pathname + '?q=' + JSON.stringify(table);
console.log(link);
$('#copyTextarea').removeClass('d-none').val(link);
$('#copyTextarea').get()[0].select();
document.execCommand('copy');
setTimeout(() => {
$('#copyTextarea').addClass('d-none');
}, 2000);
}
function updateSouce() {
$('#source').removeClass('invalid');
try {