Skip to content

Commit

Permalink
Allow hash and search parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
lukestanley committed Jul 16, 2024
1 parent 84e9552 commit 5c2798e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pdf_deep_link.htm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
const params = new URLSearchParams(window.location.search);
const url = params.get('site');
const proxyUrl = `https://api.allorigins.win/get?url=${encodeURIComponent(url)}`;
const searchString = params.get('search') ? decodeURIComponent(params.get('search')).replace(/\s+/g, ' ').trim() : '';
const searchParam = params.get('search');
const hash = window.location.hash;
const searchString = searchParam ? decodeURIComponent(searchParam) :
hash ? decodeURIComponent(hash.replace('#:~:text=', '')) : '';
const searchRegex = new RegExp(searchString.replace(/\s+/g, '\\s*'), 'i');
const loadingIndicator = document.getElementById('loadingIndicator');
const pdfContainer = document.getElementById('pdfContainer');
Expand Down Expand Up @@ -81,7 +84,7 @@
totalCharacters += text.length;
totalWords += text.split(/\s+/).length;

if (searchString && searchRegex.test(text)) {
if (searchRegex.test(text)) {
console.log(`Found "${searchString}" on page ${pageNum}`);
targetPageNum = pageNum;
const viewport = page.getViewport({scale: 1.5});
Expand Down

0 comments on commit 5c2798e

Please sign in to comment.