Greasy Fork

樱花动漫 去除所有广告 主页添加搜索框 多动漫站点去广告 移动&桌面端通用

樱花动漫、Age动漫、233动漫、森之屋动漫去除所有广告,樱花动漫主页添加加搜索框,移动&桌面端通用,后续会扩展其它动漫网站。

目前为 2022-01-08 提交的版本。查看 最新版本

// ==UserScript==
// @name         樱花动漫 去除所有广告 主页添加搜索框 多动漫站点去广告 移动&桌面端通用 
// @namespace    https://greasyfork.org/zh-CN/users/757544-ayouth
// @version      2.7.8
// @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.8", "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)); 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 imomoeSearch() {
    if (node('div#insert_div_imomoe'))
        return false;
    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 = node("body > div.head.area > div.so.l");
    if (!div) return false;
    let innerHTML = `<form name="formsearch" id="formsearch" action="/search.asp" method="post"><input  name="searchword" type="text" spellcheck="false" id="input_search"  /><input type="submit" id="button_search"  value="搜索" /></form>`;
    let d = document.createElement("div");
    d.setAttribute("style", "position:relative;margin:auto;top:0px;left:20px;right:0;width: 345px;");
    d.setAttribute("id", "insert_div_imomoe");
    d.innerHTML = innerHTML;
    div.appendChild(d);
    let but = node("#button_search");
    let inp = node("#input_search");
    inp.onblur = function () {
        var content = this.value.replace("/\s/", "");
        if (content.length >= 1) {
            node("#input_search").style.borderColor = "#f34a8e";
        }
    };
    //火狐浏览器微调
    if (navigator.userAgent.indexOf("Firefox") > -1) {
        var bs = node("#button_search");
        if (bs) {
            bs.style.bottom = "-3px";
            console.log("%c火狐浏览器搜索框调整成功", success);
        }
    }
    else {
        if (node("#button_search"))
            node("#button_search").value = "search";
    }
    console.log("%c主页搜索框添加成功", success);
}
//樱花动漫
var imomoe = {
    PC: function () {
        //添加搜索框
        urlTest({
            host: 'www.imomoe.live', 
            path: '/', 
            strict: true, 
            callback: function () {
                document.addEventListener('DOMContentLoaded', imomoeSearch);
                //防止失败
                setTimeout(imomoeSearch, 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)
}