Implemented URL sharing
This commit is contained in:
@@ -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: `# #`
|
||||
|
||||
@@ -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':
|
||||
|
||||
@@ -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: # #
|
||||
|
||||
Reference in New Issue
Block a user