Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy page meta info to clipboard funtion #819

Open
scruel opened this issue Nov 15, 2021 · 3 comments
Open

Add copy page meta info to clipboard funtion #819

scruel opened this issue Nov 15, 2021 · 3 comments

Comments

@scruel
Copy link
Contributor

scruel commented Nov 15, 2021

Describe the solution you'd like
I want to have a function that can copy the page meta info to clipboard while saving(or after or provide a button) the pages(copy the filename should be fine, but provide another template for copy function like save filename template dos would be better!)
When I write notes, I always save the content of the pages which I visited, the workflow for now is that save page with SingleFile, copy the filename after the window popped up, paste adjust the copied name into my notes, it is very inconvenience for me to adjust the name of page in notes, so I wonder if you can add this function.
THX!

@gildas-lormeau
Copy link
Owner

I understand the need and it seems quite legitimate, I agree that this option would be useful. The idea would indeed be to rely on a template that would define what should be copied. So, it would keep some flexibility.

@scruel
Copy link
Contributor Author

scruel commented Nov 16, 2021

I understand the need and it seems quite legitimate, I agree that this option would be useful. The idea would indeed be to rely on a template that would define what should be copied. So, it would keep some flexibility.

For now, I use CopyTabTitleUrl plugin to get the page info, and wrote a script to convert the info I needed.

filename = "%s - %s.html" % (page_title, sha1.hexdigest())
pyperclip.copy(filename )
markdown = "[%s](file://%s\\%s)" % (page_title, save_path, filename)
pyperclip.copy(markdown)

@scruel
Copy link
Contributor Author

scruel commented Feb 28, 2023

Might the following code will be helpful to implement this feature:

function copyToClipboard(command, tabs) {
  const text = createFormatText(command, tabs);
  
  if (isFirefox() 
   && extension(command, 'others_clipboard_api', true) 
   && !extension(command, 'others_html', true)) {
    // クリップボードコピー(ClipboardAPI)
    navigator.clipboard.writeText(text).then(function() {
      //console.log('successfully');
    }, function() {
      //console.log('failed');
    });
  } else {
    // クリップボードコピー(execCommand)
    document.addEventListener('copy', function oncopy(event) {
      document.removeEventListener('copy', oncopy, true);
      event.stopImmediatePropagation();
      event.preventDefault();
      
      if (extension(command, 'others_html', true) && command.id >= 3) {
        event.clipboardData.setData('text/html', text);
      }
      event.clipboardData.setData('text/plain', text);
    }, true);
    document.execCommand('copy');
  }
};

Source:
https://github.com/k08045kk/CopyTabTitleUrl/blob/master/src/js/common.js#L350

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants