Add Elk support
This commit is contained in:
parent
4b1628fd0b
commit
7ee4429230
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
23
js/share.js
23
js/share.js
|
@ -1,3 +1,16 @@
|
||||||
|
// Function to generate URL
|
||||||
|
function getFinalURL(domain, text, link) {
|
||||||
|
var url = ''
|
||||||
|
if (domain === 'elk.zone') {
|
||||||
|
// Elk web app
|
||||||
|
url = 'https://elk.zone/intent/post?text=' + encodeURIComponent(text + '<br /><br />' + link)
|
||||||
|
} else {
|
||||||
|
// Standard Mastodon URL intent
|
||||||
|
url = 'https://' + domain + '/share?text=' + encodeURIComponent(text + '\n\n' + link)
|
||||||
|
}
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
// Function to initialize UI and redirects
|
// Function to initialize UI and redirects
|
||||||
async function init() {
|
async function init() {
|
||||||
// Generate links to options page
|
// Generate links to options page
|
||||||
|
@ -20,11 +33,11 @@ async function init() {
|
||||||
// If there's only one server, or if the server was picked from the context menu, redirect to that one
|
// If there's only one server, or if the server was picked from the context menu, redirect to that one
|
||||||
if (inputParams.get('server') != 'generic') {
|
if (inputParams.get('server') != 'generic') {
|
||||||
document.querySelector('#server-loading').classList.remove('d-none')
|
document.querySelector('#server-loading').classList.remove('d-none')
|
||||||
window.location = 'https://' + inputParams.get('server') + '/share?text=' + encodeURIComponent(shareText + '\n\n' + shareLink)
|
window.location = getFinalURL(inputParams.get('server'), shareText, shareLink)
|
||||||
return false
|
return false
|
||||||
} else if (data.serverList.length === 1) {
|
} else if (data.serverList.length === 1) {
|
||||||
document.querySelector('#server-loading').classList.remove('d-none')
|
document.querySelector('#server-loading').classList.remove('d-none')
|
||||||
window.location = 'https://' + data.serverList[0] + '/share?text=' + encodeURIComponent(shareText + '\n\n' + shareLink)
|
window.location = getFinalURL(data.serverList[0], shareText, shareLink)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
console.log(inputParams.get('server'))
|
console.log(inputParams.get('server'))
|
||||||
|
@ -36,11 +49,15 @@ async function init() {
|
||||||
var linkEl = document.createElement('a')
|
var linkEl = document.createElement('a')
|
||||||
linkEl.classList.add('list-group-item', 'list-group-item', 'list-group-item-action', 'fw-bold')
|
linkEl.classList.add('list-group-item', 'list-group-item', 'list-group-item-action', 'fw-bold')
|
||||||
linkEl.innerText = serverUrl
|
linkEl.innerText = serverUrl
|
||||||
linkEl.href = 'https://' + serverUrl + '/share?text=' + encodeURIComponent(shareText + '\n\n' + shareLink)
|
linkEl.href = getFinalURL(serverUrl, shareText, shareLink)
|
||||||
linkEl.rel = 'preconnect'
|
linkEl.rel = 'preconnect'
|
||||||
// Add server icon to list
|
// Add server icon to list
|
||||||
var serverImg = document.createElement('img')
|
var serverImg = document.createElement('img')
|
||||||
|
if (serverUrl === 'elk.zone') {
|
||||||
|
serverImg.setAttribute('src', chrome.runtime.getURL('img/elk.png'))
|
||||||
|
} else {
|
||||||
serverImg.setAttribute('src', 'https://' + serverUrl + '/favicon.ico')
|
serverImg.setAttribute('src', 'https://' + serverUrl + '/favicon.ico')
|
||||||
|
}
|
||||||
serverImg.setAttribute('alt', serverUrl + ' icon')
|
serverImg.setAttribute('alt', serverUrl + ' icon')
|
||||||
serverImg.ariaHidden = 'true'
|
serverImg.ariaHidden = 'true'
|
||||||
serverImg.onerror = function() {
|
serverImg.onerror = function() {
|
||||||
|
|
Loading…
Reference in New Issue