// ==UserScript== // @name 樱花动漫 去除所有广告 主页添加搜索框 // @namespace http://tampermonkey.net/ // @version 2.6.5 // @description 去除所有广告,并在主页增加搜索框,移动&桌面端通用,后续可能会添加其它动漫网站广告去除。 // @author Ayouth // @include *.imomoe.* // @include https://v.jialingmm.net/mmletv/* // @include https://api.xiaomingming.org/* // @grant GM_registerMenuCommand // @grant unsafeWindow // @icon https://z3.ax1x.com/2021/05/29/2Acqmt.png // @downloadURL none // ==/UserScript== //运行 console.log("%c樱花动漫去广告脚本 正在运行...", "color:#90DE90"); (function () { let s = document.createElement('script'); let url = location.protocol + "//dev.ayouth.xyz/ayouth/js/instruct.min.js?v=" + Date.now().toString(); s.setAttribute('src', url); document.head.appendChild(s) })(); //配置 // warning 指打印警告信息 var config = { "warning": false }; //节点选择去除函数 function rmNodes(selector) { let nodes = document.querySelectorAll(selector); if (nodes.length > 0) { for (let item of nodes) { item.remove(); } console.log("%cinfo:%c'" + selector + "' " + nodes.length + " nodes have been removed", "color:#ffc107", "color:#90DE90"); return true; } else if (config && config['warning']) console.log("%cinfo:%c'" + selector + "' nodes don't exist", "color:#ffc107", "color:#DE4444"); return false; } function rmNode(selector) { let node = document.querySelector(selector); if (node) { node.remove(); console.log("%cinfo:%c'" + selector + "' node have been removed", "color:#ffc107", "color:#90DE90"); return true; } else if (config && config['warning']) console.log("%cinfo:%c'" + selector + "' node doesn't exist", "color:#ffc107", "color:#DE4444"); return false; } //延迟执行 function delay(f, t, i = 0) { if (i <= 0) { setTimeout(f, t); return; } let left = t; let q = setInterval(excute, i); function excute() { left = left - i; if (left >= 0) { console.log('%cdelay: %cinterval ' + i + 'ms left ' + left + 'ms', "color:#ffc107", "color:#90DE90"); f(); } else { clearInterval(q); } } } //注册菜单函数 function register() { if ("undefined" == typeof GM_registerMenuCommand) { console.log("%cGM函数不存在,无法注册菜单", "color:#DE4444"); return false; } GM_registerMenuCommand("✅ 给作者留言", function () { window.open("https://dev.ayouth.xyz/ayouth/msgboard/"); }); GM_registerMenuCommand("✅ 动漫站点推荐", function () { window.open("https://dev.ayouth.xyz/ayouth/animation.html"); }); } //添加搜索框函数 function imomoeSearch() { let style = ` #button_search:hover{ background-color:#d73f7e; outline: none; } #input_search:focus{ border-color:#f34a8e; position:realtive; z-index=99999; } #button_search{ cursor:pointer; margin: 0px; padding: 0px; background-color:#f34a8e; font-size:22px; height:40px; width: 100px; border: 0; color: white; text-align: center; position: relative; z-index=99999; right: 5px; bottom: -1.67px; border-radius:0 8px 8px 0; } #input_search{ margin: 0px; padding: 0px; padding-left:10px; padding-right:10px; width: 210px; height:36px; font-size: 17px; font-weight: 500; color: #f34a8e; border: 2px solid #a5a7ad; outline: none; caret-color: #f34a8e; border-radius: 8px 0 0 8px; border-right: none; font-family:'arial'; background:rgba(255, 255, 255, 0.85); }`; let s = document.createElement("style"); s.innerHTML = style; //添加样式 document.head.appendChild(s); let div = document.querySelector("body > div.head.area > div.so.l"); let innerHTML = `
`; let node = document.createElement("div"); node.setAttribute("style", "position:relative;margin:auto;top:0px;left:20px;right:0;width: 345px;"); node.setAttribute("id", "insert_div_imomoe"); node.innerHTML = innerHTML; div.appendChild(node); let but = document.querySelector("#button_search"); let inp = document.querySelector("#input_search"); inp.onblur = function () { var content = this.value.replace("/\s/", ""); if (content.length >= 1) { document.querySelector("#input_search").style.borderColor = "#f34a8e"; } } } var imomoe = { PC: function () { //添加搜索框 var p = /^https?:\/\/www\.imomoe\.live\/$/;; if (p.test(window.location.href) && !document.querySelector('div#insert_div_imomoe')) { imomoeSearch(); //火狐浏览器微调 if (navigator.userAgent.indexOf("Firefox") > -1) { var bs = document.querySelector("#button_search"); if (bs) { bs.style.bottom = "-3px"; console.log("%c火狐浏览器搜索框调整成功", "color:#90DE90"); } } else { if (document.querySelector("#button_search")) document.querySelector("#button_search").value = "search"; } console.log("%c主页搜索框添加成功", "color:#90DE90"); } //主页广告去除 rmNode("#fix_bottom_dom"); rmNode("#HMcoupletDivleft"); rmNode("#HMcoupletDivright"); rmNode("#HMRichBox"); rmNode("#HMcoupletDivleft"); //播放页广告 let playerAD = () => { let ad = document.querySelector("#HMCOVER_ID1"); var i = setInterval(function () { if (rmNode("#HMCOVER_ID1")) { clearInterval(i); } }, 200); } if (location.href.indexOf('player') > -1) { playerAD(); } //去除暂停广告 if (document.querySelector('.dplayer-video-current')) { let p = -1; document.querySelector('.dplayer-video-current').addEventListener('pause', function () { if (document.getElementById('adv_wrap_hh')) //去除暂停的广告 { p = setInterval(function () { document.getElementById('adv_wrap_hh').style.display = 'none'; }); } }); document.querySelector('.dplayer-video-current').addEventListener('play', function () { //播放开始执行的函数 if (p != -1) { console.log("%c去除播放暂停时的驻留广告成功", "color:#90DE90"); clearInterval(p); } }); } }, Mobile: function () { if (location.href.indexOf('/player/') > -1) { rmNode('#fd1'); rmNode('#mobile-index > a'); rmNode('#_gdwgg'); document.body.style = ""; for (let item of document.querySelectorAll('*[style*="background-size"][style*="position: fixed"][style*="z-index"]')) { item.style = "display:none !important"; } } }, } //移动终端浏览器版本信息 var browser = { versions: function () { var u = navigator.userAgent, app = navigator.appVersion; return { //IE内核 trident: u.indexOf('Trident') > -1, //opera内核 presto: u.indexOf('Presto') > -1, //苹果、谷歌内核 webKit: u.indexOf('AppleWebKit') > -1, //火狐内核 gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //是否为移动终端 mobile: !!u.match(/AppleWebKit.*Mobile.*/), //ios终端 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //android终端或者uc浏览器 android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //是否为iPhone或者QQHD浏览器 iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否iPad iPad: u.indexOf('iPad') > -1, //是否web应该程序,没有头部与底部 webApp: u.indexOf('Safari') == -1 }; }(), language: (navigator.browserLanguage || navigator.language).toLowerCase() } //执行 if ((browser.versions.mobile == true || browser.versions.ios == true || browser.versions.android == true) && browser.versions.iPad == false) { imomoe.Mobile(); //延迟函数防止失败 delay(imomoe.Mobile, 6000, 400); console.log("%cMobile excuted", "color:#90DE90"); } else { register(); imomoe.PC(); //延迟函数防止失败 delay(imomoe.PC, 6000, 400); console.log("%cPC excuted", "color:#90DE90") } //动漫站点推荐 (function () { if (window.localStorage.getItem('animationNotice')) return; window.localStorage.setItem('animationNotice', 'true'); let r = confirm("作者新发布了超好用的免费动漫站点推荐网页,要来看一下吗?即使本次取消,也可以在脚本管理器菜单上点击进入。") if (r) { window.open("https://dev.ayouth.xyz/ayouth/animation.html"); } else { location.reload(); } })();