Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Show a top-right YouTube tools overlay with « » speed controls and the current

## [Force Mobile View User Script](https://github.com/ChrisTorng/TampermonkeyScripts/raw/main/src/ForceMobileView.user.js)

Keep pages within the viewport width, trim excessive horizontal spacing on all enabled pages, wrap long content, and expose a draggable top-right ↔ toggle button with auto-enable for matched URLs or tiny fonts.
Keep pages within the viewport width, trim excessive horizontal spacing on all enabled pages, wrap long content, and expose a draggable top-right ↔ toggle button with auto-enable for matched URLs.

## [Better Mobile View User Script](https://github.com/ChrisTorng/TampermonkeyScripts/raw/main/src/BetterMobileView.user.js)

Expand Down
2 changes: 1 addition & 1 deletion TestCases.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Section note: automated tests inject the script and mock `GM_getValue`, `GM_setV
Section note: automated tests inject the script and mock `GM_info`.
- https://news.ycombinator.com/item?id=46255285 [CONTENT_CLASS: VALID_NON_ARTICLE_OR_LISTING] [TEST_STATUS: AUTOMATED]
- https://archive.is/75aY9 [CONTENT_CLASS: VALID_ARTICLE_CONTENT] [TEST_STATUS: AUTOMATED]
- https://lcamtuf.coredump.cx/prep/index-old.shtml [CONTENT_CLASS: VALID_ARTICLE_CONTENT] [TEST_STATUS: AUTOMATED] (tiny-font auto-enable behavior)
- https://lcamtuf.coredump.cx/prep/index-old.shtml [CONTENT_CLASS: VALID_ARTICLE_CONTENT] [TEST_STATUS: AUTOMATED] (non-matched URL remains off by default even with tiny fonts)
- https://daringfireball.net/2026/03/your_frustration_is_the_product [CONTENT_CLASS: VALID_ARTICLE_CONTENT] [TEST_STATUS: LIMITED] (mobile spacing logic is AUTOMATED via synthetic DOM harness, including minimal side-whitespace enforcement; full live-page capture coverage is still limited)
- https://steveblank.com/2026/04/09/nowhere-is-safe/ [CONTENT_CLASS: VALID_ARTICLE_CONTENT] [TEST_STATUS: AUTOMATED] (line-height overlap regression is simulated with local DOM harness against captured page content)

Expand Down
10 changes: 5 additions & 5 deletions scripts/test-force-mobile-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('ForceMobileView on captured pages', () => {
});


test('tiny-font pages auto-enable mobile view even when URL is not explicitly matched', () => {
test('non-matched URLs no longer auto-enable mobile view even on tiny-font pages', () => {
const { harness } = executeForceMobileView('https://lcamtuf.coredump.cx/prep/index-old.shtml', {
fixtureHtml: lcamtufFixtureHtml,
computedFontSize(element) {
Expand All @@ -122,9 +122,9 @@ describe('ForceMobileView on captured pages', () => {
const style = harness.document.getElementById('tm-force-width-style');
const button = harness.document.body.children.find((child) => child.tagName === 'BUTTON' && child.textContent === '↔');

assert(style, 'Expected tiny-font detection to auto-enable style injection.');
assert.equal(style, null, 'Expected style injection to remain disabled for non-matched URLs.');
assert(button, 'Expected mobile view toggle button to be created.');
assert.equal(button.getAttribute('aria-pressed'), 'true');
assert.equal(button.getAttribute('aria-pressed'), 'false');
});

test('toggle button disables and re-enables styles and minimum font size overrides', () => {
Expand All @@ -144,7 +144,7 @@ describe('ForceMobileView on captured pages', () => {
});

test('excessive horizontal spacing is trimmed on enable and restored on disable', () => {
const { harness } = executeForceMobileView('https://daringfireball.net/2026/03/your_frustration_is_the_product', {
const { harness } = executeForceMobileView('https://archive.is/75aY9', {
computedStyle(element) {
return {
fontSize: '16px',
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('ForceMobileView on captured pages', () => {
});

test('legacy font-only boost overlaps text lines, while current behavior raises parent line-height', () => {
const { harness } = executeForceMobileView('https://steveblank.com/2026/04/09/nowhere-is-safe/', {
const { harness } = executeForceMobileView('https://news.ycombinator.com/item?id=46255285', {
fixtureHtml: steveBlankFixtureHtml,
computedStyle(element) {
const inlineFont = element.style.getPropertyValue('font-size');
Expand Down
35 changes: 2 additions & 33 deletions src/ForceMobileView.user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ==UserScript==
// @name Force Mobile View
// @namespace http://tampermonkey.net/
// @version 2026-04-21_1.7.4
// @description Keep pages within the viewport width, trim excessive horizontal spacing on all enabled pages, wrap long content, and expose a draggable top-right ↔ toggle button with auto-enable for matched URLs or tiny fonts.
// @version 2026-05-20_1.7.5
// @description Keep pages within the viewport width, trim excessive horizontal spacing on all enabled pages, wrap long content, and expose a draggable top-right ↔ toggle button with auto-enable for matched URLs.
// @author ChrisTorng
// @homepage https://github.com/ChrisTorng/TampermonkeyScripts/
// @downloadURL https://github.com/ChrisTorng/TampermonkeyScripts/raw/main/src/ForceMobileView.user.js
Expand Down Expand Up @@ -421,31 +421,6 @@
return matches.some((matchPattern) => matchPatternToRegExp(matchPattern).test(currentUrl));
}

function shouldAutoEnableForTinyFonts() {
if (!document.body || !shouldEnforceMinFontSize()) {
return false;
}
const minFontSizePx = Math.max(DEFAULT_MIN_FONT_SIZE_PX, calculateMinimumFontSizePx());
const bodyFontSize = Number.parseFloat(window.getComputedStyle(document.body).fontSize);
if (Number.isFinite(bodyFontSize) && bodyFontSize < minFontSizePx) {
return true;
}

const candidates = document.body.querySelectorAll('p, li, td, th, span, div, a, article, section');
const maxChecks = 120;
for (let i = 0; i < candidates.length && i < maxChecks; i += 1) {
const candidate = candidates[i];
if (!candidate.textContent || !candidate.textContent.trim()) {
continue;
}
const computedFontSize = Number.parseFloat(window.getComputedStyle(candidate).fontSize);
if (Number.isFinite(computedFontSize) && computedFontSize < minFontSizePx) {
return true;
}
}
return false;
}

function applyMinimumFontSizeIfNeeded() {
refreshMinimumFontSize();
}
Expand Down Expand Up @@ -715,12 +690,6 @@

if (shouldAutoEnableForUrl()) {
enableForceWidth();
} else {
onDocumentReady(() => {
if (!isEnabled && shouldAutoEnableForTinyFonts()) {
enableForceWidth();
}
});
}

window.addEventListener('resize', scheduleMinimumFontRefresh);
Expand Down
Loading