aboutsummaryrefslogtreecommitdiff
path: root/src/phoronix-com-fix-benchmarks/phoronix_benchmarks.js
blob: a332cc0d94612f6e970c1134108122f85afbd5c9 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
 * SPDX-License-Identifier: CC0-1.0
 *
 * Fix benchmarks in phoronix.com articles
 *
 * Copyright (C) 2021 Wojtek Kosior <koszko@koszko.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the CC0 1.0 Universal License as published by
 * the Creative Commons Corporation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * CC0 1.0 Universal License for more details.
 */

/* Use with https://www.phoronix.com/*** */

/*
 * Phoronix normally includes scripts that call document.write() to inject
 * <img> tags. The most obvious way o code a fix would then be do download and
 * parse the contents of those scripts. CORS, however, doesn't allow this.
 * Instead, we notice that the openbenchmarking embed script url is related to
 * the actual image url we need, so we can create <img>'s from it straight away.
 */
for (const script of document.scripts) {
    const match = /openbenchmarking.org\/+(embed.php\?.*)p=0$/.exec(script.src);
    if (!match) continue;

    const img = document.createElement("img");
    img.src = `https://openbenchmarking.org/${match[1]}p=2`;
    img.setAttribute("type", "image/svg+xml");
    img.setAttribute("width", "100%");
    img.setAttribute("height", "auto");

    script.parentElement.insertBefore(img, script);
}