Greasy Fork

Greasy Fork is available in English.

卡特個人化功能

RT

当前为 2019-12-06 提交的版本,查看 最新版本

// ==UserScript==
// @name         卡特個人化功能
// @namespace    http://tampermonkey.net/
// @version      0.2.00
// @description  RT
// @author       SmallYue1
// @match        https://kater.me*
// @match        https://kater.me/*
// @require      https://code.jquery.com/jquery-3.4.1.min.js
// @require      http://greasyfork.icu/scripts/14208-datejs/code/Datejs.js?version=89671
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

var _自訂首頁,_收藏文章,_黑名單,_關圖;

var BlackList,BlockList,FavoriteList,User_Settings;

function 覆寫樓層(PostStream_Item,Li_User)
{
    if(_關圖)
    {
        if($(Li_User.parentNode).find("#ClosePictures_Icon").length === 0)
        {
            var Li_ClosePictures = document.createElement('li');
            var Btn_ClosePictures = document.createElement('button');
            var Icon_ClosePictures = document.createElement('i');
            var src = Li_User.parentNode.firstElementChild.firstElementChild.firstElementChild.firstElementChild.href;
            Li_ClosePictures.setAttribute("class","TextEditor-toolbar");
            Btn_ClosePictures.setAttribute("class","Button Button--icon Button--link hasIcon");
            Icon_ClosePictures.setAttribute("id","ClosePictures_Icon");
            try{
                if(PostStream_Item.getAttribute("haschild"))
                {
                    Icon_ClosePictures.setAttribute("class","icon fas fa-eye-slash Button-icon");
                }
                else
                {
                    Icon_ClosePictures.setAttribute("class","icon fas fa-eye Button-icon");
                }
            }
            catch(e)
            {
            }
            Li_User.parentNode.appendChild(Li_ClosePictures);
            Li_ClosePictures.appendChild(Btn_ClosePictures);
            Btn_ClosePictures.appendChild(Icon_ClosePictures);
            Li_ClosePictures.addEventListener("click",function(e) {
                var Iframes = $(PostStream_Item).find("iframe");
                var Imgs = $(PostStream_Item).find("img[class != 'Avatar PostUser-avatar']");
                var icon = this.firstElementChild.firstElementChild;
                var href = this.parentNode.firstElementChild.firstElementChild.firstElementChild.firstElementChild.href;

                if(icon.getAttribute("class") !== "icon fas fa-eye-slash Button-icon")
                {
                    //關圖
                    icon.setAttribute("class","icon fas fa-eye-slash Button-icon");
                    for(var Iframe of Iframes)
                    {
                        Iframe.setAttribute("style_pre",Iframe.getAttribute("style"));
                        Iframe.setAttribute("style","display:none");
                        Iframe.setAttribute("src_pre",Iframe.getAttribute("src"));
                        Iframe.setAttribute("src","");
                    }
                    for(var Img of Imgs)
                    {
                        Img.setAttribute("style_pre",Img.getAttribute("style"));
                        Img.setAttribute("style","display:none");
                        Img.setAttribute("src_pre",Img.getAttribute("src"));
                        Img.setAttribute("src","");
                    }
                }
                else
                {
                    //開圖
                    icon.setAttribute("class","icon fas fa-eye Button-icon");
                    for(Iframe of Iframes)
                    {
                        Iframe.setAttribute("style",Iframe.getAttribute("style_pre"));
                        Iframe.setAttribute("src",Iframe.getAttribute("src_pre"));
                    }
                    for(Img of Imgs)
                    {
                        Img.setAttribute("style",Img.getAttribute("style_pre"));
                        Img.setAttribute("src",Img.getAttribute("src_pre"));
                    }

                }
            },false);
        }
    }
    if(_黑名單)
    {
        if($(Li_User.parentNode).find("#BlckList_Icon").length === 0)
        {
            var Li_BlackList = document.createElement('li');
            var Btn_BlackList = document.createElement('button');
            var Icon_BlackList = document.createElement('i');
            var href = Li_User.parentNode.firstElementChild.firstElementChild.firstElementChild.firstElementChild.href;
            Li_BlackList.setAttribute("class","TextEditor-toolbar");
            Btn_BlackList.setAttribute("class","Button Button--icon Button--link hasIcon");
            Icon_BlackList.setAttribute("id","BlckList_Icon");
            if(BlackList.indexOf(href) === -1)
            {
                Icon_BlackList.setAttribute("class","icon fas fa-user Button-icon");
                Li_User.parentNode.parentNode.parentNode.childNodes[2].setAttribute("style","");
            }
            else if(BlackList.indexOf(href) !== -1)
            {
                Icon_BlackList.setAttribute("class","icon fas fa-user-slash Button-icon");
                Li_User.parentNode.parentNode.parentNode.childNodes[2].setAttribute("style","display:none;");
            }
            Li_User.parentNode.appendChild(Li_BlackList);
            Li_BlackList.appendChild(Btn_BlackList);
            Btn_BlackList.appendChild(Icon_BlackList);
            Li_BlackList.addEventListener("click",function(e) {
                var icon = this.firstElementChild.firstElementChild;
                var href = this.parentNode.firstElementChild.firstElementChild.firstElementChild.firstElementChild.href;
                if(icon.getAttribute("class") !== "icon fas fa-user-slash Button-icon")
                {
                    //新增黑名單
                    if(BlackList.indexOf(href) === -1)
                    {
                        BlackList.push(href)
                        GM_setValue("Kater_BlackList", BlackList);
                        this.parentNode.parentNode.parentNode.childNodes[2].setAttribute("style","display:none;");
                    }
                    icon.setAttribute("class","icon fas fa-user-slash Button-icon");
                }
                else
                {
                    //解除黑名單
                    if(BlackList.indexOf(href) !== -1)
                    {
                        BlackList.splice(BlackList.indexOf(href), 1);
                        GM_setValue("Kater_BlackList", BlackList);
                        this.parentNode.parentNode.parentNode.childNodes[2].setAttribute("style","");
                    }
                    icon.setAttribute("class","icon fas fa-user Button-icon");
                }
            },false);
        }
    }
}

function 覆寫Ul(Ul,Data_Id)
{
    var Li = document.createElement('li');
    Li.innerHTML = `<button class=" hasIcon" type="button" title="收藏"><i></i><span class="Button-label">收藏</span></button>`;
    Li.setAttribute("class","item-subscription");
    Li.setAttribute("data-id",Data_Id);
    if(FavoriteList.indexOf(Data_Id) === -1)
    {
        Li.firstElementChild.firstElementChild.setAttribute("class","icon far fa-star Button-icon");
    }
    else if(FavoriteList.indexOf(Data_Id) !== -1)
    {
        Li.firstElementChild.firstElementChild.setAttribute("class","icon fas fa-star Button-icon");
    }
    Ul.insertBefore(Li,Ul.firstElementChild);
    Li.addEventListener("click",function(){
        var Data_Id = this.getAttribute("data-id");
        if(FavoriteList.indexOf(Data_Id) === -1)
        {
            //新增收藏
            FavoriteList.push(Data_Id)
            GM_setValue("Kater_FavoriteList", FavoriteList);
            this.firstElementChild.firstElementChild.setAttribute("class","icon fas fa-star Button-icon");
        }
        else if(FavoriteList.indexOf(Data_Id) !== -1)
        {
            //解除收藏
            FavoriteList.splice(FavoriteList.indexOf(Data_Id), 1);
            GM_setValue("Kater_FavoriteList", FavoriteList);
            this.firstElementChild.firstElementChild.setAttribute("class","icon far fa-star Button-icon");
        }
    },false);
}

function 新增腳本工具列按鈕()
{
    if($("#Script_Btn").length === 0)
    {
        var Ul = $("ul.Header-controls")[1];
        var Li_Setting = document.createElement('li');
        Li_Setting.innerHTML = `<div class="ButtonGroup Dropdown dropdown SessionDropdown itemCount2"><button class=\"Dropdown-toggle Button Button--flat\" data-toggle=\"dropdown\"><i class=\"icon fas fa-cogs Button-icon\"></i><span>腳本設定</span></button><ul class="Dropdown-menu dropdown-menu Dropdown-menu--right"></ul></div>`;
        Ul.appendChild(Li_Setting);
        新增功能(Li_Setting.firstElementChild.lastElementChild);
        Li_Setting.setAttribute("id","Script_Btn");
        Li_Setting.setAttribute("class","item-session");
    }
}

function 新增功能(Ul)
{
    if(_自訂首頁)自訂首頁(Ul);
    if(_收藏文章)收藏文章(Ul);
    卡特個人化功能(Ul);
}

function 卡特個人化功能(Ul)
{
    var Li = document.createElement('li');
    Ul.appendChild(Li);
    Li.innerHTML = `<button class=" hasIcon" type="button" title="卡特個人化功能"><i class="icon fas fa-cog Button-icon"></i><span class="Button-label">卡特個人化功能</span></button>`;
    Li.setAttribute("class","item-profile");
    Li.addEventListener("click",() => {建立卡特個人化功能頁面()});
}

function 收藏文章(Ul)
{
    var Li = document.createElement('li');
    Ul.appendChild(Li);
    Li.innerHTML = `<button class=" hasIcon" type="button" title="收藏文章"><i class="icon fas fa-star Button-icon"></i><span class="Button-label">收藏文章</span></button>`;
    Li.setAttribute("class","item-profile");
    Li.addEventListener("click",() => {建立收藏頁面()});
}

function 自訂首頁(Ul)
{
    var Li = document.createElement('li');
    Ul.appendChild(Li);
    Li.innerHTML = `<button class=" hasIcon" type="button" title="自訂首頁"><i class="icon fas fa-user-edit Button-icon"></i><span class="Button-label">自訂首頁</span></button>`;
    Li.setAttribute("class","item-profile");
    Li.addEventListener("click",() => {取得Tag資料()});
}

function 建立卡特個人化功能頁面()
{
    document.body.innerHTML = "<body></body>";
    var Div = document.createElement('div');
    var Tags = document.createElement('ul');
    新增卡特個人化功能頁面中的按鈕(Div,Tags,"自訂首頁","fas fa-user-edit",_自訂首頁);
    新增卡特個人化功能頁面中的按鈕(Div,Tags,"收藏文章","fas fa-star",_收藏文章);
    新增卡特個人化功能頁面中的按鈕(Div,Tags,"黑名單","fas fa-user-slash",_黑名單);
    新增卡特個人化功能頁面中的按鈕(Div,Tags,"關圖","fas fa-eye-slash",_關圖);
    document.body.appendChild(Div);
    Div.appendChild(Tags);
    var Back_To_Kater = document.createElement('div');
    Back_To_Kater.setAttribute("style","text-align:center;width:100%;height:100%;");
    Back_To_Kater.innerHTML = `<div style="margin:0 auto;"><a href="https://kater.me/"><button class="Button Button--primary IndexPage-newDiscussion hasIcon" itemclassname="App-primaryControl" type="button" title="回到卡特"><i class="icon fas fa-edit Button-icon"></i><span class="Button-label">回到卡特</span></button></a></div>`;
    document.body.appendChild(Back_To_Kater);
}

function 新增卡特個人化功能頁面中的按鈕(Div,Tags,Name,Icon,Value)
{
    var Text_Color,Icon_Color;
    Div.setAttribute("style","max-width:100%;height:100%;");
    Tags.setAttribute("class","Dropdown-menu dropdown-menu");
    Tags.setAttribute("style","width:;display:block;position:static;");
    var Tag_Iteam = document.createElement('li');
    if(Value)
    {
        Icon_Color = "#111";
        Text_Color = "#111";
    }
    else
    {

        Icon_Color = "#b7b7b7";
        Text_Color = "#b7b7b7";
    }
    Tag_Iteam.innerHTML = `<a class="TagLinkButton hasIcon" style="text-align:center;width:100%;color:${Text_Color};"><i class="icon ${Icon} Button-icon" style="float:initial;color:${Icon_Color};"></i>${Name}</a>`;
    Tag_Iteam.setAttribute("name",Name);
    Tag_Iteam.setAttribute("value",Value);
    Tag_Iteam.setAttribute("style","max-width:100%;height:100%;");
    Tag_Iteam.addEventListener("click",(e) => {個人化頁面按鈕點擊事件(e);},false);
    Tags.appendChild(Tag_Iteam);
}

function 個人化頁面按鈕點擊事件(e)
{
    var Target = $(e.target).parents("li")[0];
    var Name = Target.getAttribute("name");
    var Value = Target.getAttribute("value");
    var Text_Color,Icon_Color;
    if(Value === "true")
    {
        變更使用者設定(Name,Value)
        GM_setValue("Kater_User_Settings", [_自訂首頁,_收藏文章,_黑名單,_關圖]);
        Target.setAttribute("value",false);
        Icon_Color = "#b7b7b7";
        Text_Color = "#b7b7b7";
    }
    else
    {
        變更使用者設定(Name,Value)
        GM_setValue("Kater_User_Settings", [_自訂首頁,_收藏文章,_黑名單,_關圖]);
        Target.setAttribute("value",true);
        Icon_Color = "#111";
        Text_Color = "#111";
    }
    Target.firstElementChild.setAttribute("style",`text-align:center;width:100%;color:${Text_Color};`);
    Target.firstElementChild.firstElementChild.setAttribute("style",`float:initial;color:${Icon_Color};`);
}

function 變更使用者設定(Name,Value)
{
    switch (Name) {
        case "自訂首頁":
            if(Value === "true")
            {
                _自訂首頁 = false;
            }
            else
            {
                _自訂首頁 = true;
            }
            break;
        case "收藏文章":
            if(Value === "true")
            {
                _收藏文章 = false;
            }
            else
            {
                _收藏文章 = true;
            }
            break;
        case "黑名單":
            if(Value === "true")
            {
                _黑名單 = false;
            }
            else
            {
                _黑名單 = true;
            }
            break;
        case "關圖":
            if(Value === "true")
            {
                _關圖 = false;
            }
            else
            {
                _關圖 = true;
            }
            break;
        default:
            console.log("變更使用者設定失敗!");
            console.log(Name+Value);
    }
}

async function 建立收藏頁面()
{
    var Ul,Data,Data_Id,Article_Card,Li_Display;
    document.body.innerHTML = "<body></body>";
    var Back_To_Kater = document.createElement('div');
    Back_To_Kater.setAttribute("style","text-align:center;width:100%;height:auto;position:fixed;display:block;z-index:5;");
    Back_To_Kater.innerHTML = `<div class="header-secondary" style="width:100%"><a href="https://kater.me/"><button itemclassname="App-primaryControl" type="button" title="回到卡特" style="width:100%" class="Button Button--primary IndexPage-newDiscussion hasIcon"><span class="Button-label">回到卡特</span></button></a></div>`;
    document.body.appendChild(Back_To_Kater);
    var Article_List = document.createElement('ul');
    document.body.appendChild(Article_List);
    Article_List.setAttribute("class","PostsUserPage-list");
    Article_List.setAttribute("style","width:80%;padding-top:45px;padding-bottom:45px;padding-left:20%;");
    for(var Favorite of FavoriteList)
    {
        Data = await 取得收藏資料(Favorite);
        Article_Card = document.createElement('li');
        Article_List.appendChild(Article_Card);
        Article_Card.innerHTML = `<div class="PostsUserPage-discussion">於 <a href="https://kater.me/d/${Data.discussions_id}/${Data.floor}">${Data.title}</a></div>
                                      <article class="Post  CommentPost">
                                              <div>
                                                  <header class="Post-header">
                                                      <ul>
                                                          <li class="item-user">
                                                              <div class="PostUser">
                                                                  <h3><a href="https://kater.me/u/${Data.uid}"><img class="Avatar PostUser-avatar" src="${Data.avatarUrl}"><span class="username">${Data.username}</span></a></h3>
                                                                  <ul class="badges">
                                                                  </ul>
                                                              </div>
                                                          </li>
                                                          <li class="item-meta">
                                                              <div class="Dropdown PostMeta">
                                                                  <a class="Dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                                                      <time pubdate="true" datetime="${Data.time}" title="${Date.parse(Data.time)}" data-humantime="true">${Date.parse(Data.time).toString("yyyy/M/d HH:mm:ss")}</time>
                                                                  </a>
                                                              </div>
                                                          </li>
                                                          <li class="TextEditor-toolbar">
                                                              <button class="Button Button--icon Button--link hasIcon">
                                                                  <i class="icon far fa-eye-slash Button-icon"></i>
                                                              </button>
                                                          </li>
                                                      </ul>
                                                  </header>
                                                  <div class="Post-body" style = "display:none;">${Data.contentHtml}</div>
                                                  <aside class="Post-actions">
                                                      <ul></ul>
                                                  </aside>
                                              </div>
                                          </article>`;
        Ul = Article_Card.lastElementChild.firstElementChild.lastElementChild.firstElementChild;
        Data_Id = Data.data_id;
        await 覆寫Ul(Ul,Data_Id);
        Ul.firstElementChild.removeAttribute("class");
        Ul.firstElementChild.firstElementChild.setAttribute("class","Dropdown-toggle Button Button--icon Button--flat");
        Ul.firstElementChild.addEventListener("click",function(){
            var Data_Id = this.getAttribute("data-id");
            $(this).parents("li")[0].setAttribute("style","display:none;");
        },false);
        Li_Display = Article_Card.lastElementChild.firstElementChild.firstElementChild.firstElementChild.lastElementChild;
        Li_Display.addEventListener("click",function() {
            var icon = this.firstElementChild.firstElementChild;
            if(icon.getAttribute("class") !== "icon far fa-eye-slash Button-icon")
            {
                this.parentNode.parentNode.parentNode.children[1].setAttribute("style","display:none;");
                icon.setAttribute("class","icon far fa-eye-slash Button-icon");
            }
            else
            {
                this.parentNode.parentNode.parentNode.children[1].setAttribute("style","");
                icon.setAttribute("class","icon far fa-eye Button-icon");
            }
        },false);
    }

}

async function 取得收藏資料(Favorite)
{
    try{
        return new Promise((resolve,reject) => {
            var settings = {
                "url":"https://kater.me/api/posts/"+Favorite,
                "method":"GET",
                "headers":{
                    "X-CSRF-TOKEN":app.data.session.csrfToken
                },
                success:function(e){
                    for(var item of e.included)
                    {
                        if(item.type === "discussions")
                        {
                            var title = item.attributes.title;
                            var discussions_id = item.id;
                        }
                    }
                    var Data = {
                        "data_id":e.data.id,
                        "floor":e.data.attributes.number,
                        "time":e.data.attributes.createdAt,
                        "contentHtml":e.data.attributes.contentHtml,
                        "username":e.included[0].attributes.username,
                        "avatarUrl":e.included[0].attributes.avatarUrl,
                        "uid":e.included[0].id,
                        "discussions_id":discussions_id,
                        "title":title
                    };
                    resolve(Data);
                },
                error:function(e){
                    console.log(e);
                    reject("Error");
                }
            }
            $.ajax(settings);
        });
    }
    catch(e)
    {

    }
}

function 取得Tag資料()
{
    var datas = [],datas_has_parent = [];
    var settings = {
        "url":"https://kater.me/api/tags",
        "method":"GET",
        "headers":{
            "X-CSRF-TOKEN":app.data.session.csrfToken
        },
        success:function(e){
            for(var data of e.data)
            {
                try{
                    if(data.relationships.parent.data.id !== "")
                    {
                        var Tempt2 = {
                            "id":data.id,
                            "position":data.attributes.position,
                            "name":data.attributes.name,
                            "icon":data.attributes.icon,
                            "color":data.attributes.color,
                            "parent_id":data.relationships.parent.data.id
                        };
                        datas_has_parent.push(Tempt2);
                    }
                }
                catch(d)
                {
                    var Tempt = {
                        "id":data.id,
                        "position":data.attributes.position,
                        "name":data.attributes.name,
                        "icon":data.attributes.icon,
                        "color":data.attributes.color,
                        "parent_id":""
                    };
                    datas.push(Tempt);
                }
            }
            建立自訂首頁頁面(datas,datas_has_parent);
        },
        error:function(e){
            console.log(e);
        }
    }
    try{
        $.ajax(settings);
    }
    catch(e)
    {

    }
}

function 建立自訂首頁頁面(datas,datas_has_parent)
{
    document.body.innerHTML = "<body></body>";
    var Div = document.createElement('div');
    var Tags = document.createElement('ul');
    var Text_Color,Icon_Color;
    Div.setAttribute("style","max-width:100%;height:100%;");
    Tags.setAttribute("class","Dropdown-menu dropdown-menu");
    Tags.setAttribute("style","width:;display:block;position:static;");
    datas.sort(function (a, b) {
        return a.position < b.position ? -1 : 1;
    });
    datas_has_parent.sort(function (a, b) {
        return a.position > b.position ? -1 : 1;
    });
    for(var data of datas)
    {
        var Tag_Iteam = document.createElement('li');
        if(BlockList.indexOf(data.name) === -1)
        {
            Icon_Color = data.color;
            Text_Color = "#111";
        }
        else if(BlockList.indexOf(data.name) !== -1)
        {

            Icon_Color = "#b7b7b7";
            Text_Color = "#b7b7b7";
        }
        Tag_Iteam.innerHTML = `<a class="TagLinkButton hasIcon" style="text-align:center;width:100%;color:${Text_Color};"><i class="icon ${data.icon} Button-icon" style="float:initial;color:${Icon_Color};"></i>${data.name}</a>`;
        Tag_Iteam.setAttribute("id",data.id);
        Tag_Iteam.setAttribute("name",data.name);
        Tag_Iteam.setAttribute("color",data.color);
        Tag_Iteam.setAttribute("style","max-width:100%;height:100%;");
        Tag_Iteam.addEventListener("click",(e) => {自訂首頁頁面按鈕點擊事件(e);},false);
        Tags.appendChild(Tag_Iteam);
    }
    document.body.appendChild(Div);
    Div.appendChild(Tags);
    for(data of datas_has_parent)
    {
        var Parent_Tag_Iteam = document.getElementById(data.parent_id);
        Tag_Iteam = document.createElement('li');
        if(BlockList.indexOf(data.name) === -1)
        {
            Icon_Color = data.color;
            Text_Color = "#111";
        }
        else
        {

            Icon_Color = "#b7b7b7";
            Text_Color = "#b7b7b7";
        }
        Tag_Iteam.innerHTML = `<a class="TagLinkButton hasIcon child" style = "text-align:center;width:100%;color:${Text_Color};max-width:100%;box-sizing:border-box;padding-left:50px;margin-left:0px;"><i class="icon ${data.icon} Button-icon" style="float:initial;color:${Icon_Color};"></i>${data.name}</a>`;
        Tag_Iteam.setAttribute("id",data.id);
        Tag_Iteam.setAttribute("name",data.name);
        Tag_Iteam.setAttribute("color",data.color);
        Tag_Iteam.setAttribute("style","max-width:100%;height:100%;");
        Tag_Iteam.addEventListener("click",(e) => {自訂首頁頁面按鈕點擊事件(e);},false);
        insertAfter(Tag_Iteam,Parent_Tag_Iteam);
    }
    var Back_To_Kater = document.createElement('div');
    Back_To_Kater.setAttribute("style","text-align:center;width:100%;height:100%;");
    Back_To_Kater.innerHTML = `<div style="margin:0 auto;"><a href="https://kater.me/"><button class="Button Button--primary IndexPage-newDiscussion hasIcon" itemclassname="App-primaryControl" type="button" title="回到卡特"><i class="icon fas fa-edit Button-icon"></i><span class="Button-label">回到卡特</span></button></a></div>`;
    document.body.appendChild(Back_To_Kater);
}

function 自訂首頁頁面按鈕點擊事件(e)
{
    var Target = $(e.target).parents("li")[0];
    var Block_Text = Target.getAttribute("name");
    var Text_Color,Icon_Color;
    if(BlockList.indexOf(Block_Text) === -1)
    {
        //新增屏蔽
        BlockList.push(Block_Text)
        GM_setValue("Kater_BlockList", BlockList);
        Icon_Color = "#b7b7b7";
        Text_Color = "#b7b7b7";
    }
    else
    {
        //解除屏蔽
        BlockList.splice(BlockList.indexOf(Block_Text), 1);
        GM_setValue("Kater_BlockList", BlockList);
        Icon_Color = Target.getAttribute("color");
        Text_Color = "#111";
    }
    Target.firstElementChild.setAttribute("style",`text-align:center;width:100%;color:${Text_Color};`);
    Target.firstElementChild.firstElementChild.setAttribute("style",`float:initial;color:${Icon_Color};`);
}

function insertAfter(newE,targetE)
{
    var parentE = targetE.parentNode;

    if(parentE.lastChild == targetE)
    {
        parentE.appendChild(newE);
    }else
    {
        parentE.insertBefore(newE,targetE.nextSibling);
    }
}

if(!GM_getValue("Kater_User_Settings"))
{
    [_自訂首頁,_收藏文章,_黑名單,_關圖] = [true,true,true,false];
    GM_setValue("Kater_User_Settings", [true,true,true,false]);
    console.log("偵測到初次使用腳本 O_Ob");
}
else
{
    [_自訂首頁,_收藏文章,_黑名單,_關圖] = GM_getValue("Kater_User_Settings");
    console.log([_自訂首頁,_收藏文章,_黑名單,_關圖]);
}

if(_黑名單)
{
    if(!GM_getValue("Kater_BlackList"))
    {
        BlackList = [];
        GM_setValue("Kater_BlackList", []);
        console.log("偵測到初次使用腳本 O_Ob");
    }
    else
    {
        BlackList = GM_getValue("Kater_BlackList");
        console.log(BlackList);
    }
}

if(_自訂首頁)
{
    if(!GM_getValue("Kater_BlockList"))
    {
        BlockList = [];
        GM_setValue("Kater_BlockList", []);
        console.log("偵測到初次使用腳本 O_Ob");
    }
    else
    {
        BlockList = GM_getValue("Kater_BlockList");
        console.log(BlockList);
    }
}

if(_收藏文章)
{
    if(!GM_getValue("Kater_FavoriteList"))
    {
        FavoriteList = [];
        GM_setValue("Kater_FavoriteList", []);
        console.log("偵測到初次使用腳本 O_Ob");
    }
    else
    {
        FavoriteList = GM_getValue("Kater_FavoriteList");
        console.log(FavoriteList);
    }
}

var callback = function (records){
    records.map(function(record){
        if(record.addedNodes.length != 0)
        {
            setTimeout(() => {
                if(location.href.indexOf("/d/") !== -1)
                {
                    var Article = $(record.addedNodes[0]).find("article.CommentPost")[0];
                    if(Article !== undefined)
                    {
                        if(_收藏文章)
                        {
                            var Ul = Article.firstElementChild.children[2].firstElementChild.lastElementChild.firstElementChild.lastElementChild;
                            if(Ul !== undefined)
                            {
                                if(Ul.firstElementChild.className !== "item-subscription")
                                {
                                    var Data_Id = Article.parentElement.getAttribute("data-id");
                                    覆寫Ul(Ul,Data_Id)
                                }
                            }
                        }
                        if((_黑名單) || (_關圖))
                        {
                            var Li_User = Article.firstElementChild.firstElementChild.firstElementChild.firstElementChild;
                            if(Li_User !== undefined)
                            {
                                var PostStream_Item = $(Li_User).parents("div.PostStream-item")[0];
                                if(_關圖)
                                {
                                    var Iframes = $(PostStream_Item).find("iframe");
                                    var Imgs = $(PostStream_Item).find("img[class != 'Avatar PostUser-avatar']");
                                    for(var Iframe of Iframes)
                                    {
                                        if(Iframe.getAttribute("style") !== "display:none")
                                        {
                                            PostStream_Item.setAttribute("haschild",true);
                                            Iframe.setAttribute("style_pre",Iframe.getAttribute("style"));
                                            Iframe.setAttribute("style","display:none");
                                            Iframe.setAttribute("src_pre",Iframe.getAttribute("src"));
                                            Iframe.setAttribute("src","");
                                        }
                                    }
                                    for(var Img of Imgs)
                                    {
                                        if(Img.getAttribute("style") !== "display:none")
                                        {
                                            PostStream_Item.setAttribute("haschild",true);
                                            Img.setAttribute("style_pre",Img.getAttribute("style"));
                                            Img.setAttribute("style","display:none");
                                            Img.setAttribute("src_pre",Img.getAttribute("src"));
                                            Img.setAttribute("src","");
                                        }
                                    }
                                }
                                覆寫樓層(PostStream_Item,Li_User);
                            }
                        }
                    }
                }
                else
                {
                    var Div = $(record.addedNodes[0]).find("div.DiscussionListItem")[0];
                    if(Div !== undefined)
                    {
                        if(_自訂首頁)
                        {
                            var Tags = Div.lastElementChild.children[2].lastElementChild.firstElementChild.firstElementChild.children;
                            for(var Tag of Tags)
                            {
                                if(BlockList.indexOf(Tag.innerText.replace(/ /g,"")) !== -1)
                                {
                                    Tag.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.setAttribute("style","display:none;");
                                }
                            }
                        }
                        if(_黑名單)
                        {
                            var User = Div.lastElementChild.firstElementChild;
                            if(BlackList.indexOf(User.href) !== -1)
                            {
                                User.parentElement.parentElement.parentElement.setAttribute("style","display:none;");
                            }
                        }
                    }

                }
            },50);
        }
    });
};

var mo = new MutationObserver(callback);

var option = {
    'childList': true,
    'subtree' : true
};

mo.observe(document.getElementById("content"), option);

$("document").ready(
    function()
    {
        'use strict';
        setTimeout(() => 新增腳本工具列按鈕(),100);
        // Your code here...
    }
);