Forgot password?
 Create new account
Author: kuing

记录一回写油猴

[Copy link]

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2022-1-26 15:53:27
回复  kuing

实际使用 发现 \$$$1\$$\$$$1\$ 效果一样,都对
isee 发表于 2021-10-18 23:11

嗯,最后那个 $ 看来是多余。
不过,我发现 \$ $1 \$$ $1 $ 都是 OK 的,但如果去掉空格 \$$1\$$$1$ 就都不行,得再加一个美元变成 $$$1$,反斜杠似乎是多余的?$$$1$$ 也 OK,不是太懂。

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-2-27 09:42:22
简化版
  1. document.querySelectorAll('img[data-formula]').forEach((a)=>(a.alt='$'+a.dataset.formula+'$'))
Copy the Code

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2022-2-27 14:41:11
回复 43# hbghlyj

这种语法俺还不会

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2022-2-27 22:54:51
根据 43# 简化后,最新:
// ==UserScript==
// @name         zihu_ltx_cpy
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  for zihu ltx cpy
// @author       kk, hbghlyj
// @match        https://www.zhihu.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var mybutton,beasetag;
    mybutton = document.createElement("div");
    beasetag = document.querySelector("body");
    beasetag.appendChild(mybutton);
    mybutton.innerHTML = "$ 代码 $";
    mybutton.style = "position:fixed;bottom:30px;left:30px;width:100px;height:100px;background:black;opacity:0.5;color:white;text-align:center;line-height:100px;cursor:pointer;";
    mybutton.onclick = function(){
      document.querySelectorAll('img[data-formula]').forEach((a)=>(a.alt='$'+a.dataset.formula+'$'))
    };
})();
试了一下应该没问题

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-3-1 02:48:16
回复 44# kuing
提个小问题:
  1. \[...\]
Copy the Code
这样的公式会被加上$,变成
  1. $\[...\]$
Copy the Code

2

Threads

465

Posts

6357

Credits

Credits
6357
QQ

Show all posts

爪机专用 Posted at 2022-3-1 03:05:21
回复 45# hbghlyj

再加一句替换命令把它们弄掉?

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2022-3-4 18:38:11
回复 42# hbghlyj

模仿这种语法,改写“解决 TOP”的方法:
  1. document.querySelectorAll('a[onclick="scrollTo(0,0);"]').forEach((a)=>(a.href="#top"))
Copy the Code
是这样写对吧?

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-3-4 18:40:57
回复 47# kuing
好像可以直接在那个viewthreadnode模板里改吧

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2022-3-4 20:36:00
回复 48# hbghlyj

不想改模板

(a)=>(a.href="#top")() 是不是可以省略

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-3-4 21:23:05
回复 49# kuing
只是想...问下)为啥不改模板呢

801

Threads

4889

Posts

310K

Credits

Credits
36169

Show all posts

isee Posted at 2022-3-4 23:29:08
回复 50# hbghlyj


要尊重个性~哈哈哈哈哈~

801

Threads

4889

Posts

310K

Credits

Credits
36169

Show all posts

isee Posted at 2022-3-4 23:29:57
根据 43# 简化后,最新:
// ==UserScript==
// @name         zihu_ltx_cpy
// @namespace    http://tamp ...
kuing 发表于 2022-2-27 22:54
哪个效率高?

2

Threads

465

Posts

6357

Credits

Credits
6357
QQ

Show all posts

爪机专用 Posted at 2022-3-4 23:36:48
回复 52# isee

新的

2

Threads

465

Posts

6357

Credits

Credits
6357
QQ

Show all posts

爪机专用 Posted at 2022-3-4 23:43:15
回复 51# isee

不是个性的问题,模版是重要文件,当然是能不改就不改。

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2022-3-5 16:33:24
回复 55# hbghlyj

O,那还是用回 window.scrollTo(0,0); 好了。

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-3-6 11:08:12
回复 55# kuing
油猴脚本的userscripts.org/topics
捕获.PNG

2

Threads

465

Posts

6357

Credits

Credits
6357
QQ

Show all posts

爪机专用 Posted at 2022-3-6 13:05:15
回复 56# hbghlyj

这是啥?我点进去只看到一只喵在跳舞

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-3-6 19:36:15
回复 57# 爪机专用
引自en.wikipedia.org/wiki/Userscript:
Historically (circa 2005–2011) userscripts.org, created by American programmer Jesse Andrews, was the largest such repository for userscripts. Over time, the site was transitioned between various maintainers before it went offline completely in May 2014. All that remains is a mirror(userscripts-mirror.org/), which is useful for archival purposes.

10年前曾是最大的greasymonkey用户脚本存储库

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-3-26 06:34:02
回复 20# 青青子衿
可以的.它这个是服务器用KaTeX处理好的.
  1. document.querySelectorAll('.katex-display').forEach(a=>a.replaceWith('$$'+a.firstChild.firstChild.firstChild.firstChild.lastChild.innerHTML+'$$'))
  2. document.querySelectorAll('.katex').forEach(a=>a.replaceWith('$'+a.firstChild.firstChild.firstChild.lastChild.innerHTML+'$'))
Copy the Code

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2022-4-4 22:36:22
才知道油猴原来是可以设置脚本注入的时机的,详见:tampermonkey.net/documentation.php#_run_at

// @run-at context-menu 就可以在右键菜单看到相应选项,点击才注入,这样就不需要自己设置按钮了。

于是代码再次被大大简化为
  1. // ==UserScript==
  2. // @name         zihu_ltx_cpy_2
  3. // @version      0.1
  4. // @description  for zihu ltx cpy
  5. // @match        https://www.zhihu.com/*
  6. // @run-at context-menu
  7. // ==/UserScript==
  8. (function() {
  9.     'use strict';
  10. document.querySelectorAll('img[data-formula]').forEach((a)=>(a.alt='+a.dataset.formula+'));
  11. })();
Copy the Code
在知乎页面右键,就会多出油猴菜单:
QQ截图20220404224533.png
点它就相当于点之前设置的按钮。

手机版Mobile version|Leisure Math Forum

2025-4-20 22:22 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list