Skip to content

Commit

Permalink
refactor: use encodeURIComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
rxb3rth committed Aug 9, 2021
1 parent ffd3515 commit ede5f3d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ <h3 class="animated animated-text">
<button class="btn mr-lg-2 custom-btn"
onclick="tweet()"><span class="iconify" data-icon="uil-twitter-alt"
data-inline="false"></span>&nbsp; Tweet </button>
<button class="btn mr-lg-" class="btn custom-btn custom-btn-bg" onclick="getRandom()">New quote</button>
<button class="btn custom-btn custom-btn-bg" class="btn custom-btn custom-btn-bg" onclick="getRandom()">New quote</button>
</div>
</div>
</div>
Expand Down
12 changes: 5 additions & 7 deletions src/public/js/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* share on twitter */
function tweet() {
const quote = document.getElementById("quote").innerHTML;
const author = document.getElementById("author").innerHTML;
const info = document.getElementById("info").innerHTML;
const fullText = `${quote} - ${author} (${info})`;
window.open(
`https://twitter.com/intent/tweet?text=${quote} - ${author} (${info})&hashtags=BTSQUOTESAPI`
`https://twitter.com/intent/tweet?text=${encodeURIComponent(
fullText
)}&hashtags=BTSQUOTESAPI`
);
}

Expand All @@ -15,13 +19,7 @@ function getRandom() {
document.getElementById("quote").innerHTML = data.quote;
document.getElementById("author").innerHTML = data.member;
console.log(data.quote + " - " + data.member); //for debugging

getInfo(data.quote);

//share on twitter
document.getElementById("shareOnTW").href =
"http://twitter.com/intent/tweet/?text=" +
encodeURIComponent(data.quote + " - " + data.member);
})
.catch((err) => console.log(err));
}
Expand Down

0 comments on commit ede5f3d

Please sign in to comment.