Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Combining Whitelist & Same-Origin #30

Closed
benjaminrancourt opened this issue Apr 6, 2023 · 3 comments
Closed

Combining Whitelist & Same-Origin #30

benjaminrancourt opened this issue Apr 6, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@benjaminrancourt
Copy link

Hi!

Thank you very much for your script, I like the way you designed your library. It's really simple to understand, and it seems to do the job well, at least from my first tests! 🤗

I just want you to know another use case that I think might be useful: combining data-tachyon-same-origin and data-tachyon-whitelist. This would allow the user to preload their website links and other links that a developer has marked in the allow list. For example, to preload links from:

Rest assured that I do not want you to implement this use case if you think it's not worth it for a lot of users. 😅 I had already planned to use a slightly modified version of your script for my peculiar use case. 😉

Thanks again!

~ Benjamin

  if ((node.tagName === 'A' && node.href) && (('tachyon' in node.dataset === whitelistEnabled) || (!sameOriginOnly || node.origin === window.location.origin))) {
    ['mouseover', 'mouseout', 'touchstart', 'touchend'].forEach((eventName) => node.addEventListener(eventName, toggleLinkTag, { passive: true }));
  }
@cowtoolz
Copy link
Owner

cowtoolz commented Apr 6, 2023

This is a good idea and seems to be somewhat of an oversight on my part. I'll look into it more sometime this week; thanks for pointing this out and glad you're getting some use out of the project!

@cowtoolz cowtoolz changed the title Thanks! Combining Whitelist & Same-Origin Apr 7, 2023
@cowtoolz
Copy link
Owner

cowtoolz commented Apr 7, 2023

I think the way I'm likely to implement this is by making data-tachyon-same-origin a subset of the whitelist, i.e. automatically enabling the whitelist with data-tachyon-same-origin. I'm not sure if this is exactly what you're describing, but this seems to make the most sense to me:

  • Adding data-tachyon-same-origin to the body tag will behave the same way as data-tachyon-whitelist BUT will automatically add same-origin links to the whitelist.
  • While data-tachyon-same-origin is on the body tag, adding data-tachyon to different-origin anchor tags will add them to the whitelist, just like with data-tachyon-whitelist

Your thoughts? I don't actually use data-tachyon-same-origin in production, so some input would be great.

@cowtoolz cowtoolz self-assigned this Apr 7, 2023
@cowtoolz cowtoolz added the enhancement New feature or request label Apr 7, 2023
@cowtoolz
Copy link
Owner

Please see the documentation for how to utilize the changes. Thanks for bringing this to my attention!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants