From d9b9bcbcc6a9e31eaeadce99016318869bc63264 Mon Sep 17 00:00:00 2001 From: Miguel Casas-Sanchez Date: Tue, 15 Jul 2014 13:56:17 +0200 Subject: [PATCH 01/35] Update redirections Redirection to raw.github.com seem to have stopped working, instead raw.githubusercontent.com is in use now. --- htmlpreview.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htmlpreview.js b/htmlpreview.js index 6f95205..10c1887 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -9,7 +9,7 @@ var HTMLPreview = { }, raw: function() { - return HTMLPreview.file().replace(/\/\/github\.com/, '//raw.github.com').replace(/\/blob\//, '/'); //Get URL of the raw file + return HTMLPreview.file().replace(/\/\/github\.com/, '//raw.githubusercontent.com').replace(/\/blob\//, '/'); //Get URL of the raw file }, replaceAssets: function() { @@ -17,7 +17,7 @@ var HTMLPreview = { frame = document.querySelectorAll('iframe[src],frame[src]'); for(i = 0; i < frame.length; ++i) { src = frame[i].src; //Get absolute URL - if(src.indexOf('//raw.github.com') > 0 || src.indexOf('//bitbucket.org') > 0) { //Check if it's from raw.github.com or bitbucket.org + if(src.indexOf('//raw.githubusercontent.com') > 0 || src.indexOf('//bitbucket.org') > 0) { //Check if it's from raw.github.com or bitbucket.org frame[i].src = 'http://' + location.hostname + location.pathname + '?' + src; //Then rewrite URL so it can be loaded using YQL } } @@ -27,7 +27,7 @@ var HTMLPreview = { if(href.indexOf('#') > 0) { //Check if it's an anchor a[i].href = 'http://' + location.hostname + location.pathname + location.search + '#' + a[i].hash.substring(1); //Then rewrite URL with support for empty anchor } - else if(href.indexOf('//raw.github.com') > 0 || href.indexOf('//bitbucket.org') > 0) { //Check if it's from raw.github.com or bitbucket.org + else if(href.indexOf('//raw.githubusercontent.com') > 0 || href.indexOf('//bitbucket.org') > 0) { //Check if it's from raw.github.com or bitbucket.org a[i].href = 'http://' + location.hostname + location.pathname + '?' + href; //Then rewrite URL so it can be loaded using YQL } } @@ -36,14 +36,14 @@ var HTMLPreview = { link = document.querySelectorAll('link[rel=stylesheet]'); for(i = 0; i < link.length; ++i) { href = link[i].href; //Get absolute URL - if(href.indexOf('//raw.github.com') > 0 || href.indexOf('//bitbucket.org') > 0) { //Check if it's from raw.github.com or bitbucket.org + if(href.indexOf('//raw.githubusercontent.com') > 0 || href.indexOf('//bitbucket.org') > 0) { //Check if it's from raw.github.com or bitbucket.org HTMLPreview.send(href, 'loadCSS'); //Then load it using YQL } } script = document.querySelectorAll('script'); for(i = 0; i < script.length; ++i) { src = script[i].src; //Get absolute URL - if(src.indexOf('//raw.github.com') > 0 || src.indexOf('//bitbucket.org') > 0) { //Check if it's from raw.github.com or bitbucket.org + if(src.indexOf('//raw.githubusercontent.com') > 0 || src.indexOf('//bitbucket.org') > 0) { //Check if it's from raw.github.com or bitbucket.org HTMLPreview.send(src, 'loadJS'); //Then load it using YQL } else if(!src && script[i].innerHTML.indexOf('HTMLPreview') < 0) { //Move all inline scripts except HTMLPreview.replaceAssets() From e6ac25a07ff61d34eee99bbe694316cb6fc712c6 Mon Sep 17 00:00:00 2001 From: niu tech Date: Wed, 16 Jul 2014 03:14:22 +0200 Subject: [PATCH 02/35] Change raw.github.com to raw.githubusercontent.com --- htmlpreview.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htmlpreview.min.js b/htmlpreview.min.js index 16b3f23..f7ad7da 100644 --- a/htmlpreview.min.js +++ b/htmlpreview.min.js @@ -1 +1 @@ -var HTMLPreview={content:"",previewform:document.getElementById("previewform"),file:function(){return location.search.substring(1)},raw:function(){return HTMLPreview.file().replace(/\/\/github\.com/,"//raw.github.com").replace(/\/blob\//,"/")},replaceAssets:function(){var a,b,c;a=document.querySelectorAll("iframe[src],frame[src]");for(b=0;ba[b].innerHTML.indexOf("HTMLPreview")&&document.write(a[b].outerHTML)}},loadHTML:function(a){a&&a.query&&a.query.results&&a.query.results.resources&&a.query.results.resources.content&&200==a.query.results.resources.status?(HTMLPreview.content=a.query.results.resources.content.replace(//i,'').replace(/<\/body>/i,'').replace(/<\/head>\s* just after and inject '); } }, From d5951d36e7518949d64398dda43f1a550570691b Mon Sep 17 00:00:00 2001 From: niu tech Date: Thu, 17 Jul 2014 17:12:00 +0200 Subject: [PATCH 04/35] Follow redirects Fixes #18 --- htmlpreview.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htmlpreview.min.js b/htmlpreview.min.js index f7ad7da..52e805e 100644 --- a/htmlpreview.min.js +++ b/htmlpreview.min.js @@ -1 +1 @@ -var HTMLPreview={content:"",previewform:document.getElementById("previewform"),file:function(){return location.search.substring(1)},raw:function(){return HTMLPreview.file().replace(/\/\/github\.com/,"//raw.githubusercontent.com").replace(/\/blob\//,"/")},replaceAssets:function(){var a,b,c;a=document.querySelectorAll("iframe[src],frame[src]");for(b=0;ba[b].innerHTML.indexOf("HTMLPreview")&&document.write(a[b].outerHTML)}},loadHTML:function(a){a&&a.query&&a.query.results&&a.query.results.resources&&a.query.results.resources.content&&200==a.query.results.resources.status?(HTMLPreview.content=a.query.results.resources.content.replace(//i,'').replace(/<\/body>/i,'').replace(/<\/head>\s* just after and inject ').replace(/<\/head>\s* just after and inject '); //Get content using YQL + document.write(''); //Get content using YQL }, submitform: function() { diff --git a/htmlpreview.min.js b/htmlpreview.min.js index c23481a..97bb17d 100644 --- a/htmlpreview.min.js +++ b/htmlpreview.min.js @@ -1 +1 @@ -var HTMLPreview={content:"",previewform:document.getElementById("previewform"),file:function(){return location.search.substring(1)},raw:function(){return HTMLPreview.file().replace(/\/\/github\.com/,"//raw.githubusercontent.com").replace(/\/blob\//,"/")},replaceAssets:function(){var a,b,c;a=document.querySelectorAll("iframe[src],frame[src]");for(b=0;ba[b].innerHTML.indexOf("HTMLPreview")&&document.write(a[b].outerHTML)}},loadHTML:function(a){a&&a.query&&a.query.diagnostics&&a.query.diagnostics.redirect?HTMLPreview.send(a.query.diagnostics.redirect.content,"loadHTML"):a&&a.query&&a.query.results&&a.query.results.resources&&a.query.results.resources.content&&200==a.query.results.resources.status?(HTMLPreview.content=a.query.results.resources.content.replace(//i,'').replace(/<\/body>/i,' -

+

Enter the HTML file to preview:

or prepend to the URL: http://htmlpreview.github.io/?https://raw.github.com/twbs/bootstrap/gh-pages/2.3.2/index.html

or use this bookmarklet while browsing GitHub or BitBucket: HTMLPreview

@@ -56,4 +56,4 @@

GitHub & BitBucket HTML Preview

- \ No newline at end of file + From 2b7e5b7e6ed18e5c9be66021af5ed0922989b763 Mon Sep 17 00:00:00 2001 From: niu tech Date: Sat, 3 Oct 2015 01:35:06 +0200 Subject: [PATCH 14/35] Update readme.md --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index ec66bed..148ba69 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,7 @@ If you try to open raw versions of any HTML, CSS or JS files in a web browser di In order to use it, just prepend this fragment to the URL of any HTML file: **[http://htmlpreview.github.io/?](http://htmlpreview.github.io/?)** E.g.: -http://htmlpreview.github.io/?https://raw.github.com/twbs/bootstrap/gh-pages/2.3.2/index.html +http://htmlpreview.github.io/?https://github.com/twbs/bootstrap/gh-pages/2.3.2/index.html http://htmlpreview.github.io/?https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html What it does is load HTML using YQL, then process all links, frames, scripts and styles, and load each of them using YQL, so they can be evaluted in the browser. Here is the workflow: @@ -16,4 +16,4 @@ What it does is load HTML using YQL, then process all links, frames, scripts and HTMLPreview.init() -> HTMLPreview.send(HTML) -> YQL fetch HTML -> HTMLPreview.loadHTML(data) -> HTMLPreview.replaceAssets() -> HTMLPreview.send(CSS) -> YQL fetch CSS -> HTMLPreview.loadCSS(data) -> HTMLPreview.send(JS) -> YQL fetch JS -> HTMLPreview.loadJS(data) ``` -**GitHub & BitBucket HTML Preview** was tested under Google Chrome, Apple Safari and Mozilla Firefox, and it should work with majority of websites, not only GitHub & BitBucket. \ No newline at end of file +**GitHub & BitBucket HTML Preview** was tested under Google Chrome, Apple Safari and Mozilla Firefox, and it should work with majority of websites, not only GitHub & BitBucket. From 94a5a0b5ea80a5bdf6cc042ed2558010552f71c8 Mon Sep 17 00:00:00 2001 From: niu tech Date: Sat, 3 Oct 2015 01:36:28 +0200 Subject: [PATCH 15/35] Update readme.md --- readme.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 148ba69..3270148 100644 --- a/readme.md +++ b/readme.md @@ -5,11 +5,10 @@ Many GitHub repositories don't use GitHub Pages to host their HTML files. **GitH If you try to open raw versions of any HTML, CSS or JS files in a web browser directly from GitHub, all you will see are sources. GitHub forces them to use the "text/plain" content-type, so they cannot be interpreted. This script overrides it by using Yahoo! Query Language. -In order to use it, just prepend this fragment to the URL of any HTML file: **[http://htmlpreview.github.io/?](http://htmlpreview.github.io/?)** +In order to use it, just prepend this fragment to the URL of any HTML file: **[http://htmlpreview.github.io/?](http://htmlpreview.github.io/?)** e.g.: -E.g.: -http://htmlpreview.github.io/?https://github.com/twbs/bootstrap/gh-pages/2.3.2/index.html -http://htmlpreview.github.io/?https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html + - http://htmlpreview.github.io/?https://github.com/twbs/bootstrap/gh-pages/2.3.2/index.html + - http://htmlpreview.github.io/?https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html What it does is load HTML using YQL, then process all links, frames, scripts and styles, and load each of them using YQL, so they can be evaluted in the browser. Here is the workflow: ``` From ae77e41345d496746e2865e4d70310cec9320e79 Mon Sep 17 00:00:00 2001 From: niu tech Date: Wed, 20 Jan 2016 20:37:28 +0100 Subject: [PATCH 16/35] Remove Google AdSense --- index.html | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/index.html b/index.html index 8ea0662..c84a719 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ color: #333; } h1 { - font-size: 24px; + font-size: 26px; } a { color: #666; @@ -33,22 +33,7 @@

GitHub & BitBucket HTML Preview

-

-

-

Enter the HTML file to preview:

+

Enter URL of the HTML file to preview:

or prepend to the URL: http://htmlpreview.github.io/?https://raw.github.com/twbs/bootstrap/gh-pages/2.3.2/index.html

or use this bookmarklet while browsing GitHub or BitBucket: HTMLPreview

From 2fa31c371acfa392783fdd93838b58362ab1ba51 Mon Sep 17 00:00:00 2001 From: niutech Date: Wed, 2 Mar 2016 09:51:18 +0100 Subject: [PATCH 17/35] Update Headers Datatable URL --- htmlpreview.js | 2 +- htmlpreview.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htmlpreview.js b/htmlpreview.js index aa11c8e..88aea21 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -116,7 +116,7 @@ var HTMLPreview = { }, send: function(file, callback) { - document.write(''); //Get content using YQL + document.write(''); //Get content using YQL }, submitform: function() { diff --git a/htmlpreview.min.js b/htmlpreview.min.js index 97bb17d..88fc2a7 100644 --- a/htmlpreview.min.js +++ b/htmlpreview.min.js @@ -1 +1 @@ -var HTMLPreview={content:"",previewform:document.getElementById("previewform"),file:function(){return location.search.substring(1)},raw:function(){return HTMLPreview.file().replace(/\/\/github\.com/,"//raw.githubusercontent.com").replace(/\/blob\//,"/")},replaceAssets:function(){var a,b,c;a=document.querySelectorAll("iframe[src],frame[src]");for(b=0;ba[b].innerHTML.indexOf("HTMLPreview")&&document.write(a[b].outerHTML)}},loadHTML:function(a){a&&a.query&&a.query.diagnostics&&a.query.diagnostics.redirect?HTMLPreview.send(a.query.diagnostics.redirect.content,"loadHTML"):a&&a.query&&a.query.results&&a.query.results.resources&&a.query.results.resources.content&&200==a.query.results.resources.status?(HTMLPreview.content=a.query.results.resources.content.replace(//i,'').replace(/<\/body>/i,'').replace(/<\/head>\s* just after and inject ').replace(/<\/head>\s* just after and inject '); //Get content using YQL + document.write(''); //Get content using YQL }, submitform: function() { From f4d9151d750069bc314c052363625124cd3cf994 Mon Sep 17 00:00:00 2001 From: niu tech Date: Sun, 2 Dec 2018 20:24:00 +0100 Subject: [PATCH 21/35] Fixed broken YQL query --- htmlpreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htmlpreview.js b/htmlpreview.js index d1b982c..440dfe3 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -117,7 +117,7 @@ var HTMLPreview = { }, send: function(file, callback) { - document.write(''); //Get content using YQL + document.write(''); //Get content using YQL }, submitform: function() { From 1d6b45d8a69264fd7be1f57a71894237720e46c6 Mon Sep 17 00:00:00 2001 From: niu tech Date: Sun, 2 Dec 2018 20:24:43 +0100 Subject: [PATCH 22/35] Fixed broken YQL query --- htmlpreview.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htmlpreview.min.js b/htmlpreview.min.js index b5d3e23..c62f7b2 100644 --- a/htmlpreview.min.js +++ b/htmlpreview.min.js @@ -1 +1 @@ -var HTMLPreview={content:"",previewform:document.getElementById("previewform"),file:function(){return location.search.substring(1)},raw:function(){return HTMLPreview.file().replace(/\/\/github\.com/,"//raw.githubusercontent.com").replace(/\/blob\//,"/")},replaceAssets:function(){var a,b,c;a=document.querySelectorAll("iframe[src],frame[src]");for(b=0;b/i,'').replace(//i,'').replace(/<\/head>\s* just after and inject '); + var loadJS = function (data) { + if (data) { + var script = document.createElement('script'); + script.innerHTML = data; + document.body.appendChild(script); } - }, - - send: function(file, callback) { - document.write(''); //Get content using YQL - }, + }; + + var fetchProxy = function (url, options, i) { + var proxy = [ + 'https://cors.io/?', + 'https://jsonp.afeld.me/?url=', + 'https://cors-anywhere.herokuapp.com/' + ]; + return fetch(proxy[i] + url, options).then(function (res) { + if (!res.ok) + throw new Error('Cannot load ' + url + ': ' + res.status + ' ' + res.statusText); + return res.text(); + }).catch(function (error) { + if (i === proxy.length - 1) + throw error; + return fetchProxy(url, options, i + 1); + }) + }; - submitform: function() { - location.href = '/?' + document.getElementById('file').value; - return false; - }, + if (url && url.indexOf(location.hostname) < 0) + fetchProxy(url, null, 0).then(loadHTML).catch(function (error) { + console.error(error); + previewForm.style.display = 'block'; + previewForm.innerText = error; + }); + else + previewForm.style.display = 'block'; - init: function() { - HTMLPreview.previewform.onsubmit = HTMLPreview.submitform; - if(HTMLPreview.file()) { - HTMLPreview.previewform.innerHTML = '

Loading...

'; - HTMLPreview.send(HTMLPreview.raw(), 'loadHTML'); - } - } -} +})() diff --git a/htmlpreview.min.js b/htmlpreview.min.js deleted file mode 100644 index 6901891..0000000 --- a/htmlpreview.min.js +++ /dev/null @@ -1 +0,0 @@ -var HTMLPreview={content:"",previewform:document.getElementById("previewform"),file:function(){return location.search.substring(1)},raw:function(){return HTMLPreview.file().replace(/\/\/github\.com/,"//raw.githubusercontent.com").replace(/\/blob\//,"/")},replaceAssets:function(){var a,b,c;a=document.querySelectorAll("iframe[src],frame[src]");for(b=0;b/i,'').replace(//i,' - + diff --git a/readme.md b/readme.md index 3270148..33818c5 100644 --- a/readme.md +++ b/readme.md @@ -1,18 +1,21 @@ GitHub & BitBucket HTML Preview ------------------------------- -Many GitHub repositories don't use GitHub Pages to host their HTML files. **GitHub & BitBucket HTML Preview** allows you to render those files without cloning or downloading whole repositories. It is a client-side solution and does not involve any third party hosting servers (except for Yahoo! Query Language to fetch assets). +Many GitHub repositories don't use GitHub Pages to host their HTML files. **GitHub & BitBucket HTML Preview** allows you to render those files without cloning or downloading whole repositories. It is a client-side solution using a CORS proxy to fetch assets. -If you try to open raw versions of any HTML, CSS or JS files in a web browser directly from GitHub, all you will see are sources. GitHub forces them to use the "text/plain" content-type, so they cannot be interpreted. This script overrides it by using Yahoo! Query Language. +If you try to open raw version of any HTML, CSS or JS file in a web browser directly from GitHub, all you will see is a source code. GitHub forces them to use the "text/plain" content-type, so they cannot be interpreted. This script overrides it by using a CORS proxy. -In order to use it, just prepend this fragment to the URL of any HTML file: **[http://htmlpreview.github.io/?](http://htmlpreview.github.io/?)** e.g.: +## Usage - - http://htmlpreview.github.io/?https://github.com/twbs/bootstrap/gh-pages/2.3.2/index.html - - http://htmlpreview.github.io/?https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html +In order to use it, just prepend this fragment to the URL of any HTML file: **[https://htmlpreview.github.io/?](https://htmlpreview.github.io/?)** e.g.: -What it does is load HTML using YQL, then process all links, frames, scripts and styles, and load each of them using YQL, so they can be evaluted in the browser. Here is the workflow: -``` -HTMLPreview.init() -> HTMLPreview.send(HTML) -> YQL fetch HTML -> HTMLPreview.loadHTML(data) -> HTMLPreview.replaceAssets() -> HTMLPreview.send(CSS) -> YQL fetch CSS -> HTMLPreview.loadCSS(data) -> HTMLPreview.send(JS) -> YQL fetch JS -> HTMLPreview.loadJS(data) -``` + - https://htmlpreview.github.io/?https://github.com/twbs/bootstrap/gh-pages/2.3.2/index.html + - https://htmlpreview.github.io/?https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html -**GitHub & BitBucket HTML Preview** was tested under Google Chrome, Apple Safari and Mozilla Firefox, and it should work with majority of websites, not only GitHub & BitBucket. +What it does is: load HTML using CORS proxy, then process all links, frames, scripts and styles, and load each of them using CORS proxy, so they can be evaluted by the browser. + +**GitHub & BitBucket HTML Preview** was tested under the latest Google Chrome and Mozilla Firefox. + +## License + +© 2019 Jerzy GÅ‚owacki under Apache License 2.0. From fef525182c1d112d1751b3bf8813af0146b9b54d Mon Sep 17 00:00:00 2001 From: Sergey Kolomenkin Date: Sat, 7 Dec 2019 14:51:49 +0300 Subject: [PATCH 26/35] disable cors.io proxy because it is broken Issue: https://github.com/htmlpreview/htmlpreview.github.com/issues/78 --- htmlpreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htmlpreview.js b/htmlpreview.js index 1390c01..e637c97 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -88,7 +88,7 @@ var fetchProxy = function (url, options, i) { var proxy = [ - 'https://cors.io/?', + //'https://cors.io/?', 'https://jsonp.afeld.me/?url=', 'https://cors-anywhere.herokuapp.com/' ]; From 55974aea3b6791596f15dca3f82f44dab6b2610a Mon Sep 17 00:00:00 2001 From: 0xflotus <0xflotus@gmail.com> Date: Thu, 28 May 2020 01:51:35 +0200 Subject: [PATCH 27/35] (readme): fixed small error --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 33818c5..3721989 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ In order to use it, just prepend this fragment to the URL of any HTML file: **[h - https://htmlpreview.github.io/?https://github.com/twbs/bootstrap/gh-pages/2.3.2/index.html - https://htmlpreview.github.io/?https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html -What it does is: load HTML using CORS proxy, then process all links, frames, scripts and styles, and load each of them using CORS proxy, so they can be evaluted by the browser. +What it does is: load HTML using CORS proxy, then process all links, frames, scripts and styles, and load each of them using CORS proxy, so they can be evaluated by the browser. **GitHub & BitBucket HTML Preview** was tested under the latest Google Chrome and Mozilla Firefox. From adaa08ac90758703e6294003b5a24a0e74286e17 Mon Sep 17 00:00:00 2001 From: niu tech Date: Wed, 7 Oct 2020 03:35:05 +0200 Subject: [PATCH 28/35] Fix CORS proxy --- htmlpreview.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/htmlpreview.js b/htmlpreview.js index e637c97..f01dc1c 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -88,13 +88,11 @@ var fetchProxy = function (url, options, i) { var proxy = [ - //'https://cors.io/?', - 'https://jsonp.afeld.me/?url=', + 'https://thingproxy.freeboard.io/fetch/', + 'https://yacdn.org/serve/', 'https://cors-anywhere.herokuapp.com/' ]; return fetch(proxy[i] + url, options).then(function (res) { - if (!res.ok) - throw new Error('Cannot load ' + url + ': ' + res.status + ' ' + res.statusText); return res.text(); }).catch(function (error) { if (i === proxy.length - 1) @@ -104,7 +102,10 @@ }; if (url && url.indexOf(location.hostname) < 0) - fetchProxy(url, null, 0).then(loadHTML).catch(function (error) { + fetch(url).then(function (res) { + if (!res.ok) throw new Error('Cannot load ' + url + ': ' + res.status + ' ' + res.statusText); + return res.text(); + }).then(loadHTML).catch(function (error) { console.error(error); previewForm.style.display = 'block'; previewForm.innerText = error; From a9b391d07a904a04d3ab1d5080638c33fb3cbfb1 Mon Sep 17 00:00:00 2001 From: niu tech Date: Wed, 7 Oct 2020 03:42:42 +0200 Subject: [PATCH 29/35] Fix CORS proxy --- htmlpreview.js | 1 - 1 file changed, 1 deletion(-) diff --git a/htmlpreview.js b/htmlpreview.js index f01dc1c..9349387 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -88,7 +88,6 @@ var fetchProxy = function (url, options, i) { var proxy = [ - 'https://thingproxy.freeboard.io/fetch/', 'https://yacdn.org/serve/', 'https://cors-anywhere.herokuapp.com/' ]; From ed8195e6fdbc28fc5d40c88f4e9dd42076374568 Mon Sep 17 00:00:00 2001 From: niu tech Date: Wed, 7 Oct 2020 03:55:12 +0200 Subject: [PATCH 30/35] Fix CORS proxy --- htmlpreview.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htmlpreview.js b/htmlpreview.js index 9349387..8e1fd5a 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -88,8 +88,9 @@ var fetchProxy = function (url, options, i) { var proxy = [ + 'https://cors-anywhere.herokuapp.com/', 'https://yacdn.org/serve/', - 'https://cors-anywhere.herokuapp.com/' + 'https://api.codetabs.com/v1/proxy/?quest=' ]; return fetch(proxy[i] + url, options).then(function (res) { return res.text(); From f56fa2a29d8313456c018614cf30327593b2ab1c Mon Sep 17 00:00:00 2001 From: niu tech Date: Wed, 7 Oct 2020 04:11:24 +0200 Subject: [PATCH 31/35] Fix CORS proxy --- htmlpreview.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htmlpreview.js b/htmlpreview.js index 8e1fd5a..14afe61 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -89,10 +89,11 @@ var fetchProxy = function (url, options, i) { var proxy = [ 'https://cors-anywhere.herokuapp.com/', - 'https://yacdn.org/serve/', + 'https://yacdn.org/proxy/', 'https://api.codetabs.com/v1/proxy/?quest=' ]; return fetch(proxy[i] + url, options).then(function (res) { + if (!res.ok) throw new Error('Cannot load ' + url + ': ' + res.status + ' ' + res.statusText); return res.text(); }).catch(function (error) { if (i === proxy.length - 1) From 2c23ebae9ab2315831bdde75b8fe2055d4360a72 Mon Sep 17 00:00:00 2001 From: niu tech Date: Tue, 13 Oct 2020 14:00:50 +0200 Subject: [PATCH 32/35] Dispatch DOMContentLoaded event Fixes #87 --- htmlpreview.js | 1 + 1 file changed, 1 insertion(+) diff --git a/htmlpreview.js b/htmlpreview.js index 14afe61..2f08b15 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -55,6 +55,7 @@ for (i = 0; i < res.length; ++i) { loadJS(res[i]); } + document.dispatchEvent(new Event('DOMContentLoaded', {bubbles: true, cancelable: true})); //Dispatch DOMContentLoaded event after loading all scripts }); }; From 1e4aa6dbb4a48362dea5c1537bbeed9a95d15c7d Mon Sep 17 00:00:00 2001 From: TrianguloY Date: Fri, 16 Oct 2020 12:32:00 +0200 Subject: [PATCH 33/35] Try fetching without proxy first When fetching a resource, try directly first. If it throws an error, then try with proxies. Fixes #95 Should also reduce drastically the petitions to the proxy servers (will only be made if the non-proxy fails) --- htmlpreview.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/htmlpreview.js b/htmlpreview.js index 2f08b15..d3996eb 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -89,6 +89,7 @@ var fetchProxy = function (url, options, i) { var proxy = [ + '', // try without proxy first 'https://cors-anywhere.herokuapp.com/', 'https://yacdn.org/proxy/', 'https://api.codetabs.com/v1/proxy/?quest=' @@ -104,10 +105,7 @@ }; if (url && url.indexOf(location.hostname) < 0) - fetch(url).then(function (res) { - if (!res.ok) throw new Error('Cannot load ' + url + ': ' + res.status + ' ' + res.statusText); - return res.text(); - }).then(loadHTML).catch(function (error) { + fetchProxy(url, null, 0).then(loadHTML).catch(function (error) { console.error(error); previewForm.style.display = 'block'; previewForm.innerText = error; From a60683d86024c899d0b8165861d15cd1c8f65198 Mon Sep 17 00:00:00 2001 From: Peter Chubb Date: Fri, 9 Jul 2021 14:23:16 +1000 Subject: [PATCH 34/35] Delete no-longer-running yacdn.org proxy. yacdn.org has been down for some time. Having it in the list of proxies means that attempting to view generated HTML can take a long time, before connection attempts time out. --- htmlpreview.js | 1 - 1 file changed, 1 deletion(-) diff --git a/htmlpreview.js b/htmlpreview.js index 2f08b15..57b9009 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -90,7 +90,6 @@ var fetchProxy = function (url, options, i) { var proxy = [ 'https://cors-anywhere.herokuapp.com/', - 'https://yacdn.org/proxy/', 'https://api.codetabs.com/v1/proxy/?quest=' ]; return fetch(proxy[i] + url, options).then(function (res) { From 6a635bd194dda9abf1c573f623d241ebe45af689 Mon Sep 17 00:00:00 2001 From: Peter Chubb Date: Fri, 9 Jul 2021 14:32:23 +1000 Subject: [PATCH 35/35] 'https://cors-anywhere.herokuapp.com/' is also broken See https://github.com/Rob--W/cors-anywhere/issues/301 Signed-off-by: Peter Chubb --- htmlpreview.js | 1 - 1 file changed, 1 deletion(-) diff --git a/htmlpreview.js b/htmlpreview.js index 57b9009..f5e1eb7 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -89,7 +89,6 @@ var fetchProxy = function (url, options, i) { var proxy = [ - 'https://cors-anywhere.herokuapp.com/', 'https://api.codetabs.com/v1/proxy/?quest=' ]; return fetch(proxy[i] + url, options).then(function (res) {