google chrome goto special text by url All In One
google chrome goto special text by url All In One
goto text with highlight color by URL
Link to Text Fragment

https://chrome.google.com/webstore/detail/link-to-text-fragment/pbcodcjpfjdpcineamnnmbkkmkdpajjg
bug

demo
https://www.cnblogs.com/xgqfrms/p/15401157.html#:~:text=goto text with highlight color by url
#:~:text=your_page_text

encodeURIComponent
const { generateFragment } = await import('https://unpkg.com/text-fragments-polyfill/dist/fragment-generation-utils.js');
const result = generateFragment(window.getSelection());
if (result.status === 0) {
  let url = `${location.origin}${location.pathname}${location.search}`;
  const fragment = result.fragment;
  const prefix = fragment.prefix ?
    `${encodeURIComponent(fragment.prefix)}-,` :
    '';
  const suffix = fragment.suffix ?
    `,-${encodeURIComponent(fragment.suffix)}` :
    '';
  const textStart = encodeURIComponent(fragment.textStart);
  const textEnd = fragment.textEnd ?
    `,${encodeURIComponent(fragment.textEnd)}` :
    '';
  url += `#:~:text=${prefix}${textStart}${textEnd}${suffix}`;
  // 
  console.log('\n🎉 encoded url =', url);
}
https://unpkg.com/text-fragments-polyfill/dist/fragment-generation-utils.js
refs
https://web.dev/text-fragments/#browser-compatibility
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15401157.html
未经授权禁止转载,违者必究!

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号