Skip to content

Commit d0cf9cf

Browse files
committed
Add share button
1 parent 9e21b5f commit d0cf9cf

File tree

4 files changed

+44
-23
lines changed

4 files changed

+44
-23
lines changed

1.bootstrap.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@ <h1 class="title">
4545
<textarea class="textarea" name="sql" rows="10" placeholder="Enter Your Sql" id="input"></textarea>
4646
</div>
4747
</div>
48-
<div class="field">
49-
<div class="field-body">
50-
<div class="field">
51-
<div class="control has-text-centered">
52-
<button class="button is-primary" id="convert-button">
53-
Convert
54-
</button>
55-
</div>
56-
</div>
48+
49+
<div class="level-left">
50+
<div class="level-item has-text-centered">
51+
<button class="button is-primary" id="convert-button">
52+
Convert
53+
</button>
54+
</div>
55+
<div class="level-item has-text-centered">
56+
<button class="button" id="share-button">
57+
Share
58+
</button>
5759
</div>
5860
</div>
5961
</div>
@@ -65,11 +67,11 @@ <h1 class="title">
6567
</div>
6668
</div>
6769
</div>
68-
6970
</div>
7071
</div>
7172
</div>
7273
</div>
74+
<input style="display: none;" id="base64sql"></input>
7375
<script src="./bootstrap.js"></script>
7476
</body>
7577
</html>

src/index.html

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@ <h1 class="title">
4545
<textarea class="textarea" name="sql" rows="10" placeholder="Enter Your Sql" id="input"></textarea>
4646
</div>
4747
</div>
48-
<div class="field">
49-
<div class="field-body">
50-
<div class="field">
51-
<div class="control has-text-centered">
52-
<button class="button is-primary" id="convert-button">
53-
Convert
54-
</button>
55-
</div>
56-
</div>
48+
49+
<div class="level-left">
50+
<div class="level-item has-text-centered">
51+
<button class="button is-primary" id="convert-button">
52+
Convert
53+
</button>
54+
</div>
55+
<div class="level-item has-text-centered">
56+
<button class="button" id="share-button">
57+
Share
58+
</button>
5759
</div>
5860
</div>
5961
</div>
@@ -65,11 +67,11 @@ <h1 class="title">
6567
</div>
6668
</div>
6769
</div>
68-
6970
</div>
7071
</div>
7172
</div>
7273
</div>
74+
<input style="display: none;" id="base64sql"></input>
7375
<script src="./bootstrap.js"></script>
7476
</body>
7577
</html>

src/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Sentry.init({
1414
allowUrls: ['https://sql2builder.github.io/']
1515
});
1616

17-
document.getElementById('convert-button').addEventListener('click', function () {
17+
let converter = function () {
1818
let input = document.getElementById("input").value;
1919

2020
if (input.trim() === '') {
@@ -44,7 +44,24 @@ document.getElementById('convert-button').addEventListener('click', function ()
4444
} catch (e) {
4545
console.log(input);
4646
output_text_area.value = e + ', I will fix this issue as soon as possible';
47-
47+
4848
throw e;
4949
}
50+
}
51+
52+
let url_search_params = new URLSearchParams(window.location.search);
53+
54+
if(url_search_params.has('base64sql')) {
55+
document.getElementById('input').value = atob(url_search_params.get('base64sql'));
56+
converter();
57+
}
58+
59+
document.getElementById('convert-button').addEventListener('click', converter);
60+
document.getElementById('share-button').addEventListener('click', function () {
61+
let share_link = window.location.origin + '?base64sql=' + btoa(document.getElementById('input').value);
62+
navigator.clipboard.writeText(share_link).then(function() {
63+
alert('Share link copied.');
64+
}, function() {
65+
alert('Copy failed.');
66+
});
5067
});

0 commit comments

Comments
 (0)