diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/README.md b/README.md index 02f69b5..f8339a6 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ The easiest way to use Scrollbench.js is through the bookmarklet. 1. Make a new bookmark (e.g. just bookmark this site). 2. Edit the bookmarklet to have the name "scrollbench" and set its URL to this: - javascript:!function(){function e(){window.ScrollBench&&new ScrollBench({loadConfig:!0}).start()}if(!window.ScrollBench&&!window.scrollbench_bookmarklet){window.scrollbench_bookmarklet=!0;var n=document.createElement('script');return n.src='https://raw.github.com/natduca/scrollbench.js/master/src/scrollbench.js',n.addEventListener('load',e,!1),document.getElementsByTagName('head')[0].appendChild(n),void 0}e()}(); + javascript:! function () { function e () { window.ScrollBench && new ScrollBench ( { loadConfig: ! 0 } ).start () } function scriptLoaded () { window.scrollbench_bookmarklet = ! 0; var n = document.createElement ( 'script' ); n.innerHTML = this.responseText; n.addEventListener ( 'load', e, ! 1 ); document.getElementsByTagName ( 'head' )[ 0 ].appendChild ( n ); e (); } var scriptRequest = new XMLHttpRequest (); scriptRequest.addEventListener ( 'load', scriptLoaded ); scriptRequest.open ( 'GET', 'https://raw.githubusercontent.com/natduca/scrollbench.js/master/src/scrollbench.js' ); scriptRequest.send (); } (); 3. There is no 3, just run the bookmarklet: * On desktop browsers just click it. diff --git a/report.html b/report.html index 667a4ee..6b5661e 100644 --- a/report.html +++ b/report.html @@ -14,7 +14,7 @@ function hashToReport () { var el; var value; - var report = decodeURIComponent(window.location.hash.substr(1)).split(','); + var report = decodeURIComponent(document.body.dataset.resultHash).split(','); for ( var i = 0, l = report.length; i < l; i++ ) { value = report[i].split('='); diff --git a/src/scrollbench.js b/src/scrollbench.js index 3890d65..586e34c 100644 --- a/src/scrollbench.js +++ b/src/scrollbench.js @@ -8,8 +8,8 @@ */ (function (window, document) { - var CONFIG_URL = 'https://raw.github.com/natduca/scrollbench.js/master/src/config.js'; - var REPORT_URL = '//natduca.github.com/scrollbench.js/report.html'; + var CONFIG_URL = 'https://raw.githubusercontent.com/natduca/scrollbench.js/master/src/config.js'; + var REPORT_URL = '//raw.githubusercontent.com/natduca/scrollbench.js/master/report.html'; var reliabilityReport = {}; @@ -362,10 +362,17 @@ return; } - script = document.createElement('script'); - script.src = typeof this.options.loadConfig == 'string' ? this.options.loadConfig : CONFIG_URL; - script.addEventListener('load', parseConfig, false); - document.getElementsByTagName('head')[0].appendChild(script); + function scriptLoaded() { + script = document.createElement('script'); + script.innerHTML = this.responseText; + script.addEventListener('load', parseConfig, false); + document.getElementsByTagName('head')[0].appendChild(script); + } + + var scriptRequest = new XMLHttpRequest (); + scriptRequest.addEventListener ( 'load', scriptLoaded ); + scriptRequest.open ( 'GET', typeof this.options.loadConfig == 'string' ? this.options.loadConfig : CONFIG_URL ); + scriptRequest.send (); }, _waitForContent: function () { @@ -586,10 +593,21 @@ window.scrollTo(0, 0); } - frame.style.cssText = 'position:fixed;z-index:2147483640;bottom:0;left:0;width:100%;height:270px;padding:0;margin:0;border:0'; - frame.src = REPORT_URL + '#' + encodeURIComponent(parms.join(',')); - frame.id = 'scrollbench-report-frame'; - document.documentElement.appendChild(frame); + + function frameLoaded() { + frame.style.cssText = 'position:fixed;z-index:2147483640;bottom:0;left:0;width:100%;height:270px;padding:0;margin:0;border:0'; + frame.id = 'scrollbench-report-frame'; + document.documentElement.appendChild(frame); + document.getElementById(frame.id).contentWindow.document.open(); + document.getElementById(frame.id).contentWindow.document.write(this.responseText); + document.getElementById(frame.id).contentWindow.document.close(); + document.getElementById(frame.id).contentWindow.document.body.dataset.resultHash = encodeURIComponent(parms.join(',')); + } + + var frameRequest = new XMLHttpRequest (); + frameRequest.addEventListener ( 'load', frameLoaded ); + frameRequest.open ( 'GET', REPORT_URL ); + frameRequest.send (); // Close button is on the same parent page to avoid cross-domain errors close.style.cssText = 'position:fixed;z-index:2147483641;bottom:238px;right:0;width:88px;height:32px;padding:0;margin:0;border:0;background:transparent;cursor:pointer';