ar5iv油猴脚本备份 发表于 2024-08-06 | 更新于 2025-03-30
| 阅读量:
因为ar5iv是自适应系统主题的,但我希望看论文始终使用light
主题而不是跟随系统设置,因此就通过JavaScript做一些后处理。之前一直用tampermonkey
,中文叫篡改猴,也就是所谓的油猴插件去对网页做一些后处理。
但7月31日的时候发现不能用了,一开始还以为是ar5iv更新了,但F12找了发现原来的代码能用没问题。后来在控制台发现:Uncaught ReferenceError: MutationEvent is not defined
,然后什么油猴脚本都用不了,才发现是油猴的问题。经Google查找到:Uncaught
ReferenceError: MutationEvent is not
defined ,说是要启用chrome://flags/#mutation-events
才行。但那是几个月前的问题了,应该有更加好的修复方式。
后面又看到: Throw
error "Uncaught DOMException: Failed to execute 'createEvent' on
'Document': The provided event type ('MutationEvent') is invalid." in
tampermonkey in
content.js ,解决方案是更新一下脚本到5.1.1或之后的版本。
这个倒是可以接受,但我没找到直接更新的选项,然后点了移除再装的新版。点了之后我就后悔了,果然一上去之前写的ar5iv脚本没了。但好歹是把新版装上了,而且运行脚本也确实没啥问题了。
为了防止之后继续丢失ar5iv的后处理脚本,在这里做一下简单备份。
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 function skip_translate (elements ) { for (let i=0 ;i<elements.length ;i++){ elements[i].setAttribute ('translate' ,'no' ) } } (function ( ) { 'use strict' ; let k = document .querySelector ("html" ); k.setAttribute ('data-theme' , 'light' ); let equations = document .getElementsByClassName ('ltx_equation' ) skip_translate (equations); let bibLinks = document .querySelectorAll ('a[href^="#bib"]' ); skip_translate (bibLinks); let math_blocks = document .getElementsByClassName ('ltx_Math' ) skip_translate (math_blocks); let biblist = document .getElementsByClassName ('ltx_biblist' ) skip_translate (biblist); const observer = new MutationObserver ((mutationsList, observer ) => { for (let mutation of mutationsList) { if (mutation.type === 'childList' ) { for (let node of mutation.addedNodes ) { if (node.nodeType === 1 && node.classList .contains ('ar5iv-bibitem-preview' )) { console .log ('Found new element with class "ar5iv-bibitem-preview":' , node); node.setAttribute ('translate' ,'no' ) } } } } }); const config = { childList : true , subtree : true }; const targetNode = document .body ; observer.observe (targetNode, config); })();
主要有以下几个增强功能: 1. 强制主题为亮色主题 2. 避开公式翻译 3.
避开参考文献翻译 4. 避开弹出的参考文献预览窗口的翻译