Make Seance bookmarklet URLs relative

So it'll send people to the current Seance installation instead
of blindly directing them to localhost
This commit is contained in:
Hippo 2020-05-10 22:44:47 +05:30
parent 54ae9f57a6
commit 7ad8f7b3f8
3 changed files with 11 additions and 4 deletions

View File

@ -38,7 +38,9 @@ app.use(renderer)
// Views
app.get('/', (req, res) => {
res.render('index')
res.render('index', {
baseUrl: req.protocol + '://' + req.headers.host,
})
})
app.get('/fetch/', (req, res) => {

View File

@ -1,6 +1,6 @@
(() => {
const baseUrl = 'http://localhost:4000'
const baseUrl = document.querySelector('[data-seance-url]').dataset.seanceUrl || 'http://localhost:4000'
function resetTitle() {
document.title = document.title.replace('[Loading...] ', '')

View File

@ -29,7 +29,7 @@
<h1 class="title">{{ title }}</h1>
<form action="/fetch/medium/" method="post">
<input type="search" class="input is-medium is-rounded is-focused" placeholder="Enter a Medium link..."/>
<p>or, use the bookmarklet <a class="button is-primary is-small" href="javascript:(()=>{document.title='[Loading...] '+document.title;s=document.createElement('script');s.src='http://localhost:4000/bookmarklet.js';document.body.appendChild(s)})()">Add to Seance</a></p>
<p>or, use the bookmarklet <a class="button is-primary is-small" :href="bookmarklet">Add to Seance</a></p>
</form>
</div>
@ -43,7 +43,12 @@
return {
title: 'Seance',
user: null,
host: 'http://localhost:4000',
baseUrl: 'http://localhost:4000',
}
},
computed: {
bookmarklet () {
return `javascript:(()=>{document.title='[Loading...] '+document.title;s=document.createElement('script');s.src='${this.baseUrl}/bookmarklet.js';s.dataset.seanceUrl='${this.baseUrl}';document.body.appendChild(s)})()`
}
}
}