1
|
/**
|
2
|
* SPDX-License-Identifier: CC0-1.0
|
3
|
*
|
4
|
* Fix benchmarks in phoronix.com articles
|
5
|
*
|
6
|
* Copyright (C) 2021 Wojtek Kosior <koszko@koszko.org>
|
7
|
*
|
8
|
* This program is free software: you can redistribute it and/or modify
|
9
|
* it under the terms of the CC0 1.0 Universal License as published by
|
10
|
* the Creative Commons Corporation.
|
11
|
*
|
12
|
* This program is distributed in the hope that it will be useful,
|
13
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
* CC0 1.0 Universal License for more details.
|
16
|
*/
|
17
|
|
18
|
/* Use with https://www.phoronix.com/*** */
|
19
|
|
20
|
/*
|
21
|
* Phoronix normally includes scripts that call document.write() to inject
|
22
|
* <img> tags. The most obvious way o code a fix would then be do download and
|
23
|
* parse the contents of those scripts. CORS, however, doesn't allow this.
|
24
|
* Instead, we notice that the openbenchmarking embed script url is related to
|
25
|
* the actual image url we need, so we can create <img>'s from it straight away.
|
26
|
*/
|
27
|
for (const script of document.scripts) {
|
28
|
const match = /openbenchmarking.org\/+(embed.php\?.*)p=0$/.exec(script.src);
|
29
|
if (!match) continue;
|
30
|
|
31
|
const img = document.createElement("img");
|
32
|
img.src = `https://openbenchmarking.org/${match[1]}p=2`;
|
33
|
img.setAttribute("type", "image/svg+xml");
|
34
|
img.setAttribute("width", "100%");
|
35
|
img.setAttribute("height", "auto");
|
36
|
|
37
|
script.parentElement.insertBefore(img, script);
|
38
|
}
|