var timerGetInfo; // 延时获取信息 var timerMouseLeave; // 鼠标离开番号。鼠标进入菜单时的定时器, 超时不进入, 菜单消失 var timerMouseLeaveMenu; // 鼠标离开菜单 var divTarget; // 鼠标当前经过的番号节点 var avInfo = {}; // 临时存储相关信息 var Imgscall = 1.0; // 图片默认放大倍数, 在图片上滚动鼠标滚轮使用。 // 鼠标经过番号 function savIDMouseEnter(e, nameEn) { // 进入番号, 如果之前存在菜单, 就判断是否是现在番号的菜单, 如果是, 退出; 否则删掉菜单, 重新获取 if (divTarget && $(e).attr('href') == $(divTarget).attr('href')) { clearTimeout(timerMouseLeaveMenu); // return; } else if (divTarget) { clearTimeout(timerMouseLeaveMenu); let odiv = document.querySelector(".sav-menu"); if (odiv) { odiv.parentNode.removeChild(odiv); } } divTarget = $(e); clearTimeout(timerMouseLeave); clearTimeout(timerGetInfo); avmouseenter($(e), nameEn); } // 鼠标离开番号 function savIDMouseLeave(e, nameEn) { timerMouseLeave = setTimeout(function () { avInfo = {}; savMenuMouseLeave($(e), nameEn); removeLoading(); }, 50) } // 鼠标进入菜单 function savMenuMouseEnter(e) { clearTimeout(timerMouseLeave); } // 鼠标离开菜单 function savMenuMouseLeave(e) { timerMouseLeaveMenu = setTimeout(function () { var odiv = document.querySelector(".sav-menu"); if (odiv) { if (setting.dontClearMenu) { console.log("移除"); } else { // odiv.parentNode.removeChild(odiv); odiv.classList.add("savCloseAnim") setTimeout(function () { if (odiv) { odiv.parentNode.removeChild(odiv); } }, 100) } Imgscall = 1.0; divTarget = null; } avInfo = {}; clearTimeout(timerGetInfo); }, 10); } // 鼠标滑过 显示菜单 function avmouseenter(e, nameEn) { if (document.querySelector(".sav-menu")) { return; // 防止出现菜单后重复触发, 尤其是margin上移两像素后 } // 创建搜索基本菜单(搜索按钮) var odiv = createPattenr($(e), nameEn); // 信息加载时的动画 addLoading(odiv); var oPosition = $(e)[0].getBoundingClientRect(); var posRight = 630 - (document.documentElement.clientWidth - oPosition.x); if (posRight < 15) { posRight = 15; } odiv.style.transformOrigin = posRight + "px 5px"; document.body.appendChild(odiv); odiv.style.left = oPosition.x + "px"; odiv.style.top = oPosition.y + oPosition.height - 2 + "px"; odiv.style.width = "650px"; timerGetInfo = setTimeout(() => { getInfo($(e), nameEn); }, 300); var otherInfo = document.createElement('avdivsInfo'); otherInfo.innerHTML = addOtherInfo($(e)); odiv.appendChild(otherInfo); settingPostion(); //重置位置 } // 获取番号相关的信息, 添加图片,调用其他函数添加信息 function getInfo(e, nameEn) { var id = $(e).attr("avid"); $.ajax({ url: "coin/mainSearchDetail/" + getCookie('username') + "/" + nameEn + "/" + id, //请求的url地址 dataType: "json", //返回格式为json type: "get", //请求方式 async: false, //请求是否异步,默认为异步,这也是ajax重要特性 success: function (data) { noReferrer(); // 针对防盗链问题 javbusloading(); //请求成功时处理 if (data != null && $.trim(data) != "" && data.success) { console.log("insertOrUpdateWatchlist-submit success data"); if ('image' === nameEn){ // 将获取到的信息进行展示和保存 var otherInfo = document.querySelector("avdivsInfo"); if (!otherInfo) { otherInfo = document.createElement('avdivsInfo'); } otherInfo.innerHTML = addOtherInfo($(e)); let imgDiv = document.createElement("avdivimg"); let image = document.createElement("img"); image.src = data.data.path; image.classList.add("avimg"); image.setAttribute("referrerpolicy", "no-referrer"); imgDiv.appendChild(image); otherInfo.appendChild(imgDiv); // 原图标签更新属性 $("a:contains('原图')").attr("href", data.data.path); image.onload = function () { console.log("insertOrUpdateWatchlist-image onload,", image.src); removeLoading(); settingPostion(); } image.onerror = () => { console.log("insertOrUpdateWatchlist-image onerror,", image.src); if (avInfo.imgSrc2) { image.src = avInfo.imgSrc2; localInfo[avID].image = avInfo.imgSrc2; GM_setValue("avInfo2", localInfo); } else { image.classList.add('savImgError'); image.src = imgErrorSVG; } settingPostion(); } }else if ('watchlist' === nameEn){ // 将获取到的信息进行展示和保存 var otherInfo = document.querySelector("avdivsInfo"); if (!otherInfo) { otherInfo = document.createElement('avdivsInfo'); } document.querySelector(".feixiaohao").href = data.data.feixiaohaoUrl; document.querySelector(".coinMarketCap").href = data.data.cmcUrl; document.querySelector(".coinGecko").href = data.data.coingeckoUrl; //otherInfo.style.overflow = "auto"; //otherInfo.style.maxHeight = "550px"; otherInfo.style.textIndent = "0em"; otherInfo.innerHTML = data.data.remark; removeLoading(); settingPostion(); } } else { console.log("insertOrUpdateWatchlist-submit success empty,", data); } }, beforeSend: function () { }, complete: function () { }, error: function (data) { //请求出错处理 console.log("insertOrUpdateWatchlist-submit error," + data); } }); } // 创建搜索基本菜单(搜索按钮) function createPattenr(e, nameEn) { var odiv = document.createElement("avdiv"); odiv.classList.add("sav-menu"); let aPattern = ""; if ('image' === nameEn) { aPattern += "原图"; } else if ('watchlist' === nameEn) { aPattern += "Feixiaohao"; aPattern += "CoinMarketCap"; aPattern += "CoinGecko"; odiv.style.overflow = "auto"; odiv.style.maxHeight = "550px"; } aPattern += ""; odiv.addEventListener("mouseenter", savMenuMouseEnter); odiv.addEventListener("mouseleave", savMenuMouseLeave); // 鼠标在图片上点击和滚轮放大缩小图片 odiv.addEventListener("click", savMenuClick); odiv.addEventListener("wheel", savImgWheel); odiv.innerHTML = aPattern; return odiv; } // 防盗链 function noReferrer() { // 相关代码地址 https://greasyfork.org/zh-CN/scripts/376884 // 名称: 显示防盗链图片 for Inoreader // 作者: maboloshi var meta = document.createElement('meta'); meta.name = "referrer"; meta.content = "no-referrer"; document.getElementsByTagName('head')[0].appendChild(meta); } function javbusloading() { var stop2 = document.querySelector(".stop2"); if (stop2) { stop2.classList.toggle("javbusloading"); } } // 滚动图片放大缩小 function savImgWheel(e) { if (e.target.tagName == "IMG") { if (e.wheelDelta > 0) { e.target.classList.add("imageBig"); // 点击后可以恢复 Imgscall += 0.15; e.target.style.transform = "scale(" + Imgscall + ")"; } else if (e.wheelDelta < 0) { if (Imgscall > 1) { Imgscall -= 0.15; if (Imgscall < 1) { // 偶尔会继续减小, 明明已经小于1还是会执行到这 Imgscall = 1 } e.target.style.transform = "scale(" + Imgscall + ")"; if (Imgscall == 1) { // 缩放到1就去掉class, 之前是缩放到1后继续滚动一次才会去掉class e.target.classList.remove("imageBig"); e.target.style = ""; } } else { e.target.classList.remove("imageBig"); e.target.style = ""; } } } e.preventDefault(); return false; } // 点击事件, 图片放大缩小, debug中复制番号 function savMenuClick(e) { // 测试使用 if (e.target.classList.contains("savCopyID")) { GM_setClipboard(e.target.dataset.av) } else if (e.target.classList.contains("savCloseMenu")) { var odiv = document.querySelector(".sav-menu"); odiv.classList.add("savCloseAnim") setTimeout(function () { odiv.parentNode.removeChild(odiv); }, 100) Imgscall = 1.0; avInfo = {}; divTarget = null; clearTimeout(timerGetInfo); return; } else if (e.target.classList.contains("savSetting")) { savBoxEdit(); return; } else if (e.target.classList.contains("jellyfin")) { if (e.target.classList.contains("noJellyfin")) { console.log(e.target.dataset.avid); GM_setClipboard(e.target.dataset.avid); } // console.log(e.target.dataset.url); if (debug) console.log(e.target.dataset.url); GM_openInTab(e.target.dataset.url, {active: true, insert: true, setParent: true}); return; } else if (e.target.classList.contains("savsehuatang")) { // 防止多次点击导致重复发送请求 e.target.classList.remove("savsehuatang"); sehuatang(e.target.dataset.avid); return; } else if (e.target.classList.contains("savVideoClose")) { let videoDiv = document.querySelector("avdivVideo"); if (videoDiv) { videoDiv.classList.add("savCloseAnim2"); setTimeout(() => { videoDiv.parentNode.removeChild(videoDiv); }, 200) } return; } // 图片放大缩小 if (e.target.tagName == "IMG") { if (e.target.classList.contains("imageBigClick")) { e.target.classList.remove("imageBigClick"); Imgscall = 1.0; e.target.style = ""; } else { Imgscall = 1.3; // 重置大小 e.target.classList.add("imageBigClick"); } } else { var oImg = document.querySelector(".sav-menu").querySelector("img"); if (oImg) { oImg.classList.remove("imageBig"); Imgscall = 1.0; oImg.style = ""; } } } // 添加信息加载时的动画 function addLoading(odiv) { var savLoading = document.createElement('avdiv'); savLoading.classList.add("savLoadingContainer"); var savhr = '' + '' + '' + '' + '' + '' + ' ' + '' savLoading.innerHTML = '' + savhr + savhr + ''; odiv.appendChild(savLoading); } // 在菜单中添加番号相关的信息(标题,演员等) function addOtherInfo(avID) { var str = ""; //str += "标题: " + "测试ING" + ""; str += "" + ""; return str; } // 调整距离底部的距离,以防越界 function settingPostion(image) { var odiv = document.querySelector(".sav-menu"); if (!odiv) return; var oClient = odiv.getBoundingClientRect(); var oTop = oClient.top; // 距离顶部举例 var oHeight = oClient.height; //自身高度 // var oWidth = oClient.Width; // 自身宽度 var winHeight = document.documentElement.clientHeight; //可视窗口高度 var winWidth = document.documentElement.clientWidth; //可视窗口宽度 let loadingContainerHeight = document.querySelector(".savLoadingContainer") ? 8 : 0; if (oTop + oHeight - loadingContainerHeight > winHeight) { // 越出了屏幕底边 odiv.style.position = "fixed"; odiv.style.top = winHeight - oHeight + 2 * loadingContainerHeight - 16 + "px"; var posBottom = oHeight - (document.documentElement.clientHeight - $(divTarget)[0].getBoundingClientRect().y) + 30; if (posBottom < 5) { posBottom = 5 } odiv.style.transformOrigin = odiv.style.transformOrigin.replace(/\s.+px/, ` ${posBottom}px`) } if (oClient.x < 0) { //左边 odiv.style.position = "fixed"; odiv.style.left = 0; } else if (winWidth - oClient.x < 600) { // 越出了屏幕右边 odiv.style.position = "fixed"; odiv.style.right = "4px"; odiv.style.left = ""; } } // 鼠标离开菜单 function savMenuMouseLeave(e, nameEn) { timerMouseLeaveMenu = setTimeout(function () { var odiv = document.querySelector(".sav-menu"); if (odiv) { odiv.classList.add("savCloseAnim"); setTimeout(function () { if (odiv) { odiv.parentNode.removeChild(odiv); } }, 100) } avInfo = {}; }, 10); } // 移除信息加载时的动画 function removeLoading() { // return; var loading = document.querySelector(".savLoadingContainer"); if (loading) { loading.style.height = "0px"; loading.style.marginTop = "0px"; setTimeout(() => { loading.parentNode?.removeChild(loading); }, 200) } }