mirror of
https://github.com/jvsteiner/send-note.git
synced 2026-07-22 11:20:26 +00:00
Add icons for mobile ease of access
This commit is contained in:
parent
faebb0e152
commit
fc52cdac6e
3 changed files with 46 additions and 2 deletions
36
src/main.ts
36
src/main.ts
|
|
@ -1,4 +1,4 @@
|
|||
import { Plugin, TFile } from 'obsidian'
|
||||
import { Plugin, setIcon, TFile, Workspace } from 'obsidian'
|
||||
import { DEFAULT_SETTINGS, ShareSettings, ShareSettingsTab, YamlField } from './settings'
|
||||
import Note from './note'
|
||||
import API from './api'
|
||||
|
|
@ -56,6 +56,40 @@ export default class SharePlugin extends Plugin {
|
|||
}
|
||||
})
|
||||
|
||||
// Add share icons to properties panel
|
||||
this.registerEvent(this.app.workspace.on('active-leaf-change', () => {
|
||||
console.log('icons')
|
||||
// I tried using onLayoutReady() here rather than a timeout, but it did not work.
|
||||
// It seems that the layout is still updating even after it is "ready".
|
||||
setTimeout(() => {
|
||||
document.querySelectorAll(`div.metadata-property[data-property-key="${this.field(YamlField.link)}"]`)
|
||||
.forEach(propertyEl => {
|
||||
const valueEl = propertyEl.querySelector('div.metadata-property-value')
|
||||
if (valueEl && !valueEl.querySelector('div.share-note-icons')) {
|
||||
const iconsEl = document.createElement('div')
|
||||
iconsEl.classList.add('share-note-icons')
|
||||
// Re-share note icon
|
||||
const shareIcon = iconsEl.createEl('span')
|
||||
shareIcon.title = 'Re-share note'
|
||||
setIcon(shareIcon, 'upload')
|
||||
shareIcon.onclick = () => this.uploadNote()
|
||||
// Copy to clipboard icon
|
||||
const copyIcon = iconsEl.createEl('span')
|
||||
copyIcon.title = 'Copy link to clipboard'
|
||||
setIcon(copyIcon, 'copy')
|
||||
copyIcon.onclick = async () => {
|
||||
const link = propertyEl.querySelector('div.metadata-link-inner.external-link') as HTMLElement
|
||||
if (link) {
|
||||
await navigator.clipboard.writeText(link.innerText)
|
||||
new StatusMessage('📋 Shared link copied to clipboard')
|
||||
}
|
||||
}
|
||||
valueEl.prepend(iconsEl)
|
||||
}
|
||||
})
|
||||
}, 200)
|
||||
}))
|
||||
|
||||
// Add command - Share note
|
||||
this.addCommand({
|
||||
id: 'share-note',
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { CachedMetadata, FileSystemAdapter, moment, requestUrl, TFile, WorkspaceLeaf } from 'obsidian'
|
||||
import { CachedMetadata, FileSystemAdapter, moment, requestUrl, setIcon, TFile, WorkspaceLeaf } from 'obsidian'
|
||||
import { encryptString, sha1 } from './crypto'
|
||||
import SharePlugin from './main'
|
||||
import StatusMessage, { StatusType } from './StatusMessage'
|
||||
|
|
|
|||
10
styles.css
10
styles.css
|
|
@ -12,3 +12,13 @@
|
|||
background: #629762;
|
||||
color: white
|
||||
}
|
||||
|
||||
.share-note-icons {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.share-note-icons > span {
|
||||
display: flex;
|
||||
margin-left: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue