Skip to content

Commit

Permalink
give feedback to user about wrong links (closes #1)
Browse files Browse the repository at this point in the history
- Added pattern to input field
- added error-banner in case browser messes up pattern matching.
  • Loading branch information
RealDekkia committed Apr 14, 2024
1 parent b41d1bf commit f0825a0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
11 changes: 11 additions & 0 deletions css/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
--accent: #2F0C7A;
--marked: #2F0C7A;
--markedfg: var(--accent-text);
--bannerfg: #ffc400;
--bannerbg: #212121;
--headerbg: rgba(255, 255, 255, .65);
--headerblend: lighten;
}
Expand All @@ -17,4 +19,13 @@

mark {
color: var(--markedfg);
}

banner {
padding: 0.5rem;
margin-bottom: 0.5rem;
border-radius: var(--standard-border-radius);
display: none;
background-color: var(--bannerfg);
color: var(--bannerbg);
}
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ <h1 id="topBarText">Unroll Ninja</h1>
</div>

<form id="urlInputForm" action="javascript:main.unrollButton();">
<input type="url" id="posturl" placeholder="Link to Mastodon Thread" />
<input type="url" id="posturl" placeholder="Link to Mastodon Thread" pattern="^http(s)*:\/\/.*@.*\/\d*$"
title="Required Format: https://mastodon.example.org/@exampleUser/123" />
<button id="startUnrollButton">Unroll</button>
<banner id="underInputBanner"></banner>
</form>

<div id="explainerText">
Expand Down
14 changes: 12 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
var main = {
init: function () {

//Hide banner in case it's been displayed previously
document.getElementById("posturl").onkeydown = function () {
document.getElementById("underInputBanner").style.display = "none";
};
},
unrollButton: function () {
var postUrl = document.getElementById("posturl").value;
Expand All @@ -22,6 +25,13 @@ var main = {
document.location = "thread?uri=" + encodeURIComponent(serverDomain) + "&id=" + encodeURIComponent(postID);

} else {
//Normally this should never show up
//Because the browser is supposed to catch this.
//But let's better be save then sorry.
var banner = document.getElementById("underInputBanner");
banner.innerHTML = "The URL is in the wrong format.";
banner.style.display = "block";
}
}
};
};
main.init();

0 comments on commit f0825a0

Please sign in to comment.