// ==UserScript== // @name 扇贝单词助手 // @namespace http://tampermonkey.net/ // @version 1.0.3 // @description 喝水不忘挖井人,本插件是在扇贝单词小助手基础上二次开发。 // @author q1982069904 // @match https://web.shanbay.com/wordsweb/* // @grant GM_info // @grant GM_setValue // @grant GM_getValue // @connect greasyfork.org // @grant GM_xmlhttpRequest // @grant GM_registerMenuCommand // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js // @require https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js // @require https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.1/index.min.js // @grant unsafeWindow // @license q1982069904 // @downloadURL https://update.greasyfork.icu/scripts/454444/%E6%89%87%E8%B4%9D%E5%8D%95%E8%AF%8D%E5%8A%A9%E6%89%8B.user.js // @updateURL https://update.greasyfork.icu/scripts/454444/%E6%89%87%E8%B4%9D%E5%8D%95%E8%AF%8D%E5%8A%A9%E6%89%8B.meta.js // ==/UserScript== (function() { // 定义变量 var flag; // 用于数字5切换词典 var flag2; // 用于柯林斯词典真题例句发音 //const version = 1.8; // 脚本当前版本 const version = GM_info.script.version; const updateURL = GM_info.script.homepage; // url const scriptname = GM_info.script.name; var tip; // 展开笔记标识 var xhflag = -1 //循环flag var xfisplay = false var xhmutationObserver $(document.head).append( ` ` ) // bootstrap按钮样式 $(document.head).append( `` ) // 设置字体大小 let util = { getValue(name) { return GM_getValue(name); }, setValue(name, value) { GM_setValue(name, value); }, }; let main = { /** * 配置默认值 */ initValue() { let value = [{ name: 'current_val', value: 15 }, { name: 'has_init', value: false }]; value.forEach((v) => { util.getValue(v.name) === undefined && util.setValue(v.name, v.value); }); }, registerMenuCommand() { GM_registerMenuCommand('字体大小设置', () => { vapp.showSetting(); }); }, init() { this.initValue(); this.registerMenuCommand(); } }; main.init(); // 显示托盘============================================== const html = `
扇贝单词助手 {{isleftbox ? '最小化' : '还原'}}
开启专注模式 关闭专注模式 {{theme == 'light' ? '白天' : '黑夜'}}模式 查看快捷键
加粗中文翻译 默认选择我的笔记 隐藏例句中的翻译 隐藏柯林斯词典中的中文 自动展开共享笔记
` // 显示翻译托盘============================================== const html2 = `
拼写句子助手 {{isrightbox ? '最小化' : '还原'}}
` const html3 = `
拖动滑块观察字体大小变化
保 存 还 原
`; const html4 = ` ` var node = $(`
`); node = node.html(html + html2 + html3 + html4); $('#root').append(node); var vapp vapp = new Vue({ el: "#app", data() { return { trans_result: [], keyDate: [ { tip: '认识、想起来了', key: 'J/1'}, { tip: '提示一下、没想起来、撤销', key: 'K/2'}, { tip: 'US发音', key: 'O/3'}, { tip: 'UK发音', key: 'I/4'}, { tip: '扇贝与柯林斯切换', key: 'U/5'}, { tip: '例句发音', key: 'T/6'}, { tip: '真题例句发音', key: 'G/7'}, { tip: '例句翻译显示与隐藏', key: 'H/8'}, { tip: '下一个', key: 'L/.'}, { tip: '隐藏展示柯林斯词典中的中/英文', key: 'V/0'}, { tip: '拼写模式下查看正确答案/继续', key: 'Enter'}, ], msg: '', textarea: '', theme: GM_getValue('theme') || 'light', isfullScreen: false, dialogSizeVisible: false, dialogKeyTipVisible: false, fontsize: 15, isopenNote: GM_getValue('isopenNote'), isCollins: GM_getValue('isCollins'), isCollinsFY: GM_getValue('isCollinsFY'), ishideFY: GM_getValue('ishideFY'), isblodFY: GM_getValue('isblodFY'), isMyNote: GM_getValue('isMyNote'), isleftbox: true, isrightbox: false, } }, mounted: function() { let _this = this // 全屏与退出全屏==================================================== // 根据浏览器可视区域高度与屏幕实际高度差值判断页面是否为全屏状态 // 取值17是为了处理页面内容出现滚动条的情况 var isFull = Math.abs(window.screen.height - window.document.documentElement.clientHeight) <= 17 window.onresize = function() { isFull = Math.abs(window.screen.height - window.document.documentElement.clientHeight) <= 17 } // 阻止F11键默认事件,用HTML5全屏API代替 window.addEventListener('keydown', function(e) { e = e || window.event if (e.keyCode == 122 && !isFull) { e.preventDefault() _this.enterFullScreen() document.addEventListener("webkitfullscreenchange", exitF, true); document.addEventListener("mozfullscreenchange", exitF, true); } }) function exitF() { if (!document.webkitIsFullScreen) { //退出全屏后执行的代码 $(".Nav_nav__3kyeO").show(); $(".Nav_container__sBZA1").show(); $(".SubNav_itemsWrapper__1mM4u").show(); _this.exitFullScreen() } } $('.twodiv > .el-card__body').css("display" , 'none') this.changeTheme() // =================================================================== }, methods: { leftbox: function() { $('.onediv > .el-card__body').toggle("slow") this.isleftbox = !this.isleftbox }, rightbox: function(){ $('.twodiv > .el-card__body').toggle("slow") this.isrightbox = !this.isrightbox }, // 打开浏览器全屏模式 enterFullScreen: function () { this.isfullScreen = true $(".Nav_nav__3kyeO").hide(); $(".Nav_container__sBZA1").hide(); $(".SubNav_itemsWrapper__1mM4u").hide(); this.$message({ message: '进入专注模式,更专注于背单词!', type: 'success' }); let el = document.documentElement let rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el .msRequestFullscreen if (rfs) { // typeof rfs != "undefined" && rfs rfs.call(el) } else if (typeof window.ActiveXObject !== 'undefined') { // for IE,这里其实就是模拟了按下键盘的F11,使浏览器全屏 let wscript = new ActiveXObject('WScript.Shell') if (wscript != null) { wscript.SendKeys('{F11}') } } }, // 退出全屏 exitFullScreen: function () { this.isfullScreen = false $(".Nav_nav__3kyeO").show(); $(".Nav_container__sBZA1").show(); $(".SubNav_itemsWrapper__1mM4u").show(); this.$message({ message: '退出专注模式,不要被外界干扰哟!建议开启专注模式!', type: 'warning' }); let el = document let cfs = el.cancelFullScreen || el.mozCancelFullScreen || el.msExitFullscreen || el.webkitExitFullscreen || el.exitFullscreen if (cfs) { // typeof cfs != "undefined" && cfs cfs.call(el) } else if (typeof window.ActiveXObject !== 'undefined') { // for IE,这里和fullScreen相同,模拟按下F11键退出全屏 let wscript = new ActiveXObject('WScript.Shell') if (wscript != null) { wscript.SendKeys('{F11}') } } }, //切换主题 btnTheme: function (){ this.theme = this.theme == "light" ? 'dark' : 'light' GM_setValue('theme', this.theme) this.changeTheme(this.theme) this.$message({ message: this.theme == 'dark' ? '切换黑夜': '切换白天', type: 'success' }); }, //切换主题 changeTheme: function (){ if (this.theme == "light") { const style = document.createElement("style"); style.id = "theme-css-dark"; // 加上id方便后面好查找到进行删除 style.innerHTML = `html{filter: invert(100%) hue-rotate(180deg);scrollbar-width: none;} ::-webkit-scrollbar{display:none} img,video {filter: invert(100%) hue-rotate(180deg);}`; document.querySelector("head").appendChild(style); } else { document.querySelector("#theme-css-dark").remove(); } }, showSetting: function() { this.dialogSizeVisible = true }, changefont: function(e){ }, setValue: function(name, e){ GM_setValue(name, e); this.$message({ message: '操作成功', type: 'success' }); }, // 取消多行文本框的回车 textareaKeydown:function (e) { e.stopPropagation(); return false; }, } }) // 键盘监听======== $(document).keydown(function(event, repeat) { if (repeat) return // 数字键3,o ,US发音 if (event.keyCode == 99 || event.keyCode == 51 || event.keyCode == 79) { $(".index_trump__3bTaM:last").click() $(".Pronounce_audio__3xdMh:last").click() } // 数字键4,i,UK发音 if (event.keyCode == 100 || event.keyCode == 52 || event.keyCode == 73) { $(".index_trump__3bTaM:first").click() $(".Pronounce_audio__3xdMh:first").click() } // 数字5,u,用于切换扇贝单词与柯林斯词典 if (event.keyCode == 101 || event.keyCode == 53 || event.keyCode == 85) { var msg = $(".index_tab__37Cha.index_active__1bHoy").html() if (msg == $(".index_tabNavs__3tWev:eq(0) > p:eq(0)").html()) { flag = true; } else { flag = false; } if (!flag) { $(".index_tabNavs__3tWev:eq(0) > p:eq(0)").click() flag = !flag; // console.log($(".index_tab__37Cha").html()) // $(".index_tab__37Cha").trigger("click"); } else { // console.log($(".index_tab__37Cha.index_active__1bHoy").html()) // $(".index_tab__37Cha.index_active__1bHoy").trigger("click"); $(".index_tabNavs__3tWev:eq(0) > p:eq(1)").click() flag = !flag; } } // 数字键盘6,f,例句发音,将f键改为t键(f键与扇贝原有的快捷键冲突) if (event.keyCode == 102 || event.keyCode == 54 || event.keyCode == 84) { $(".index_icon__1IK2K").click() } // 数字键盘7,,g,真题例句发音 if (event.keyCode == 103 || event.keyCode == 55 || event.keyCode == 71) { $(".index_audio__1mSVg:first > img").click() } // 数字键盘8,h,例句翻译显示与隐藏 if (event.keyCode == 104 || event.keyCode == 56 || event.keyCode == 72) { $(".btn.btn-primary.btn-xs").next().toggle() } // 数字键盘0,v,隐藏展示柯林斯词典中的英文 if (event.keyCode == 96 || event.keyCode == 48 || event.keyCode == 86) { if (GM_getValue('check5') == 1) { // $(".CollinsTrans_senseEn__17oYf").toggle() $(".btn.btn-link.btn-xs").prev().prev().toggle() } else if (GM_getValue('check5') == 2) { // $(".CollinsTrans_senseEn__17oYf").next().toggle() $(".btn.btn-link.btn-xs").prev().toggle() } } // 键盘k,相当于2 if (event.keyCode == 75) { // console.log("k按下") $(".index_option__1CVr2.index_red__VSPTN").click() // 撤销 // $(".Message_message__w-TNe.alert.middle > div > span").click() } // 键盘j,相当于1 if (event.keyCode == 74) { // console.log("j按下") $(".index_option__1CVr2.index_green__2lFgU").click() } // 键盘L if (event.keyCode == 76) { // console.log("l按下") $(".StudyPage_nextBtn__1ygGn").click() } // 键盘回车 拼写模式下点击查看正确答案,继续 if (event.keyCode == 13) { // console.log("enter弹起") // console.log($(".index_tenseAnswer__2o47S").length) if ($(".index_tenseAnswer__2o47S").length != 0) { $(".index_tenseAnswer__2o47S").click() } else { $(".index_continueBtn__34NqT").click() } } }); // $("#oneinput").attr("checked", GM_getValue('check')); // $("#oneinput").click(() => { // GM_setValue('check', $("#oneinput").is(':checked')); // }) $("#twoinput").attr("checked", GM_getValue('check2')); $("#twoinput").click(() => { GM_setValue('check2', $("#twoinput").is(':checked')); }) $("#threeinput").attr("checked", GM_getValue('check3')); $("#threeinput").click(() => { GM_setValue('check3', $("#threeinput").is(':checked')); }) $("#fourinput").attr("checked", GM_getValue('check4')); // selectksl $(`input[name='selectksl'][value=${GM_getValue('check5')}]`).attr("checked", true); $("input[name='selectksl']").click((params) => { // console.log($("input[name='selectksl']:checked").val()) GM_setValue('check5', $("input[name='selectksl']:checked").val()); }) // ========================================================== // 两个定时器============================================ var t = setInterval(() => { //index_button__9uno8 if ($(".index_button__9uno8 > span").html() == '开始学习' || $(".index_button__9uno8 > span").html() == '继续学习') { clearInterval(t) $(".index_button__9uno8").click(() => { enterFullScreen() }) } }, 800) var t3 = setInterval(() => { if ($(".StudyDone_checkinBtn__3DuXc").html() == '打卡') { clearInterval(t3) $(".StudyDone_checkinBtn__3DuXc").click(() => { exitFullScreen() }) } }, 1000) // 展开共享笔记函数 function show_note(tip) { if (tip != undefined && tip.indexOf("展开") > -1) { // console.log("123") $(".index_unfold__3BwCB > span").click() return } else { tip = $(".index_unfold__3BwCB > span").html() // setTimeout(()=>{ show_note(tip) // },100) } } // 用于实时监听DOM================================ function addBr() { let mutationObserver = new MutationObserver(function(mutations) { xhmutationObserver && xhmutationObserver.disconnect() console.log(mutations); // mutations.forEach(function(mutation) { // $(".index_icon__1IK2K").after("
数字键6发音
") // $(".index_audio__1mSVg:first").after("
数字键7发音
") // $(".index_trump__3bTaM:first").after("
数字键4:UK发音
") // $(".Pronounce_audio__3xdMh:first").after("
数字键4:UK发音
") // $(".index_trump__3bTaM:last").after("
数字键3:US发音
") // $(".Pronounce_audio__3xdMh:last").after("
数字键3:US发音
") //复读机 var btn = $("#btnRefresh") btn.addClass("btnRefresh") $("img[alt=trumpet]").after((index)=>{ return `` }) $('.btnRefresh').on('click', (e)=> { let currentIndex = -1 xhmutationObserver && xhmutationObserver.disconnect() var target = $(e.currentTarget); var trumpet = target.parent().find("img[alt=trumpet]") $('.btnRefresh i').removeClass("xz") if(xhflag == target.data('index')) { xhflag = -1 return } trumpet.click() currentIndex = xhflag = target.data('index') target.find("i").addClass("xz") xhmutationObserver = new MutationObserver(function(mutations) { if(mutations[0].target.src.indexOf("iVBORw0KGgoAAAA") != -1) { currentIndex == xhflag && setTimeout(()=>{trumpet.click()}, 3000) } }); xhmutationObserver.observe(trumpet.get(0), { attributes: true // subtree: true }); }) $(".index_exampleEN__3OIEA, .index_sentenceEn__1Qjgx").after( "" ) $(".index_exampleEN__3OIEA").after("") // 隐藏例句中的中文 $(".optionFY").click((event) => { var $target = $(event.target); $target.next().toggle() }) if (GM_getValue('ishideFY')) { $(".optionFY").click() } $(".pingxie").click((event) => { var $target = $(event.target); $target.prev().toggle() if($target.next().next().css("display") == 'none') { $target.next().click() } vapp.rightbox() }) //柯林斯词典 $(".CollinsTrans_paraphraseList__3SZ3y > li > span:nth-child(3),.StudySummaryItem_content__3j9YG > div > div >span:nth-child(3)") .after( "  " ) $(".isCollinsFY").click((event) => { // 取消冒泡事件 if (event.stopPropagation()) { event.stopPropagation() } else { event.cancelBubble = true // 兼容ie浏览器 } var $target = $(event.target); $target.prev().toggle() }) if (GM_getValue('isCollinsFY')) { $(".isCollinsFY").click() } $( ".BayTrans_paraphrase__2JMIz > p" ).css({ "font-size": `inherit`, }) // 加粗解释 if(GM_getValue('isblodFY')) { $(".StudySummaryItem_content__3j9YG > div > div >span:nth-child(3),.BayTrans_paraphrase__2JMIz,.CollinsTrans_pos__3szum,.CollinsTrans_paraphraseList__3SZ3y > li > span:nth-child(3),.index_name__1gkfJ").css({ "font-weight": "bold", }) // 扇贝单词添加序号 var ptotal = $(".BayTrans_paraphrase__2JMIz > p") // console.log(ptotal) let index = 1 for (let s of ptotal) { // console.log("s",$(s)) $(s).children().first().before("" + index + ". ") // s.before("" + var1 + ".") index++ } ptotal.css({ "margin-top": "6px" }) } // $(".CollinsTrans_senseEn__17oYf").after("
") // $(".CollinsTrans_senseEn__17oYf").hide() // $(".CollinsTrans_paraphraseList__3SZ3y > li > span:nth-child(3)").after($(".CollinsTrans_senseEn__17oYf").html()) // 隐藏柯林斯词典中的英文 // if (GM_getValue('check')) { // $(".CollinsTrans_senseEn__17oYf").hide() // } // 隐藏柯林斯词典中的英文,中文 let getDiv = $(".StudySummaryItem_content__3j9YG > div > div"); if (GM_getValue('check5') == 1) { $(".CollinsTrans_senseEn__17oYf").hide() $(".StudySummaryItem_content__3j9YG > div > div >span:nth-child(2)").hide() } else if (GM_getValue('check5') == 2) { $(".CollinsTrans_senseEn__17oYf").next().hide() $(".StudySummaryItem_content__3j9YG > div > div >span:nth-child(3)").hide() } // 柯林斯词典例句自动发音 if (GM_getValue('isCollins')) { var msg2 = $(".index_tab__37Cha.index_active__1bHoy").html() if (msg2 == $(".index_tabNavs__3tWev:eq(0) > p:eq(1)").html()) { flag2 = true; } else { flag2 = false; } if (flag2) { $(".index_audio__1mSVg:first > img").click() } } // 如果智慧词根过期提示,直接关闭 $(".AppletTip_close__2lEIB").click() // 展开笔记 function listenOne(tip) { let mutationObserver = new MutationObserver(function(mutations) { show_note(tip) }); mutationObserver.observe($('.span12.block-center > div > div:last > div:last').get(0), { childList: true // subtree: true }); } if (GM_getValue('isopenNote')) { tip = $(".index_unfold__3BwCB > span").html() try { listenOne(tip) } catch (e) {} } // }); }); // mutationObserver.observe($('.span12.block-center').get(0), { mutationObserver.observe($('.StudyPage_studyPage__1Ri5C > div').get(0), { childList: true // subtree: true }); // mutationObserver.disconnect() } try { listenOne() } catch (e) { //TODO handle the exception } // 用于实时监听DOM,用这个监听器,去调用另一个监听器 function listenOne() { let mutationObserver = new MutationObserver(function(mutations) { // mutations.forEach(function(mutation) { // clearInterval(show_note_time) // 另一个监听器 try { addBr() } catch (e) { //TODO handle the exception } // $(".index_trump__3bTaM:first").after("
数字键4:UK发音
") // $(".index_trump__3bTaM:last").after("
数字键3:US发音
") // clearInterval(show_note_time) // }); }); mutationObserver.observe($('.Layout_main__2_zw8').get(0), { childList: true // subtree: true }); } function _click_hide_show(event) { var $target = $(event.target); // console.log($target) } //update() // upate function update() { GM_xmlhttpRequest({ url: updateURL, method: "get", headers: { 'Content-type': 'application/x-www-form-urlencoded', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4484.7 Safari/537.36' }, onload: function(data) { // console.log(data) const newversion = $(data.response).find('.install-link').attr("data-script-version"); // console.log(data.status) if (data.status == 200) { if (version != newversion) { Swal.fire({ icon: 'info', title: '检测到新版本', allowOutsideClick: false, allowEscapeKey: false, html: `当前《${scriptname}》不是最新版本
当前版本:${version}

最新版本:${newversion}

更新日志请查看:更新日志与使用说明

`, footer: "保持最新版本,更好的体验", confirmButtonText: '更新' }).then((result) => { if (result.value) { window.open("https://greasyfork.org/" + $(data.response).find( '.install-link').attr("href"), "_self"); setTimeout(() => { Swal.fire({ icon: 'success', title: '提示', allowOutsideClick: false, allowEscapeKey: false, html: "更新后,请点击刷新", footer: "点击刷新,加载最新版本", confirmButtonText: '刷新' }).then((result) => { if (result.value) { // GM_openInTab("https://greasyfork.org/"+$(data.response).find('.install-link').attr("href"),{active: true}); window.location.reload(); } }); }, 500) } }); } } else { console.log("网络错误,错误码:" + data.status) } }, }); } })();