Deguang / link-and-title-copy-pro

Link&TitleCopyPro is a browser extension that allows you to copy both the title and URL link of a browser tab at the same time. 是一个可以同时复制浏览器标签页的标题和URL链接的浏览器扩展
MIT License
1 stars 1 forks source link

Feature request: Add option to copy URL without query parameters #1

Open lainbo opened 1 month ago

lainbo commented 1 month ago

Hey there! I love this browser extension for quick link sharing. I have a feature request that I think could make it even more powerful and flexible.

Current behavior

The extension copies a string in the format:

${document.title}
${location.href}

Requested feature

We'd like to enhance the extension with two main improvements:

  1. Customizable URL copying options: It would be great to have customizable options for what parts of the URL and page information to include when copying. Users could choose which elements to include in their copied string, such as:

    • Page Title
    • Protocol (http/https)
    • Domain
    • Path
    • Query Parameters
    • Hash Fragment

    Users should be able to set the order of these elements and choose a separator (newline, space, etc.).

  2. Keyboard shortcut support: To make this customizable copying feature quickly accessible, we should implement keyboard shortcut support. Users should be able to:

    • Assign a custom keyboard shortcut for this new copying function
    • Potentially set different shortcuts for different custom copying configurations (e.g., one shortcut for copying with query parameters, another for copying without)

This combination of customizable copying and keyboard shortcuts would provide a powerful, flexible, and efficient way for users to share links exactly as they need them.

Why?

Different sharing contexts require different information. Sometimes we want to exclude tracking parameters(e.g. https://www.bilibili.com/video/BV1uT4y1P7CX/?spm_id_from=333.788.recommend_more_video.-1&vd_source=23484e816035c7f74633), This flexibility would make the extension useful in more scenarios.

Proposed user interface

A settings page where users can choose which elements to include:

Users could also set the order of these elements and choose a separator (newline, space, etc.).

Technical implementation

Here's a possible approach to implement this feature:

  1. Store user preferences in extension storage.
  2. Use the URL API for robust URL parsing:
function generateCustomString(url, title, preferences) {
  const urlObj = new URL(url);
  const parts = [];

  if (preferences.includeTitle) parts.push(title);
  if (preferences.includeProtocol) parts.push(urlObj.protocol.slice(0, -1));
  if (preferences.includeDomain) parts.push(urlObj.hostname);
  if (preferences.includePath) parts.push(urlObj.pathname);
  if (preferences.includeQueryParams) parts.push(urlObj.search);
  if (preferences.includeHash) parts.push(urlObj.hash);

  return parts.join(preferences.separator || '\n');
}

// Usage:
const customString = generateCustomString(
  window.location.href,
  document.title,
  userPreferences
);

I'm not sure if there's a better way to implement this, but I thought using this might work. If anyone has a more robust solution, I'm all ears!

Examples

Depending on user settings, the extension could generate:

  1. Full URL: https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=43s
  2. Clean URL: https://www.bilibili.com/video/BV1uT4y1P7CX
  3. Title + Domain: Never Gonna Give You Up - YouTube
  4. etc.

What do you think? This would give users the power to create exactly the kind of shareable links they need for different situations.

Deguang commented 1 month ago

Your suggestion is excellent! I was actually considering adding a similar feature just yesterday, using configurable string templates to control different output results. Your idea of implementing different configurations through various shortcuts is fantastic! I will prioritize this feature update in our next version release. Please stay tuned!