UnderHentai小工具

手机端因为广告基本不能正常观看,故有此脚本

От 23.03.2023. Виж последната версия.

// ==UserScript==
// @name         UnderHentai小工具
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  手机端因为广告基本不能正常观看,故有此脚本
// @author       thunder-sword
// @match        *://www.underhentai.net/*
// @match        *://doodstream.com/e/*
// @match        *://dood.yt/e/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=underhentai.net
// @license      MIT
// @grant        none
// ==/UserScript==


// @require      https://code.jquery.com/jquery-latest.min.js

const settings={
    "del_player_adv":true,//删除播放器上方的浮动广告,可能导致页面头部消失不见
    "del_nomal_adv":true,
    "del_sex_adv":true,
};

//作用:删除普通广告(烦人的,让视频无法观看的)
function del_nomal_adv(){
    if(-1!==window.location.host.indexOf("underhentai")){
        //document.querySelector("#main > div.col-sm-4.col-md-3.col-lg-3.sidebar > div > div.afi-sm")?.remove();
        //删除侧栏广告
        document.querySelector("div.afi-sm")?.remove();
        //删除点击watch按钮会弹出页面广告
        document.querySelectorAll("#main > div.col-sm-8.col-md-9.col-lg-9.content > div.content-table > table > tbody > tr > td.c8 > a").forEach(e => e?.setAttribute("class",""));
    }else if(-1!==window.location.host.indexOf("dood")){
        // 取消所有 interval
        // var highestIntervalId = setInterval(";");
        // for (var i = 0 ; i < highestIntervalId ; i++) {
        //     clearInterval(i);
        // }
        //document.head.innerHTML='';

        //document.body.outerHTML="<body>"+document.querySelector("#os_player").outerHTML+"</body>";
        setInterval(() => {
            //删除所有script
            document.querySelectorAll('script').forEach(e => e?.remove());
            //删除所有iframe
            document.querySelectorAll('iframe').forEach(e => e?.remove());
            //删除检查对话框
            document.querySelectorAll('#checkresume_div').forEach(e => e?.remove());
        }, 1000);
        console.log("dood普通广告清理完毕");
        //alert("dood普通广告清理完毕");
    }
}

//作用:删除sex广告(不影响观看体验的,提升情趣的)
function del_sex_adv(){
    if(-1!==window.location.host.indexOf("underhentai")){
        //document.querySelector("#main > div.col-sm-4.col-md-3.col-lg-3.sidebar > div > div.afi-lg")??.remove();
        document.querySelector("div.afi-lg")?.remove();
        if('/watch/'===window.location.pathname){
            //删除播放页面上下两个广告框
            document.body.querySelectorAll('.visible-xs').forEach(e => e?.remove());
        }
    }
}

//作用:一种思路,获取到url后再替换video,缺点是不能切换源,同时还要识别不同的url,舍去这种思路
function get_url_replace_video(){
    let url=document.body.innerHTML.match("(https://video.storangeunderh.com/player/.*?)\\\\")[1];
    if(!url){
        alert("未找到videourl");
        console.log("未找到videourl");
    }
    console.log(url);
    url+="?ads=false";

    //删除所有script
    document.body.querySelectorAll('script').forEach(e => e?.remove());
    //删除所有iframe
    document.body.querySelectorAll('iframe').forEach(e => e?.remove());
    //删除视频上广告
    document.querySelector("div#overlay")?.remove();
    //添加新的iframe播放视频
    var iframe=document.createElement("iframe");
    iframe.scrolling='no';
    iframe.frameborder="0";
    iframe.allowFullscreen=true;
    iframe.src=url;
    document.querySelector("#doodstream").appendChild(iframe);
    //document.querySelector(".sidebar-dark").append(iframe);
    //document.querySelector(".embed-responsive")?.remove();
}

//作用:仅去除掉播放页面中的广告因素【最后其实只是将js全部去除了,其实是有些弊端的】
function replace_video(){
    if(-1!==window.location.host.indexOf("underhentai") && '/watch/'===window.location.pathname){
        console.log("清除播放界面的广告");
    }else{
        return;
    }
    let ret=document.body.innerHTML.match(/\$\(function.*<\/iframe>"\);}\);/);
    if(!ret){
        alert("未找到videourl");
        console.log("未找到videourl");
    }
    let content=ret[0];
    content=content.slice(1)+"})();";//去除掉开头的$,因为发现有这玩意函数总是执行不成功,去掉之后用普通jquery方式执行就可以成功执行了,话说为什么啊
    console.log(content);

    //删除所有script
    document.body.querySelectorAll('script').forEach(e => e?.remove());
    //删除所有iframe
    document.body.querySelectorAll('iframe').forEach(e => e?.remove());
    //删除视频上广告
    document.querySelector("div#overlay")?.remove();

    //先加载jquery,然后执行代码
    var jquery=document.createElement("script");
    jquery.src="https://code.jquery.com/jquery-latest.min.js";
    jquery.onload = function() {
        //console.log("start");
        // jQuery 加载完成后执行的代码
        var script=document.createElement("script");
        script.innerHTML=content;
        document.body.append(script);
        //console.log("end");
    };
    document.body.append(jquery);
}

(function() {
    //取消所有 interval
    var highestIntervalId = setInterval(";");
    for (var i = 0 ; i < highestIntervalId ; i++) {
        clearInterval(i);
    }
    if(settings["del_player_adv"]){
        //alert("删除播放器广告已执行");
        replace_video();
    }
    if(settings["del_nomal_adv"]){
        del_nomal_adv();
    }
    if(settings["del_sex_adv"]){
        del_sex_adv();
    }
})();