From 5c2798e13059b62edd4fc9fbf5312795861c3558 Mon Sep 17 00:00:00 2001 From: Luke Stanley Date: Tue, 16 Jul 2024 10:51:51 +0100 Subject: [PATCH] Allow hash and search parameter --- pdf_deep_link.htm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pdf_deep_link.htm b/pdf_deep_link.htm index 68b33d7..26df949 100644 --- a/pdf_deep_link.htm +++ b/pdf_deep_link.htm @@ -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'); @@ -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});