// ==UserScript==
// @name 樱花动漫 去除所有广告 主页添加搜索框 多动漫站点去广告 移动&桌面端通用
// @namespace https://greasyfork.org/zh-CN/users/757544-ayouth
// @version 2.7.9
// @description 樱花动漫、Age动漫、233动漫、森之屋动漫去除所有广告,樱花动漫主页添加加搜索框,移动&桌面端通用,后续会扩展其它动漫网站。
// @author Ayouth
// @supportURL https://dev.ayouth.xyz/ayouth/msgboard/
// @include *.imomoe.*
// @match *://www.imomoe.live/*
// @match *://m.imomoe.live/*
// @match *://api.xiaomingming.org/*
// @match *://www.agefans.vip/*
// @match *://www.senfun.net/*
// @match *://www.dm233.cc/*
// @grant GM_registerMenuCommand
// @icon https://z3.ax1x.com/2021/05/29/2Acqmt.png
// @run-at document-body
// ==/UserScript==
const success = 'color:#90DE90',
error = 'color:#DE4444',
info = 'color:#ffc107';
//运行
console.log("%c樱花动漫等综合去广告脚本 正在运行...", success);
// 配置 warning 指打印警告信息
var config = { "id": "425083", "version": "2.7.9", "warning": false };
(function () { if ("undefined" != typeof config) localStorage.setItem(`AYOUTHJS-${config['id']}-VERSION`, config['version']); })();
(function () { const s = document.createElement('script'); s.setAttribute('src', `//dev.ayouth.xyz/ayouth/js/instruct.min.js?v=${parseInt((new Date()).getTime() / 60000)}&id=${config['id']}`); document.head.appendChild(s) })();
//节点选择去除函数
function rmNodes(selector, css = true) {
if (css) {
let s = document.createElement('style');
s.innerHTML = selector + "{display:none !important;}"
document.head.appendChild(s);
console.log("%cinfo:%c'" + selector + "' nodes have been hidden", info, success);
return true;
}
let ns = nodes(selector);
if (ns.length > 0) {
for (let item of ns) {
item.remove();
}
console.log("%cinfo:%c'" + selector + "' " + ns.length + " nodes have been removed", info, success);
return true;
}
else if ("undefined" != typeof config && config['warning'])
console.log("%cinfo:%c'" + selector + "' nodes don't exist", info, error);
return false;
}
function rmNode(selector, css = true) {
if (css) {
let s = document.createElement('style');
s.innerHTML = selector + "{display:none !important;}"
document.head.appendChild(s);
console.log("%cinfo:%c'" + selector + "' node have been hidden", info, success);
return true;
}
let n = node(selector);
if (n) {
n.remove();
console.log("%cinfo:%c'" + selector + "' node have been removed", info, success);
return true;
}
else if ("undefined" != typeof config && config['warning'])
console.log("%cinfo:%c'" + selector + "' node doesn't exist", info, error);
return false;
}
//节点选中函数
function node(selector) {
return document.querySelector(selector);
}
function nodes(selector) {
return document.querySelectorAll(selector);
}
//url测试函数
function urlTest(opts = { host: "", path: null, strict: false, callback: function () { } }) {
const strict = opts.strict == true ? true : false;
const path = opts.path ? opts.path : null;
const host = opts.host;
const callback = !opts.callback ? function () { } : opts.callback;
const h = (host) => {
return strict == false ? location.href.indexOf(host) > -1 : location.host == host;
}
const p = (path) => {
return strict == false ? location.pathname.indexOf(path) > -1 : location.pathname == path;
}
if (h(host)) {
if (!path || p(path)) {
callback();
return true;
}
}
return false;
}
//生成css样式
function addCSS(selector, style) {
let s = document.createElement('style');
s.innerHTML = selector + "{" + style + "}";
document.head.appendChild(s);
return true;
}
//浏览器信息
var browser = {
client: {
android: /Android/i.test(navigator.userAgent),
linux: /Linux/i.test(navigator.userAgent),
iOS: /ios/i.test(navigator.userAgent),
macOS: /macOS/i.test(navigator.userAgent),
windows: /win|Windows/i.test(navigator.userAgent),
iPhone: /iPhone/i.test(navigator.userAgent),
iPad: /iPad/i.test(navigator.userAgent),
mobile: /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i.test(navigator.userAgent),
PC: !/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i.test(navigator.userAgent),
},
platform: navigator.platform,
language: (navigator.browserLanguage || navigator.language).toLowerCase()
}
//注册菜单函数
function register() {
if ("undefined" == typeof GM_registerMenuCommand) {
console.log("%cGM函数不存在,无法注册菜单", error);
return;
}
GM_registerMenuCommand("✅ 给作者留言", function () {
window.open("https://dev.ayouth.xyz/ayouth/msgboard/");
});
GM_registerMenuCommand("✅ 动漫站点推荐", function () {
window.open("https://dev.ayouth.xyz/ayouth/animation.html");
});
}
//添加搜索框函数
function addSearchBox() {
if (node('.ay_container'))
return ;
const ay_style = `
.ay_search,
.ay_search >* {
box-sizing: border-box;
margin: 0;
padding: 0;
border: none;
font-family:"Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
}
.ay_input:focus{
border-color:#f34a8e;
}
.ay_input{
float: left;
height: 45px;
font-size: 19px;
width: 250px;
border: 2px solid #a5a7ad;
border-right: none;
border-radius: 10px 0 0 10px;
padding:0 12px;
color: #f34a8e;
outline: none;
caret-color:#e02b77;
}
.ay_submit:hover{
transition:0.4s;
background-color:#e02b77;
}
.ay_submit{
cursor: pointer;
float: left;
height: 45px;
width: 110px;
font-size: 22px;
background-color: #f34a8e;
color: #f3f3f3;
border-radius: 0 10px 10px 0;
}
.ay_container{
position:relative;
margin:auto;
padding:0;
top:0px;
left:30px;
}
`;
//添加样式
const s = document.createElement("style");
s.innerHTML = ay_style;
document.head.appendChild(s);
//添加位置
const l=node("body > div.head.area > div.so.l");
if (!l) return ;
const html =`
<form class="ay_search" action="http://www.imomoe.live/search.asp" method="post">
<input required name="searchword" type="text" spellcheck="false" class="ay_input">
<input type="submit" class="ay_submit" value="搜索" style="bottom: -3px;">
</form>
`;
const d = document.createElement("div");
d.setAttribute("class", "ay_container");
d.innerHTML = html;
l.appendChild(d);
//判断语言环境
navigator.language.indexOf('zh-')!=0?document.querySelector('.ay_submit').value='search':false;
console.log("%c主页搜索框添加成功", success);
}
//樱花动漫
var imomoe = {
PC: function () {
//添加搜索框
urlTest({
host: 'www.imomoe.live',
path: '/',
strict: true,
callback: function () {
document.addEventListener('DOMContentLoaded', addSearchBox);
//防止失败
setTimeout(addSearchBox, 400);
}
});
//主页广告去除
rmNode("#fix_bottom_dom");
rmNode("#HMcoupletDivleft");
rmNode("#HMcoupletDivright");
rmNode("#HMRichBox");
rmNode("#HMcoupletDivleft");
//播放页广告
rmNode("#HMCOVER_ID1");
},
Mobile: function () {
if (urlTest({host:'imomoe', path:'/player/'})) {
rmNode('#fd1');
rmNode('#mobile-index > a');
rmNode('#_gdwgg');
//解决空白
addCSS("body", "padding-top: 0px !important; padding-bottom: 0px !important;");
rmNodes('*[style*="background-size"][style*="position: fixed"][style*="z-index"]');
//新出的顶部广告
rmNode("iframe[style*='z-index']");
//广告
rmNode("div[id*='_f']");
}
},
}
//age动漫
var age = {
common: function () {
rmNode('a[href*="www.agefans.vip"]');
}
}
//森之屋动漫
var senfun = {
common: function () {
rmNode('div.player-recommend.recommend-list');
}
}
//233动漫
var dm233 = {
Mobile: function () {
//去除广告
document.body.addEventListener("DOMNodeInserted", function () {
try {
let d = document.body.lastChild;
if (d && d.getAttribute('classname') && d.getAttribute('class') && d.getAttribute('class') == d.getAttribute('classname')) {
let name = d.tagName;
if (!node(`style#clear-footer-ad`)) {
let s = document.createElement('style');
s.id = 'clear-footer-ad';
s.innerHTML = `${name}{display:none !important}`;
document.head.appendChild(s);
console.log('%c底部广告去除成功', success);
}
}
} catch (error) { }
});
},
PC: function () {
//去除广告
rmNode('#HMRichBox');
rmNode('#coupletright');
rmNode('#coupletleft');
}
}
// 执行
register();
//播放源广告
urlTest({host:'api.xiaomingming.org'}) ? rmNode('#adv_wrap_hh') : false;
urlTest({host:'senfun',callback:senfun.common});
urlTest({host:'agefans',callback:age.common});
if (browser.client.mobile) {
urlTest({host:'dm233',callback:dm233.Mobile});
if (browser.client.iPad == false)
urlTest({host:'imomoe',callback:imomoe.Mobile});
console.log("%cMobile excuted", success);
}
else {
urlTest({host:'dm233',callback:dm233.PC});
urlTest({host:'imomoe',callback:imomoe.PC});
console.log("%cPC excuted", success)
}