From 8160cf5eb58b85a3de10d623e25cb841384279ac Mon Sep 17 00:00:00 2001 From: Misode Date: Wed, 19 Jun 2019 18:41:56 +0200 Subject: [PATCH] Implement URL sharing --- index.html | 4 +++- model.js | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index f409182d..7a621773 100644 --- a/index.html +++ b/index.html @@ -37,7 +37,7 @@
-
+
diff --git a/model.js b/model.js index 9fd2afc1..3513df8b 100644 --- a/model.js +++ b/model.js @@ -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 {