Implemented URL sharing

This commit is contained in:
Luxferre
2023-04-02 23:00:47 +03:00
parent 69d9741037
commit 53f9dc3a46
3 changed files with 24 additions and 0 deletions
+1
View File
@@ -83,6 +83,7 @@ Kopher's controls were inspired by old WAP browsers and partially Opera Mini. On
- Open a bookmark: `# [num]`
- Save to the homepage: `* *`
- Save to a bookmark: `* [num]`
- Share the URL: `* Call`
- Toggle light/dark theme: `4`
- Toggle line wrapping: `6`
- Version and page info: `# #`
+22
View File
@@ -15,6 +15,11 @@ function saveBlob(blob, fname, successCb, errorCb) {
freeSpaceReq.onerror = errorCb
}
function hi2gopher(hiurl) {
var parts = hiurl.split(':')[1].split('|')
return 'gopher://'+parts[2]+':'+parts[3]+'/'+parts[0]+parts[1]
}
function openURL(url, successCb, errorCb) {
if(url.startsWith('about:')) { // handle about: pages first
var pageName = url.split(':')[1], allowedPageNames = ['kopher', 'blank', 'help']
@@ -267,6 +272,23 @@ addEventListener('DOMContentLoaded', function() {
if(currentUrl && confirm('Save current URL as the homepage?'))
setBookmark(0, currentUrl)
break
case '*Call': // share current URL as text in messages/email or via Bluetooth in vCard format
var hgoph = hi2gopher(currentUrl), htype = 'text/vcard',
btext = 'BEGIN:VCARD\r\nVERSION:2.1\r\nN:'+hgoph+'\r\nURL:'+hgoph+'\r\nEND:VCARD',
hblob = new Blob([btext], {type: htype}),
hname = hgoph.replace(/[\/:]+/g, '_') + '.vcf'
hblob.name = hname
new MozActivity({
name: 'share',
data: {
type: 'url',
number: 1,
url: hgoph,
blobs: [hblob],
filenames: [hname]
}
})
break
case '#1': // load bookmark
case '#2':
case '#3':
+1
View File
@@ -12,6 +12,7 @@ Kopher controls
* Open bookmark: # [num]
* Save to homepage: * *
* Save bookmark: * [num]
* Share the URL: * Call
* Toggle theme: 4
* Toggle line wrapping: 6
* Version+page info: # #