// ==UserScript==
// @name 扇贝单词增强
// @name:en Shanbay Enhance
// @description 扇贝单词功能增强,带来更好的背单词体验。❤单词总结释义遮挡❤隐藏例句翻译❤自定义单词例句字体❤自定义功能快捷键❤专注模式/深色模式
// @description:en More function for Shanbay.
// @version 0.1.9
// @author ZiuChen
// @namespace https://greasyfork.org/zh-CN/users/605474
// @icon https://fastly.jsdelivr.net/gh/ZiuChen/ZiuChen@main/avatar.jpg
// @source https://github.com/ZiuChen/Shanbay-Enhance.git
// @supportURL https://github.com/ZiuChen/Shanbay-Enhance.git
// @match https://www.shanbay.com/*
// @match https://web.shanbay.com/wordsweb/*
// @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js
// @require https://cdn.bootcdn.net/ajax/libs/toastr.js/latest/js/toastr.min.js
// @license MIT
// @downloadURL https://update.greasyfork.icu/scripts/437942/%E6%89%87%E8%B4%9D%E5%8D%95%E8%AF%8D%E5%A2%9E%E5%BC%BA.user.js
// @updateURL https://update.greasyfork.icu/scripts/437942/%E6%89%87%E8%B4%9D%E5%8D%95%E8%AF%8D%E5%A2%9E%E5%BC%BA.meta.js
// ==/UserScript==
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./package.json":
/***/ ((module) => {
module.exports = JSON.parse('{"name":"shanbay-enhance","version":"0.1.9","description":"More function for Shanbay.","main":"userscript.js","scripts":{"dev":"webpack --mode development --config config/webpack.config.dev.js","build":"webpack --mode production --config config/webpack.config.prod.js"},"repository":{"type":"git","url":"https://github.com/ZiuChen/Shanbay-Enhance.git"},"author":"ZiuChen","license":"MIT","bugs":{"url":"https://github.com/ZiuChen/Shanbay-Enhance/issues"},"homepage":"https://github.com/ZiuChen/Shanbay-Enhance#readme","devDependencies":{"@babel/core":"^7.16.7","babel-loader":"^8.2.3","userscript-metadata-webpack-plugin":"^0.1.1","webpack":"^5.65.0","webpack-cli":"^4.9.1","webpack-livereload-plugin":"^3.0.2","webpack-merge":"^5.8.0"},"dependencies":{}}');
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
;// CONCATENATED MODULE: ./src/style/CommonStyle.js
const style =
/* CSS */
`
/* switch */
.switch {
position: relative;
display: inline-block;
width: 50px;
height: 34px;
}
.switch input {display:none;}
.slider {
position: absolute;
cursor: pointer;
height: 25px;
width: 45px;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 19px;
width: 19px;
left: 3px;
bottom: 3px;
background-color: white;
-webkit-transition: .3s;
transition: .3s;
}
input:checked + .slider {
background-color: #209e85;
}
input:focus + .slider {
box-shadow: 0 0 1px #209e85;
}
input:checked + .slider:before {
-webkit-transform: translateX(20px);
-ms-transform: translateX(20px);
transform: translateX(20px);
}
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
/* toastr position */
.toastr-center {
top: 50%;
left: 50%;
margin-top: -30px;
margin-left: -150px;
}
/* config input text */
input[type=text] {
width: 220px;
border: 1px solid #ccc;
background-color: #fff;
height: 30px;
margin-top: 4px;
line-height: 30px;
}
input[id=config-fonts-choice-tmp] {
margin-left: 10px;
}
input[id=config-fonts-selector] {
width: 450px;
}
button[class~=short-keys] {
height: 25px;
padding-right: 5px;
padding-left: 5px;
margin-top: 5px;
margin-right: 10px;
cursor: pointer;
border: 1px solid #ccc;
}
button:focus {
background-color: #ccc;
}
button[class~=settingbutton] {
height: 25px;
padding-right: 5px;
padding-left: 5px;
margin-top: 5px;
margin-right: 20px;
cursor: pointer;
border: 1px solid #ccc;
}
.short-keys-wrap {
width: 1000px;
}
/* hide translation */
.hideTrans {
color: #cccccc;
background-color: #cccccc;
}
.removeTrans {
display: none;
}
.showTrans {
color: black;
background-color: ;
}
`;
/* harmony default export */ const CommonStyle = (style);
;// CONCATENATED MODULE: ./src/common/LoadUrl.js
function LoadUrl() {
const cssUrl = [{
name: `toastr`,
url: `https://cdn.bootcdn.net/ajax/libs/toastr.js/latest/toastr.min.css`
}];
cssUrl.forEach(item => {
$("head").append(``);
});
$("head").append(``);
selectors.forEach(selector => {
if (selector.enable === false) return;
$(selector.selector).addClass("fontToggle");
});
}
/* harmony default export */ const FontToggle = (fontToggle);
;// CONCATENATED MODULE: ./src/function/NoteRemove.js
function noteRemove() {
if (localStorage.getItem("config-note-remove") === "false") return;
$(`h6:contains("笔记")`).parent().parent().hide();
}
/* harmony default export */ const NoteRemove = (noteRemove);
;// CONCATENATED MODULE: ./src/function/HideTranslation.js
function hideTranslation() {
if (localStorage.getItem("config-example-hide") === "不隐藏") return;
let en = $(".index_sentenceEn__1Qjgx"); // real question
let cn = $(".index_sentenceCn__XJD1u");
let example = $(".index_left__2LkyW p");
if (localStorage.getItem("config-example-hide") === "隐藏并移除") {
for (let i = 0; i < $(".index_sentenceEn__1Qjgx").length; i++) {
$(en[i]).attr("title", $(cn[i]).text());
$(en[i]).css("cursor", "pointer");
$(en[i]).click(() => {
$(cn[i]).toggleClass("removeTrans");
});
}
$(example[0]).attr("title", $(example[1]).text());
$(example[0]).css("cursor", "pointer");
$(example[0]).click(() => {
$(example[1]).toggleClass("removeTrans");
});
$($(".index_left__2LkyW p")[1]).toggleClass("removeTrans");
$(".index_sentenceCn__XJD1u").toggleClass("removeTrans");
}
if (localStorage.getItem("config-example-hide") === "隐藏并占位") {
for (let i = 0; i < $(".index_sentenceEn__1Qjgx").length; i++) {
$(cn[i]).toggleClass("hideTrans");
$(cn[i]).mouseenter(e => {
$(e.target).toggleClass("hideTrans");
});
$(cn[i]).mouseleave(e => {
$(e.target).toggleClass("hideTrans");
});
}
$(example[1]).toggleClass("hideTrans");
$(example[1]).mouseenter(e => {
$(e.target).toggleClass("hideTrans");
});
$(example[1]).mouseleave(e => {
$(e.target).toggleClass("hideTrans");
});
}
}
/* harmony default export */ const HideTranslation = (hideTranslation);
;// CONCATENATED MODULE: ./src/function/KeyDownFunctions.js
function wordPronunceUS() {
// US
$(".index_trump__3bTaM:last").click();
$(".Pronounce_audio__3xdMh:last").click();
}
function wordPronunceUK() {
// UK
$(".index_trump__3bTaM:first").click();
$(".Pronounce_audio__3xdMh:first").click();
}
function examplePronunce() {
$(".index_icon__1IK2K").click();
}
function examplePronunceRealQuestion() {
$(".index_audio__1mSVg:first > img").click();
}
function summaryToggle() {
$(".slider").trigger("click");
}
function collinsToggle() {
if ($(".index_tab__37Cha.index_active__1bHoy").html() === "扇贝单词") {
// to Collins Dictionary
$(".index_tabNavs__3tWev:eq(0) > p:eq(1)").click();
} else if ($(".index_tab__37Cha.index_active__1bHoy").html() === "柯林斯词典") {
// to Shanbay Dictionary
$(".index_tabNavs__3tWev:eq(0) > p:eq(0)").click();
}
}
function toggleExample() {
// hide and remove
if (localStorage.getItem("config-example-hide") === "隐藏并移除") {
$($(".index_left__2LkyW p")[1]).toggleClass("removeTrans");
$(".index_sentenceCn__XJD1u").toggleClass("removeTrans");
} // hide and reserved
if (localStorage.getItem("config-example-hide") === "隐藏并占位") {
$($(".index_left__2LkyW p")[1]).toggleClass("hideTrans");
$(".index_sentenceCn__XJD1u").toggleClass("hideTrans");
}
}
/* harmony default export */ const KeyDownFunctions = ({
"word-pronunce-uk": wordPronunceUK,
"word-pronunce-us": wordPronunceUS,
"example-pronunce": examplePronunce,
"example-pronunce-real-question": examplePronunceRealQuestion,
"summary-toggle": summaryToggle,
"collins-toggle": collinsToggle,
"toggle-example": toggleExample
});
;// CONCATENATED MODULE: ./src/common/KeyDownObserver.js
function executeFuntions(keyCode, type) {
if (localStorage.getItem("config-shortkey") === "false") return;
let shortcutKeys = JSON.parse(localStorage.getItem("config-shortkey-keycode"));
shortcutKeys.forEach(config => {
if (config.id.indexOf(type) !== -1) {
config.keyCodes.forEach(code => {
if (code === keyCode) {
KeyDownFunctions[type]();
return;
} else return;
});
}
});
}
function keyDownObserver() {
$(document).off("keydown"); // Unbind all events first
$(document).on("keydown", e => {
executeFuntions(e.keyCode, "word-pronunce-uk");
executeFuntions(e.keyCode, "word-pronunce-us");
executeFuntions(e.keyCode, "example-pronunce");
executeFuntions(e.keyCode, "example-pronunce-real-question");
executeFuntions(e.keyCode, "summary-toggle");
executeFuntions(e.keyCode, "collins-toggle");
executeFuntions(e.keyCode, "toggle-example");
});
}
/* harmony default export */ const KeyDownObserver = (keyDownObserver);
;// CONCATENATED MODULE: ./src/function/SlipPronunce.js
function slipPronunce() {
if (localStorage.getItem("config-silp-pronunce") === "false") return;
let tds = $(".StudySummaryItem_studySummaryItem__k2ME0");
tds.each(index => {
let item = $(tds[index]);
let sound = item.find(".StudySummaryItem_sound__htCqt img");
item.on("mouseenter", () => {
sound.trigger("click");
});
});
}
/* harmony default export */ const SlipPronunce = (slipPronunce);
;// CONCATENATED MODULE: ./src/common/Observer.js
const commonConditions = ["study-page", "index_hint", "StudyPage_nextBtn", "StudySummary"];
function Observer() {
const OuterTargetNode = document.getElementsByClassName("Layout_main__2_zw8")[0];
if (typeof OuterTargetNode === "undefined") return;
const OuterCallback = mutations => {
mutations.forEach(mutation => {
if (mutation.addedNodes.length === 0 || mutation.addedNodes[0].className === undefined) return;
let currentState = mutation.addedNodes[0].className;
if (currentState.indexOf("SettingContainer_setting") !== -1) {
LoadConfig();
FocusMode();
}
if (currentState.indexOf("row") !== -1) {
NoteRemove();
HideTranslation();
}
if (currentState.indexOf("StudySummary") !== -1) {
SummaryTranslation.hideSummaryTranslation();
SlipPronunce();
}
if (currentState.indexOf("study-page") !== -1) {
KeyDownObserver();
}
commonConditions.forEach(condition => {
if (currentState.indexOf(condition) !== -1) {
FontToggle();
FocusMode();
}
});
if (mutation.addedNodes[0].childNodes.length === 0 || mutation.addedNodes[0].childNodes[0].className === undefined) return;
if (mutation.addedNodes[0].childNodes[0].className.indexOf("wordBox") !== -1) {
FontToggle();
FocusMode();
}
});
};
const ExecuteFunctions = () => {
if (window.location.hash === "#/study/entry") common_CheckUpdate();
if (window.location.hash === "#/study?type=book") FocusMode();
if (window.location.hash === "#/setting") LoadConfig();
if (window.location.hash.indexOf("#/detail") !== -1) {
FontToggle();
NoteRemove();
HideTranslation();
}
ToggleDarkMode();
FocusMode();
};
const OuterObserver = new MutationObserver(OuterCallback);
OuterObserver.observe(OuterTargetNode, {
childList: true,
subtree: true
});
ExecuteFunctions();
}
/* harmony default export */ const common_Observer = (Observer);
;// CONCATENATED MODULE: ./src/index.js
window.onload = () => {
common_LoadUrl();
common_Observer();
};
})();
/******/ })()
;