Overv / Open.GL

The source code and content of Open.GL.
http://open.gl/
1.07k stars 259 forks source link

Use another CDN for Highlight.js #69

Closed dmitmel closed 4 years ago

dmitmel commented 5 years ago

yandex.st along with other Yandex domains is blocked in Ukraine. Please use other CDN, for example jsdelivr which is recommended on the download page of Highlight.js:

<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.16.2/build/highlight.min.js"></script>

Relevant code is here:

https://github.com/Overv/Open.GL/blob/63b4d7714d7ed68807386b143c1018b2a9bfce71/index.php#L75

dmitmel commented 5 years ago

It seems that you use a very old version of Highlight.js. I can try updating it and opening a pull request.

dmitmel commented 5 years ago

It seems like your website works with older versions of HLJS, you just need to update the theme file (includes/zenburn.min.css) or use one from a CDN.

Anyway, in the meantime I created this little script for GreaseMonkey as a workaround for this issue:

// ==UserScript==
// @name     open.gl Highlight.js fix
// @version  1
// @grant    none
// @match https://open.gl/*
// @run-at document-start
// ==/UserScript==

// create a dummy Highlight.js object in the global scope, so that scripts that depend on it don't crash
window.eval("var hljs = { initHighlightingOnLoad: () => {} }");

document.addEventListener('readystatechange', () => {
  if (document.readyState !== 'interactive') return;
  // this code is going to run right after the DOM tree has been parsed

  let scriptTags = Array.from(document.getElementsByTagName('script'));

  let incorrectScript = scriptTags.find(script => script.src.includes('//yandex.st/highlightjs/6.1/highlight.min.js'));
  incorrectScript.parentElement.removeChild(incorrectScript);

  let correctScript = document.createElement('script');
  correctScript.src = '//cdnjs.cloudflare.com/ajax/libs/highlight.js/7.5/highlight.min.js';
  correctScript.setAttribute('onload', 'hljs.initHighlightingOnLoad()');
  document.body.appendChild(correctScript);
});
Overv commented 4 years ago

I've fixed the problem by mirroring highlight.js locally just like the other dependencies.

dmitmel commented 4 years ago

Thanks!