From 0a708f74631fb1cb9ea3b15ddb14798d699cbba8 Mon Sep 17 00:00:00 2001 From: Egor Seredin <4819888+agmt@users.noreply.github.com> Date: Thu, 24 Aug 2023 21:23:26 +0900 Subject: [PATCH] Do not modify external URLs with segment See https://github.com/htmlpreview/htmlpreview.github.com/issues/133 --- htmlpreview.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htmlpreview.js b/htmlpreview.js index a38e616..d44cd1f 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -22,7 +22,9 @@ for (i = 0; i < a.length; ++i) { href = a[i].href; //Get absolute URL if (href.indexOf('#') > 0) { //Check if it's an anchor - a[i].href = '//' + location.hostname + location.pathname + location.search + '#' + a[i].hash.substring(1); //Then rewrite URL with support for empty anchor + if ((a[i].protocol + '//' + a[i].hostname + a[i].pathname) == url) { //Rewrite links to this document only + a[i].href = '//' + location.hostname + location.pathname + location.search + '#' + a[i].hash.substring(1); //Then rewrite URL with support for empty anchor + } // Do not modify external URLs with fragment } else if ((href.indexOf('//raw.githubusercontent.com') > 0 || href.indexOf('//bitbucket.org') > 0) && (href.indexOf('.html') > 0 || href.indexOf('.htm') > 0)) { //Check if it's from raw.github.com or bitbucket.org and to HTML files a[i].href = '//' + location.hostname + location.pathname + '?' + href; //Then rewrite URL so it can be loaded using CORS proxy }