锋宝宝

记录工作中的一些笔记以及一些有趣的代码,致力于成为一个优秀的程序员
引用到评论
随便逛逛博客分类文章标签
复制地址关闭热评深色模式轉為繁體
navigator.clipboard.readText().then(clipText => rm.insertAtCaret(globalEvent.target, clipText)); } }; // 粘贴文本到焦点 rm.insertAtCaret = function (elemt, value) { const startPos = elemt.selectionStart, endPos = elemt.selectionEnd; if (document.selection) { elemt.focus(); var sel = document.selection.createRange(); sel.text = value; elemt.focus(); } else { if (startPos || startPos == "0") { var scrollTop = elemt.scrollTop; elemt.value = elemt.value.substring(0, startPos) + value + elemt.value.substring(endPos, elemt.value.length); elemt.focus(); elemt.selectionStart = startPos + value.length; elemt.selectionEnd = startPos + value.length; elemt.scrollTop = scrollTop; } else { elemt.value += value; elemt.focus(); } } }; //粘贴文本 rm.pasteText = function () { const result = rm.readClipboard() || ""; rm.hideRightMenu(); }; //引用到评论 rm.rightMenuCommentText = function (txt) { rm.hideRightMenu(); const postCommentDom = document.getElementById("post-comment"); var domTop = postCommentDom.offsetTop; window.scrollTo(0, domTop - 80); if (txt == "undefined" || txt == "null") txt = "好棒!"; function setText() { setTimeout(() => { var input = document.getElementsByClassName("el-textarea__inner")[0]; if (!input) setText(); let evt = document.createEvent("HTMLEvents"); evt.initEvent("input", true, true); let inputValue = replaceAll(txt, "\n", "\n> "); input.value = "> " + inputValue + "\n\n"; input.dispatchEvent(evt); input.focus(); input.setSelectionRange(-1, -1); if (document.getElementById("comment-tips")) { document.getElementById("comment-tips").classList.add("show"); } }, 100); } setText(); }; //替换所有内容 function replaceAll(string, search, replace) { return string.split(search).join(replace); } // 百度搜索 rm.searchBaidu = function () { anzhiyu.snackbarShow("即将跳转到百度搜索", false, 2000); setTimeout(function () { window.open("https://www.baidu.com/s?wd=" + selectTextNow); }, "2000"); rm.hideRightMenu(); }; //分享链接 rm.copyLink = function () { rm.rightmenuCopyText(domhref); anzhiyu.snackbarShow("已复制链接地址"); }; function addRightMenuClickEvent() { // 添加点击事件 document.getElementById("menu-backward").addEventListener("click", function () { window.history.back(); rm.hideRightMenu(); }); document.getElementById("menu-forward").addEventListener("click", function () { window.history.forward(); rm.hideRightMenu(); }); document.getElementById("menu-refresh").addEventListener("click", function () { window.location.reload(); }); document.getElementById("menu-top").addEventListener("click", function () { anzhiyu.scrollToDest(0, 500); rm.hideRightMenu(); }); const menuLinks = document.querySelectorAll(".menu-link"); menuLinks.forEach(function (link) { link.addEventListener("click", rm.hideRightMenu); }); document.getElementById("menu-darkmode").addEventListener("click", anzhiyu.switchDarkMode); document.getElementById("menu-home") && document.getElementById("menu-home").addEventListener("click", function () { window.location.href = window.location.origin; }); document.getElementById("menu-randomPost").addEventListener("click", function () { toRandomPost(); }); document.getElementById("menu-commentBarrage").addEventListener("click", anzhiyu.switchCommentBarrage); document.getElementById("rightmenu-mask").addEventListener("click", rm.hideRightMenu); document.getElementById("rightmenu-mask").addEventListener("contextmenu", function (event) { rm.hideRightMenu(); event.preventDefault(); // Prevent the default context menu from appearing }); document.getElementById("menu-copy").addEventListener("click", rm.copyPageUrl); document.getElementById("menu-pastetext").addEventListener("click", rm.pasteText); document.getElementById("menu-copytext").addEventListener("click", function () { rm.rightmenuCopyText(selectTextNow); anzhiyu.snackbarShow("复制成功,复制和转载请标注本文地址"); }); document.getElementById("menu-commenttext").addEventListener("click", function () { rm.rightMenuCommentText(selectTextNow); }); document.getElementById("menu-newwindow").addEventListener("click", function () { window.open(domhref, "_blank"); rm.hideRightMenu(); }); document.getElementById("menu-copylink").addEventListener("click", rm.copyLink); document.getElementById("menu-downloadimg").addEventListener("click", function () { anzhiyu.downloadImage(domImgSrc, "anzhiyu"); }); document.getElementById("menu-newwindowimg").addEventListener("click", function () { window.open(domImgSrc, "_blank"); rm.hideRightMenu(); }); document.getElementById("menu-copyimg").addEventListener("click", function () { rm.writeClipImg(domImgSrc); }); document.getElementById("menu-searchBaidu").addEventListener("click", rm.searchBaidu); //音乐 document.getElementById("menu-music-toggle").addEventListener("click", anzhiyu.musicToggle); document.getElementById("menu-music-back").addEventListener("click", anzhiyu.musicSkipBack); document.getElementById("menu-music-forward").addEventListener("click", anzhiyu.musicSkipForward); document.getElementById("menu-music-copyMusicName").addEventListener("click", function () { rm.rightmenuCopyText(anzhiyu.musicGetName()); anzhiyu.snackbarShow("复制歌曲名称成功", false, 3000); }); } addRightMenuClickEvent();