Git Product home page Git Product logo

jaem1n207 / synchronize-tab-scrolling Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1.62 MB

A browser extension that lets you synchronize the scrolling position of multiple tabs

Home Page: https://chromewebstore.google.com/detail/synchronize-tab-scrolling/phceoocamipnafpgnchbfhkdlbleeafc

License: MIT License

JavaScript 6.36% TypeScript 52.56% HTML 0.40% CSS 1.92% Svelte 38.76%
extension svelte webstore scroll-sync

synchronize-tab-scrolling's Introduction

Chrome Web Store

A browser extension that lets you synchronize the scrolling position of multiple tabs

Chrome Web Store Microsoft Edge Add-ons Firefox Add-ons Brave Extensions

GitHub Release GitHub pull requests GitHub issues GitHub License

Synchronize Tab Scrolling

ENGLISH | 한국어

Synchronize Tab Scrolling is a tool that automatically synchronizes scroll positions between two tabs, enabling users to conveniently compare and read the original and translated documents without the hassle of manual scrolling.

Contents

Intro

This extension provides convenience for users reading original and translated documents across multiple tabs. When the user scrolls in one tab, the linked tab automatically scrolls to the same position, allowing for easy comparison and reading of the original and translated texts. This feature is particularly useful when translating documents or referencing multilingual documents simultaneously.

Usage

To get started, simply follow these steps:

  1. Open multiple tabs in different windows.
  2. Click on the extension icon.
  3. Select two or more tabs you want to synchronize scrolling.

Then, simply click the 'Start sync' button and scroll through the tabs. To stop synchronizing tabs, just click the extension icon once more and select the 'Stop sync' button or close the synchronized tabs.

Youtube Video Link

Watch the video

Privacy Policy

The Synchronize Tab Scrolling extension has no ads, no analytics, no trackers, and no use of cookies. It is also an open-source project.

Note

Please note that tab scrolling cannot be synchronized for tabs with certain URLs. Tabs starting with the following URLs are excluded:

This is to prevent the extension from interacting with unintended pages, such as certain services.

SUPPORT

I use it myself to improve usability and catch bugs, but if you encounter any issues, please report it below:

License

This project is licensed under the MIT License. For more details, please refer to the LICENSE file.

synchronize-tab-scrolling's People

Contributors

dependabot[bot] avatar jaem1n207 avatar semantic-release-bot avatar

Stargazers

 avatar

Watchers

 avatar

synchronize-tab-scrolling's Issues

[Feature] 동일한 탭이 존재하면 자동으로 스크롤 동기화 시작

기능 설명

동일한 URL 탭이 존재한다면 자동으로 스크롤을 동기화하는 옵션을 추가하는 것은 어떨까요?
보통 스크롤 동기화를 원하는 경우는 동일한 내용을 다른 형태로 띄워두고 있을 때입니다. 예로 다음과 같은 상황이 있습니다:

  • 위지윅 에디터에서 마크다운 입력창과 프리뷰창의 스크롤 동기화
  • 번역글과 원글의 스크롤 동기화

보통 이 확장 프로그램을 사용하는 이유는 두 번째 이유일 것입니다. 이때, 동일한 URL 탭을 생성해 하나는 번역기능을 활용해 자신의 언어로 보고 원글을 비교하며 읽는 경우도 있습니다. 이 경우, 스크롤 동기화는 반드시 사용하게 됩니다. 그러므로 동일한 URL 탭이 존재한다면 해당 탭의 스크롤 동기화를 자동으로 하는 기능을 추가하는 것도 좋을 것 같습니다.

이를 원하지 않는 사용자가 있을 수 있으니 기능 on/off 옵션을 통해 기능을 끌 수 있도록 해두는 작업도 필요할 것입니다. 더 나아간다면 동기화를 원하지 않는 URL을 사용자가 직접 리스트에 추가할 수 있도록 하는 자유도도 부여할 수 있을 것입니다.

[Bug] 다양한 높이를 가진 페이지 간의 스크롤 동기화 문제 해결

문제 인식

다양한 높이를 가진 웹 페이지 간의 스크롤 위치를 백분율로 동기화하는 기능에 문제가 있다는 것을 사용자의 리뷰에서 발견했습니다:

works great – if i could request one feature it would be the ability to sync by scroll percentage vs. scroll y-position. this helps a lot when comparing on screens of different pixel densities. (e.g., if we are comparing a page on two screens that renders with heights 500px and 1000px, scrolling to the bottom of the 500px tall tab would scroll to the bottom of the 1000px tab as well.)

사용자는 한 페이지에서 스크롤을 최하단으로 내렸을 때, 다른 페이지에서도 동일하게 최하단으로 스크롤되기를 기대했으나, 실제로는 그렇지 않았다는 내용이었습니다.

애초에 화면 크기나 해상도 차이에 관계없이 두 화면에서 동일한 비율로 스크롤이 동기화될 수 있도록 스크롤 위치를 절대적인 픽셀 값이 아닌, 문서의 전체 높이에 대한 백분율(%)로 동기화하도록 기능을 작성했었습니다.

그래서 처음엔 스크롤 위치를 절대적인 px 값으로도 동기화할 수 있도록 옵션을 추가해달라는 요청으로 이해했습니다. 하지만 사용자가 제시한 예시대로 재현해보기로 했고 여기서 문제를 발견할 수 있었습니다.

문제 분석

사용자가 제시한 문제를 재현하기 위해 두 개의 다른 높이를 가진 웹 페이지를 생성하고, 스크롤 동기화를 테스트할 수 있는 간단한 HTML과 JS 코드를 작성했습니다: https://codepen.io/jaem1n207/pen/bGyNPBE (Codepen 결과 화면의 Before 섹션 참고)

문제의 원인을 분석하기 위해 기존의 스크롤 동기화 로직을 천천히 살펴보았는데요. 기존 로직은 scrollTop 값을 scrollHeight로 나누어 스크롤 위치의 백분율을 계산하고 있었습니다. 그러나 이런 게산 방식은 clientHeight를 고려하지 않아 실제 스크롤 가능한 범위를 정확히 반영하지 못했습니다:

const scrollPosition = window.scrollY || document.documentElement.scrollTop || document.body.scrollTop || 0;
const scrollHeight = document.documentElement.scrollHeight;
const scrollYPercentage = scrollPosition / scrollHeight;

const nextScrollPosition = scrollYPercentage * scrollHeight;
window.scrollTo({ top: nextScrollPosition });
  • scrollPosition: 스크롤바의 현재 위치를 나타냅니다.
  • scrollHeight: 스크롤 가능한 전체 문서의 높이를 나타냅니다.

여기서 scrollPosition의 최대값은 scrollHeight에서 뷰포트(보이는 영역)의 높이를 뺀 값입니다. 이로 인해 백분율 계산이 잘못되어 스크롤 동기화가 정확히 이루어지지 않는 문제가 발생하던 것이었습니다.

예를 들어, scrollHeight가 3500인 문서가 있고 뷰포트의 높이가 1400이라고 가정하면 scrollY의 최대값은 2100입니다.

해결 방안

문제를 해결하기 위해, 스크롤 백분율을 계산할 때 clientHeight를 고려하여 실제 스크롤 가능한 높이를 사용하도록 로직을 수정했습니다:

const scrollPosition = window.scrollY || document.documentElement.scrollTop || document.body.scrollTop || 0;
const scrollHeight = document.documentElement.scrollHeight;
+ const clientHeight = document.documentElement.clientHeight;

- const scrollYPercentage = scrollPosition / scrollHeight;
// 스크롤 가능한 최대 높이에서 뷰포트 높이를 빼고, 현재 스크롤 위치를 나누어 백분율을 계산
+ const scrollYPercentage = scrollHeight === clientHeight ? 0 : scrollPosition / (scrollHeight - clientHeight);

- const nextScrollPosition = scrollYPercentage * scrollHeight;
// 다른 문서의 스크롤 위치를 계산할 때도 동일하게 뷰포트 높이를 고려
+ const nextScrollPosition = scrollYPercentage * (scrollHeight - clientHeight);
// 다른 문서의 스크롤 위치 조정
window.scrollTo({ top: nextScrollPosition });

이제 스크롤 가능한 범위를 기준으로 백분율을 계산하게 됩니다.

결과

scroll-sync-problem

이전 스크롤 로직과 변경 후 스크롤 로직은 코드펜에서 확인할 수 있습니다.

Warning with use client directive with Vite & @tanstack/react-query

I'm seeing a lot of warnings like this:

Screenshot 2023-07-13 at 11 36 25 PM

In a recent development project, I began to encounter an array of warnings while bundling client output with Vite. Intrigued and somewhat concerned, I decided to delve deeper into the matter, to understand the origins and implications of these warnings.

When is this warning displayed:

Occurs when bundling client output with Vite.

Why is this warning displayed:

The crux of the issue was rooted in the fact that my project wasn't making use of Server Components, and therefore had no necessity to "support" the directive causing these warnings. The bundler, in its quest to create a seamless bundle, stumbled upon this directive at the start of a file it intended to include. Unfortunately, it found itself unable to hoist the directive across the entirety of the bundle and thus opted to remove it. This is where the warnings originated from.

The bundler, in its diligence, doesn't prefer to remove components without providing prior notice. As a result, it generates these warnings, to keep the developer informed about any changes it's making.

The cause of the warnings also traced back to my usage of the unbundled .mjs-version of React Query. Interestingly, this version now includes a 'use client' directive at the top of some files. While this initially seemed to be the issue, I realized it was actually a blessing in disguise. The .mjs version of React Query enables the bundler to perform tree shaking, thereby allowing it to discard any parts of React Query that aren't actively in use. This ensures that the final app-bundle is devoid of any unnecessary parts, resulting in a more streamlined and optimized bundle.

How can I solve this problem:

As for mitigating this barrage of warnings, a viable solution I found is to incorporate a Rollup onwarn filter, effectively hiding the warnings. However, it's important to remember that the warnings don't indicate a fault or problem, but are merely informational. You can find further information on this issue in this GitHub comment.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.