poi190213

汲汲營營大報社

目前为 2019-02-14 提交的版本。查看 最新版本

// ==UserScript==
// @name         poi190213
// @namespace    https://gf.qytechs.cn/zh-TW/scripts/377743
// @description  汲汲營營大報社
// @author       稻米
// @include      http://sora.komica.org/00/*
// @include      https://sora.komica.org/00/*


// @version      2019.01.15.2343.build16299
// @grant        none
// ==/UserScript==

try{
    $(document).ready(function() {
        //console.log( 'jquery ready' );
        //window.gg=[];
        window.gg=[]; //globalVar
        gg.time=new Date();//可讀時間
        gg.timestamp=Date.now();//new Date().getTime();
        $.gginin=gg;
        //

        poi();
    });
}
catch(err){
    console.log( ''+err.message );
}
finally {
    //console.log( 'try-catch-finally' );
}

function poi(){
    //console.log( gg );
    console.log( $.gginin );

    var json_array=[];
    var ary=[];
    ary={nn:'123',cc:1};
    json_array.push(ary);
    ary={nn:'456',cc:1};
    json_array.push(ary);

    [json_array]=mode_read_session();//讀取session

    console.log( json_array );
    if( json_array.length >0 ){
        console.log( '讀取session記錄成功='+json_array.length );
    }else{
        console.log( '讀取session記錄失敗' );
        //throw '失敗';
    }

    var thread_all=[];
    [thread_all]=mode_read_html();
    //console.log( thread_all );
    if( thread_all.length >0 ){
        console.log( '目前網頁上的文章數量=',thread_all.length );//
    }else{
        throw '失敗';
    }
    //判斷目前網頁的模式
    switch( thread_all.length ){
        case 1:
            console.log( '回應模式=',thread_all.length );//
            break;
        case 15:
            console.log( '首頁模式=',thread_all.length );//
            var qwq='';
            [json_array,qwq]=mode_1(thread_all,json_array);//比對紀錄
            mode_save_session(json_array);//存進session
            break;
        default:
            console.log( '[x]例外=',thread_all.length );//
    }





    $('#contents').before("<div id='id190214'>id190214</div>");
    $('#id190214').css({
        'background':'rgb(200,200,200)',
        'color':'rgb(100,100,100)',
        'text-align':'initial',
    });




}//ff
//

function mode_read_html(){
    var str='';
    var cc=0;
    var thread_all=[];
    var ary=[];
    $('#contents').find('.thread').each(function(a,b){//讀取目前網頁上文章編號
        str=$(b).attr('data-no');
        //ary=[{nn:str,cc:1}];
        thread_all.push(str);
    });
    return [thread_all];

}//ff
//

function mode_read_session(){
    var session='';
    if(window.localStorage){
        session=window.sessionStorage.poi190214;
        if( session.length >0 ){
            console.log( 'session長度='+session.length );
            //
            var json_array=[];
            try{
                json_array=JSON.parse( window.sessionStorage.poi190214 );//解析json字串
                //console.log( 'json_array=',json_array );
            }
            catch(e){
                console.log( 'try=',e );
            }
        }
    }else{
    }
    //
    return [json_array];
}


function mode_save_session(a,b){
    console.log( 'mode_save_session' );//
    var json_array=a;//舊紀錄
    var json_array2=[];








    //
    if(window.localStorage){
        //儲存紀錄
        var json_str=JSON.stringify(json_array); //建立json字串
        console.log( json_str );
        window.sessionStorage.poi190214=json_str;//存到session
        //console.log( window.sessionStorage );
    }else{
    }
}//ff
//
function mode_1(a,b){
    console.log( 'mode_1' );//
    var thread_all=a;
    var json_array=b;
    //
    //console.log( json_array );//
    for(var i=0;i<json_array.length;i++){
        //console.log( json_array[i].nn );//
    }
    //從json_array產生一個只有文章編號的陣列
    var json_array_nn = json_array.map(function(item, index, array){
        return item.nn;
    });
    //console.log( json_array );//
    //console.log( json_array_nn );//
    //console.log( json_array_nn[0] );//

    var ary=[];
    var FFF='';
    thread_all.forEach(function(item,index,array){
        //console.log( index,item );//

        FFF=json_array_nn.indexOf(item);
        if( FFF >=0 ){
            console.log( '舊',item,FFF );//
            //舊資料 加count數
            json_array[FFF].cc++;
            //console.log( json_array[FFF] );//

        }else{
            console.log( '新',item,FFF );//
            //把新資料加進json_array
            ary={
                nn:item,
                cc:1,
                tt:Date.now(),
            };
            json_array.push(ary);
        }
    });
    //console.log( json_array );//
    //更新json_array_nn
    json_array_nn = json_array.map(function(item, index, array){
        return item.nn;
    });
    //json_array_nn比大小 //排序 //大的在前
    json_array_nn.sort(function(a,b){
        return (a - b)*(-1);//
    });
    //console.log( json_array_nn );//
    //json_array_nn剪裁 //瘦身
    json_array_nn=json_array_nn.slice(0, 100);//
    //console.log( json_array_nn );//
    //


    var json_array2=[];
    json_array.forEach(function(item,index,array){
        //console.log( item );//
        //在json_array_nn尋找相同的編號 並回傳index
        var xx21 = json_array_nn.findIndex(function(item2, index2, array2){
            return (item2 == item.nn);
        });
        //console.log( xx21 );//陣列index位置
        //有找到
        if(xx21>=0){
            json_array2[xx21]=item;//依照排序放進新陣列
        }

    });
    console.log( json_array2 );//
    json_array=json_array2;//取代原本的陣列
    json_array2=[];//清空

    return [json_array,'ouo'];
}//ff
//
function poi_old(){
    console.log( 'poi' );
    $('.bar_reply').html('123');
    $('.bar_reply').css({
        'background':'rgb(200,200,200)',
        'color':'rgb(100,100,100)',
        'text-align':'initial',
    });
}//ff
//





/*

*/





QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址