NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name 知乎复制公式到word // @namespace http://*.zhihu.com // @version 0.1 // @description 知乎复制公式,点按钮,手动选中复制,word右键粘贴只保留文本,Axmath公式转换,将latex代码转换为axmath公式 // @author mikecoding // @match https://*.zhihu.com/* // @copyright 2021, mikecoding (https://openuserjs.org/users/mikecoding) // @require http://code.jquery.com/jquery-1.11.0.min.js // @license MIT // @grant none // ==/UserScript== (function () { 'use strict'; jQuery.fn.wait = function (selector, func, times, interval) { var _times = times || -1, //100次 _interval = interval || 20, //20毫秒每次 _self = this, _selector = selector, //选择器 _iIntervalID; //定时器id if (this.length) { //如果已经获取到了,就直接执行函数 func && func.call(this); } else { _iIntervalID = setInterval(function () { if (!_times) { //是0就退出 clearInterval(_iIntervalID); } _times <= 0 || _times--; //如果是正数就 -- _self = $(_selector); //再次选择 if (_self.length) { //判断是否取到 func && func.call(_self); clearInterval(_iIntervalID); } }, _interval); } return this; } $(".Post-Header").wait(".Post-Header", function () { $('<a href="javascript:;" class="copytax Button Button--blue"> 复制公式</a>').appendTo($("div[class^='CornerAnimayedFlex']")); $(".copytax").click(function () { console.log("运行成功"); for (var i = 0; i < document.getElementsByTagName("img").length; i++) { if (document.getElementsByTagName("img")[i].hasAttribute("data-formula")) { document.getElementsByTagName("img")[i].setAttribute("alt", "$$" + document.getElementsByTagName("img")[i].getAttribute("data-formula") + "$$") } } }); }) $(".QuestionPage").wait(".QuestionPage", function () { console.log("加载成功"); $('<a href="javascript:;" class="copytax Button--blue">公式</a>').appendTo($("div[class^='QuestionButtonGroup']")); $(".copytax").click(function () { console.log("运行成功"); for (var i = 0; i < document.getElementsByTagName("img").length; i++) { if (document.getElementsByTagName("img")[i].hasAttribute("data-formula")) { document.getElementsByTagName("img")[i].setAttribute("alt", "$$" + document.getElementsByTagName("img")[i].getAttribute("data-formula") + "$$") } } }); }) })();