Forgot password?
 Register account
Author: kuing

记录一回写油猴

[Copy link]

682

Threads

110K

Posts

910K

Credits

Credits
90968
QQ

Show all posts

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

实际使用 发现 \$$$1\$$\$$$1\$ 效果一样,都对
isee 发表于 2021-10-18 23:11
嗯,最后那个 $ 看来是多余。
不过,我发现 \$ $1 \$$ $1 $ 都是 OK 的,但如果去掉空格 \$$1\$$$1$ 就都不行,得再加一个美元变成 $$$1$,反斜杠似乎是多余的?$$$1$$ 也 OK,不是太懂。

3157

Threads

7925

Posts

610K

Credits

Credits
64218
QQ

Show all posts

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

682

Threads

110K

Posts

910K

Credits

Credits
90968
QQ

Show all posts

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

这种语法俺还不会

682

Threads

110K

Posts

910K

Credits

Credits
90968
QQ

Show all posts

 Author| kuing Posted 2022-2-27 22:54
根据 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+'$'))
    };
})();
试了一下应该没问题

3157

Threads

7925

Posts

610K

Credits

Credits
64218
QQ

Show all posts

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

0

Threads

412

Posts

6093

Credits

Credits
6093
QQ

Show all posts

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

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

682

Threads

110K

Posts

910K

Credits

Credits
90968
QQ

Show all posts

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

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

3157

Threads

7925

Posts

610K

Credits

Credits
64218
QQ

Show all posts

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

682

Threads

110K

Posts

910K

Credits

Credits
90968
QQ

Show all posts

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

不想改模板

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

3157

Threads

7925

Posts

610K

Credits

Credits
64218
QQ

Show all posts

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

768

Threads

4685

Posts

310K

Credits

Credits
35004

Show all posts

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


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

768

Threads

4685

Posts

310K

Credits

Credits
35004

Show all posts

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

0

Threads

412

Posts

6093

Credits

Credits
6093
QQ

Show all posts

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

新的

0

Threads

412

Posts

6093

Credits

Credits
6093
QQ

Show all posts

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

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

682

Threads

110K

Posts

910K

Credits

Credits
90968
QQ

Show all posts

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

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

3157

Threads

7925

Posts

610K

Credits

Credits
64218
QQ

Show all posts

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

0

Threads

412

Posts

6093

Credits

Credits
6093
QQ

Show all posts

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

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

3157

Threads

7925

Posts

610K

Credits

Credits
64218
QQ

Show all posts

hbghlyj Posted 2022-3-6 19:36
回复 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用户脚本存储库

3157

Threads

7925

Posts

610K

Credits

Credits
64218
QQ

Show all posts

hbghlyj Posted 2022-3-26 06:34
回复 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

682

Threads

110K

Posts

910K

Credits

Credits
90968
QQ

Show all posts

 Author| kuing Posted 2022-4-4 22:36
才知道油猴原来是可以设置脚本注入的时机的,详见: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|Discuz Math Forum

2025-6-7 00:04 GMT+8

Powered by Discuz!

× Quick Reply To Top Edit