|
楼主 |
kuing
发表于 2022-8-10 03:57
突然想起我之前在 chrome 安装了一个“Simple Allow Copy”插件专门用来解除各种复制限制的。
于是先在知乎上点亮该插件(以后好像就不用再点),再用油猴,复制他人的也没问题了。
=====
哦还是有复制到多余 MathML 的问题……
好吧,再修改油猴,不搞什么小黑点图片了,直接让公式变成代码显示出来!:
(2022-8-10 20:01 更新)
- // ==UserScript==
- // @name zihu_ltx_cpy
- // @version 2022-8-10
- // @description for zihu ltx cpy
- // @match https://*.zhihu.com/*
- // @run-at context-menu
- // ==/UserScript==
- (function() {
- 'use strict';
- let zmaths = document.querySelectorAll('.ztext-math');
- for (let item of zmaths) {
- var tex = item.dataset.tex;
- if (!(tex.search(/align\*|gather\*|equation\*|eqnarray|\\\]/) == -1)) {
- tex = tex.replace(/\\\\ *$/g,'')
- .replace(/(\\begin\{(align\*|gather\*|equation\*|eqnarray)\})/g,'$1\n')
- .replace(/(\\end\{(align\*|gather\*|equation\*|eqnarray)\})/g,'\n$1')
- ;
- } else if (!(tex.search(/\\\\/) == -1)) {
- tex = tex.replace(/\\\\ *$/g,'');
- tex = '\\['+tex+'\\]';
- } else {
- tex = '$'+tex+'$';
- }
- tex = tex.replace(/\\\\(\[.*?\])?/g,'\\\\$1\n');
- item.innerText = tex;
- }
- })();
复制代码
用法一样。
顺便又作一点小改进:
考虑到知乎上很多人喜欢在公式末尾加 \\\\ 以变成行间公式,但在知乎外是不应该有的,所以去掉;
兼容 \\\\[...] 这种换行;
(之前一直复制自己的,所以不曾考虑以上两点(我从来不这样写……))
当发现公式内有 \\\\ 时判断为行间公式,此时两边加的是 \\[ 和 \\](会误伤某些原先在行内的多行公式比如分段函数); |
评分
-
查看全部评分
|