MCPcopy
hub / github.com/darkreader/darkreader / isRelativeHrefOnAbsolutePath

Function isRelativeHrefOnAbsolutePath

src/utils/url.ts:53–71  ·  view source on GitHub ↗
(href: string)

Source from the content-addressed store, hash-verified

51// Visa versa https://duck.com/ext.css should return fasle on https://duck.com/search/
52// We're checking if any relative value within ext.css could potentially not be on the same path.
53export function isRelativeHrefOnAbsolutePath(href: string): boolean {
54 if (href.startsWith('data:')) {
55 return true;
56 }
57 const url = parseURL(href);
58
59 if (url.protocol !== location.protocol) {
60 return false;
61 }
62 if (url.hostname !== location.hostname) {
63 return false;
64 }
65 if (url.port !== location.port) {
66 return false;
67 }
68 // Now check if the path is on the same path as the base
69 // We do this by getting the pathname up until the last slash.
70 return url.pathname === location.pathname;
71}
72
73export function getURLHostOrProtocol($url: string): string {
74 const url = new URL($url);

Callers 1

getRulesSyncFunction · 0.90

Calls 1

parseURLFunction · 0.85

Tested by

no test coverage detected