MCPcopy
hub / github.com/darkreader/darkreader / isPDF

Function isPDF

src/utils/url.ts:301–327  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

299const wikiPDFPathRegexp = /^\/.*\/[a-z]+\:[^\:\/]+\.pdf/i;
300
301export function isPDF(url: string): boolean {
302 try {
303 const {hostname, pathname} = new URL(url);
304 if (pathname.includes('.pdf')) {
305 if (
306 ((hostname.endsWith('.wikimedia.org') || hostname.endsWith('.wikipedia.org')) && pathname.match(wikiPDFPathRegexp)) ||
307 (hostname.endsWith('.dropbox.com') && pathname.startsWith('/s/') && (pathname.endsWith('.pdf') || pathname.endsWith('.PDF')))
308 ) {
309 return false;
310 }
311 if (pathname.endsWith('.pdf')) {
312 for (let i = pathname.length; i >= 0; i--) {
313 if (pathname[i] === '=') {
314 return false;
315 } else if (pathname[i] === '/') {
316 return true;
317 }
318 }
319 } else {
320 return false;
321 }
322 }
323 } catch (e) {
324 // Do nothing
325 }
326 return false;
327}
328
329const indexedSiteLists = new WeakMap<string[], URLTemplateIndex>();
330

Callers 8

pdfMethod · 0.90
ExtensionClass · 0.90
canInjectScriptFunction · 0.90
getSiteToggleDataFunction · 0.90
SiteToggleGroupFunction · 0.90
url.tests.tsFile · 0.90
url.tests.tsFile · 0.90
isURLEnabledFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected