您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
latex.codecogs.com, chart.apis.google
// ==UserScript== // @name gamedev latex support // @namespace e6y // @description latex.codecogs.com, chart.apis.google // @version 0.7 // @include /^https?://(www.)?gamedev\.ru\/.*$/ // @grant none // ==/UserScript== /* jshint esversion: 6 */ (function () { process([ filter_google, filter_codecogs, ]).catch(console.log.bind(console)); async function process(filters) { for (let fn of filters) { for (let {node, tex} of fn()) { await load_katex_once(); let container = document.createElement('span'); tex = tex.trim().replace(/^\\\[/, '').replace(/\\]$/, ''); try { container.innerHTML = katex.renderToString(tex, {throwOnError: true}); container.title = tex; node.replaceWith(container); } catch (e) { console.log(e.message); } } } } async function load_katex_once() { if (!load_katex_once.loaded) { await load_katex(); load_katex_once.loaded = true; } } async function load_katex() { let css = document.createElement('link'); css.rel = 'stylesheet'; css.href = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css'; document.head.appendChild(css); return new Promise((resolve, reject) => { let script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js'; script.onload = resolve; script.onerror = reject; document.head.appendChild(script); }); } function* filter_codecogs() { for (let img of [...document.querySelectorAll('img[src^="https://latex.codecogs.com"]')]) { let tex = decodeURIComponent(img.src) .replace(/^https:\/\/latex\.codecogs\.com\/[^.]+?\.latex\?/, '') .replace('\\bg_white', '') .replace(/\\inline/g, '') ; yield {node: img, tex: tex}; } } function* filter_google() { for (let img of [...document.querySelectorAll('img[src^="https://chart.apis.google.com/chart?"]')]) { let chl = (new URL(img.src)).searchParams.get('chl'); if (chl) { let tex = decodeURIComponent(chl); yield {node: img, tex: tex}; } } } })();