From 7ad8f7b3f868990554f1f6c3eac1bbd04f2e3bfb Mon Sep 17 00:00:00 2001 From: Hippo Date: Sun, 10 May 2020 22:44:47 +0530 Subject: [PATCH] Make Seance bookmarklet URLs relative So it'll send people to the current Seance installation instead of blindly directing them to localhost --- server.js | 4 +++- static/bookmarklet.js | 2 +- views/index.vue | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index 6a3cc5d..627be7a 100644 --- a/server.js +++ b/server.js @@ -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) => { diff --git a/static/bookmarklet.js b/static/bookmarklet.js index d4084c8..1dc78bf 100644 --- a/static/bookmarklet.js +++ b/static/bookmarklet.js @@ -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...] ', '') diff --git a/views/index.vue b/views/index.vue index 51b75c0..c607922 100644 --- a/views/index.vue +++ b/views/index.vue @@ -29,7 +29,7 @@

{{ title }}

-

or, use the bookmarklet Add to Seance

+

or, use the bookmarklet Add to Seance

@@ -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)})()` } } }