Skip to content
Open
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
19 changes: 18 additions & 1 deletion src/BookReader/Toolbar/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,26 @@ export class Toolbar {

const $titleSectionEl = br.refs.$BRtoolbar.find('.BRtoolbarSectionTitle');
if (br.bookUrl && br.options.enableBookTitleLink) {
// Use referrer if available and from same origin, otherwise use bookUrl
// This allows returning to the previous BookServer Explorer App page
let returnUrl = br.bookUrl;
const referrer = document.referrer;

if (referrer) {
Comment on lines +55 to +57
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is trailing whitespace on the blank line after const referrer = document.referrer;, which violates the repo’s no-trailing-spaces ESLint rule and will fail npm run lint. Remove the whitespace (or the blank line).

Copilot uses AI. Check for mistakes.
try {
const referrerUrl = new URL(referrer);
const currentUrl = new URL(window.location.href);
if (referrerUrl.origin === currentUrl.origin) {
returnUrl = referrer;
}
Comment on lines 51 to +63
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new return-link behavior (preferring document.referrer when same-origin) isn’t covered by tests. Since this repo already has Jest tests for Toolbar.js, add unit tests for buildToolbarElement() covering: (1) defaulting to br.bookUrl, (2) same-origin referrer override, (3) cross-origin referrer ignored, and (4) invalid referrer string fallback.

Copilot uses AI. Check for mistakes.
} catch (e) {
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch (e) introduces an unused variable, which violates this repo’s no-unused-vars ESLint rule and will fail npm run lint. Use an empty catch binding (catch { ... }) or otherwise reference the error variable.

Suggested change
} catch (e) {
} catch {

Copilot uses AI. Check for mistakes.
// Fall back to br.bookUrl if URL parsing fails
}
}

$titleSectionEl.append(
Comment on lines +67 to 69
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is trailing whitespace on the blank line just before appending the <a> element, which violates the repo’s no-trailing-spaces ESLint rule and will fail npm run lint. Remove the whitespace (or the blank line).

Copilot uses AI. Check for mistakes.
$('<a>')
.attr({href: br.bookUrl, title: br.bookUrlTitle})
.attr({href: returnUrl, title: br.bookUrlTitle})
.addClass('BRreturn')
.html(br.bookUrlText || br.bookTitle),
);
Expand Down