Greasy Fork is available in English.

今年一定島 自動更新回文

汲汲營營大報社

Pada tanggal 29 Desember 2023. Lihat %(latest_version_link).

// ==UserScript==
// @name         今年一定島 自動更新回文
// @description  汲汲營營大報社
// @author       稻米
// @namespace    https://greasyfork.org/zh-TW/scripts/39891
// @version      2023.12.30.0010.build16299

// @match        *://gaia.komica.org/00b/*
// @match        *://gaia.komica1.org/00b/*
// @match        *://gaia.komica2.net/00b/*

// @exclude      *://*/00b/src/*
// @exclude      *://*/00b/thumb/*

// @grant        none
// @license      WTFPL



// ==/UserScript==

//jquery
try{}
catch(err){}
finally{}
//
$(document).ready(function() {
    //var time=new Date();
    //
    //var url = new URL( window.location.href );
    //var res=url.searchParams.get('res');
    //console.log( res );
    //return;
    poi(); //回應模式才執行
});

function poi(){
    if(window.localStorage){
        //ok //網頁儲存資料的功能
        //console.log( window.localStorage );
    }else{
        return;
    }
    //
    var aa=window.location.href.match("\\?res=");
    //console.log( aa );
    if( aa ){
        //ok //確認是回應模式的網址
    }else{
        return;
    }
    //
    var bb=$("div.bar_reply:contains('回應模式')");
    //console.log( bb );
    if( bb.length ){
        //ok //確認是回應模式
    }else{
        return;
    }
    //
    //console.log( '回應模式才執行' );
    poi231230倒數計時器();
}//poi()


function poi231230倒數計時器(){
    //console.log( 'poi231230倒數計時器' );
    //建立元素
    var aa =$('.thread');
    if(aa.length ){
        //ok //元素存在
    }else{
        return;
    }
    aa.append('<span class="poi231230bigbox"><span class="poi231230">自動更新回文</span> </span>');
    $(".poi231230").css({
        "background-color":"yellow",
        "border":"2px solid red",
    });//
    ///
    poi231230倒數計時器2();//倒數
    poi231230手動更新();//倒數

}//poi231230倒數計時器

function poi231230手動更新(){
    //console.log( 'poi231230手動更新' );
    $('.poi231230bigbox').append('<button type="reset">api資料</button><span id="poi231230訊息box"></span>');
    $(".poi231230bigbox >button:contains('api資料')").click(function(){
        //console.log('按鈕');
        clearTimeout( $.poi231230計時器 );//停止現有的計時器
        $('#poi231230訊息box').text('更新太快會有429錯誤');
        poi231230取得資料();//取得頁面的api新資料
    });

}//

function poi231230倒數計時器2(){
    //console.log( 'poi231230倒數計時器2' );
    var 紀錄的時間點= new Date().getTime();//更新當下的時間
    //
    var 計時器a1=function(){
        $.poi231230計時器=setTimeout(function(){
            var 檢查的新時間= new Date().getTime();//
            var 計時間隔=30;//秒
            var diff=檢查的新時間 - 紀錄的時間點;
            $(".poi231230").html(''+ 計時間隔 - Math.floor(diff/1000) );//取整數
            if(diff < 計時間隔*1000){ //設定每隔幾秒 更新頁面的新資料 //更新太快會有429錯誤
                clearTimeout( $.poi231230計時器 );//停止現有的計時器
                計時器a1();//重複
            }else{
                //window.clearTimeout( 計時器a1 );
                紀錄的時間點= new Date().getTime();//更新當下的時間
                //計時器a1();//重複//由getapi啟動
                poi231230取得資料();//取得頁面的api新資料
            }
        }, 1*1000);//setTimeout//每秒更新
        $.poi231230計時器;//啟動
    }//計時器a1
    計時器a1();//啟動
}//poi231230倒數計時器2


function poi231230取得資料(){
    //console.log('poi231230取得api資料');
    //var url = new URL( document.location.href );
    //var thread_no=url.searchParams.get("res");
    var thread_no = $('.post.threadpost').attr('data-no'); //首篇編號
    var apiurl='./pixmicat.php?mode=module&load=mod_ajax&action=thread&html=true&op='+thread_no; //綜合版原生api
    //console.log(apiurl);


    var jqXHR=$.ajax({
          url: apiurl,
          type: 'GET',
          data: {},
    });
    $('.poi231230').text('正在取得api資料');

    jqXHR.done(function(  data, textStatus, jqXHR ) {
        //console.log( 'jqXHR.done' );
        var json = $.parseJSON( data );//分析parse
        if(json.error >0){//出現錯誤 有可能是串被砍了
            console.log( json.msg );//錯誤訊息
            return;
        }
        //console.log( json.posts );//ok
        //return;
        var bb=json.posts; //post_json_ary
        var apidata_文章編號=[];
        var apidata_文章內容=[];
        $.each(bb,function(index,item){
            //console.log( item );
            //var bb2 = item.no;
            apidata_文章編號[index]=''+item.no;//用字串儲存
            apidata_文章內容[item.no]=item.html;
        });
        //console.log( apidata_文章編號,apidata_文章內容 );
        //return;
        var FFF=[apidata_文章編號,apidata_文章內容]
        poi231230比對資料( FFF );//比對資料
        poi231230倒數計時器2();
        //poi3(post_new_ary,post_new_ary2);//比對資料
    });//jqXHR.done

    ///
    jqXHR.fail(function( jqXHR, textStatus, errorThrown ){
        console.log( 'jqXHR.fail' );
        //console.log( jqXHR, textStatus, errorThrown );
        $('.poi231230').text(textStatus+jqXHR.status);
    });
    jqXHR.always(function( data, textStatus, jqXHR ){
        //console.log( 'jqXHR.always' );
        //console.log( textStatus );//success
    });

}//poi231230取得資料()

function poi231230比對資料(FFF){
    //console.log( 'poi231230比對資料' );
    var [apidata_文章編號,apidata_文章內容]=FFF;
    //console.log( apidata_文章編號,apidata_文章內容 );//ok

    //找出現有的文章編號
    var aa =$('div.thread').find('div.post');
    var html_文章編號=[];
    FFF='';
    aa.each(function(index,item){
        FFF = $(item).find('span.qlink').attr('data-no');//.data('no')
        //console.log( FFF );
        html_文章編號[index]=''+FFF;//用字串儲存
    });//each
    //console.log( html_文章編號 );

    //用新的文章編號 進行比對
    //遍歷
    $.each( apidata_文章編號 , function( index, item ) {
        var aa = html_文章編號.includes(item);
        if( aa ){
            //ok //已經存在
        }else{
            //$('div.thread').append( apidata_文章內容[item] );//prepend
            $('.poi231230bigbox').before( apidata_文章內容[item] );//after

        }
    });//each

/*
    html_文章編號.forEach(function(value,index){
        //console.log(value,index);
    });//js

*/

}//poi231230比對資料(FFF)






/*
舊版本
https://greasyfork.org/zh-TW/scripts/39891-?version=1139339
*/