Greasy Fork is available in English.

FB 贊助之殺手 (FB Sponsored Killer)

刪除動態牆跟右上角贊助還有關鍵字(支持所有左到右的語言) kill wall sponsored, suggested for you, ad and keyword for TW、JP、KR、UK(no need setting) or other countries(need manual setting)

Від 25.07.2022. Дивіться остання версія.

// ==UserScript==
// @name         FB 贊助之殺手 (FB Sponsored Killer)
// @name:en      FB Sponsored Killer
// @namespace    http://tampermonkey.net/
// @version      5.5
// @description  刪除動態牆跟右上角贊助還有關鍵字(支持所有左到右的語言) kill wall sponsored, suggested for you, ad and keyword for TW、JP、KR、UK(no need setting) or other countries(need manual setting)
// @description:en  kill wall sponsored, suggested for you, ad and keyword for TW、JP、KR、UK(no need setting)  or other countries(need manual setting)
// @author       貓咪不作戰
// @match        https://*.facebook.com/*
// @run-at       document-idle
// @grant        GM_registerMenuCommand
// @license MIT
// ==/UserScript==

(function () {
    var isMobile;
    /*if(navigator.userAgentData){
         isMobile = navigator.userAgentData.mobile;
    }else{
        window.mobileAndTabletCheck = function () {
            let check = false;
            (function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
            return check;
        };
        isMobile= window.mobileAndTabletCheck()
    }*/
    isMobile=false
    'use strict';
    function log(msg) {
        if (false) {
            console.log(msg);
        }
    }
    //setInterval(kill, 500);
    var request;
    var db;
    var init = false;
    var transaction, objectStore;
    var forYouPush, wallSup, wallWord, autoKillOld30,violentMode;
    var suggested, sponsored, wordKill;
    var killInterval;

    var fbkill_checkBox1
    var fbkill_checkBox2
    var fbkill_checkBox3
    var fbkill_checkBox4
    var fbkill_checkBox5
    var fbkill_textarea1
    var fbkill_textarea2
    var fbkill_textarea3

    var logOutStartObserve=false
    var isLoaded = false;
    if (isLoaded) return
    function kill() {
        log("kill")
        //右上角廣告
        var d1 = document.querySelector("span > div > .l9j0dhe7 > .sj5x9vvc")
        if (d1 != null) {
            d1.style.display = "none"
            if (d1.parentNode != null && d1.parentNode.parentNode != null) {
                d1.parentNode.parentNode.style.display = "none"
            }
        }
        killBy();
        function killBy() {
            let tagz;
            tagz = document.querySelectorAll("div[role=feed] b:not([fbkill_checked]),div[role=feed] div:not([fbkill_checked]),div[role=feed] span:not([fbkill_checked])");
            for (let j = 0; j < tagz.length; j++) {
                let d = tagz[j]
                XDivOrB(d)
            }
        }
    }
    function destroyTopDiv(e) {
        //log("destroyTopDiv")
        if (e.parentNode != null) {
            if (isMobile) {
                if (e.tagName.toLowerCase() == "article") {
                    if (e.style.display != "none") {
                        e.style.display = "none"
                        e.remove()
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return destroyTopDiv(e.parentNode);
                }
            } else {
                if (e.getAttribute("role") == "article") {
                    if (e.parentNode.style.display != "none") {
                        e.parentNode.style.display = "none"
                        e.parentNode.parentNode.remove();
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return destroyTopDiv(e.parentNode);
                }
            }
        }
    }
    function destroyTopDivSimple(e) {
        //log(e)
        if (e.parentNode != null) {
            if (isMobile) {
                if (e.tagName.toLowerCase() == "article") {
                    if (e.parentNode.style.display != "none") {
                        e.parentNode.style.display = "none"
                        e.parentNode.remove();
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return destroyTopDiv(e.parentNode);
                }
            } else {
                if (e.getAttribute("role") == "article") {
                    if (e.parentNode.style.display != "none") {
                        e.parentNode.style.display = "none"
                        e.parentNode.parentNode.removeChild(e.parentNode)
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return destroyTopDiv(e.parentNode);
                }
            }
        }
    }
    function XDivOrB(x) {
        let innerText= x.innerText
        let isArticalPart=false
        if(x.querySelector("[data-ad-preview]")!=null || x.closest("[data-ad-preview]") !=null ){
            isArticalPart=true
            log("this is artical")
        }
        if (!isArticalPart && forYouPush) {
            let suggestedContain1 = false
            for (let k1 = 0; k1 < suggested.length; k1++) {
                if (suggested[k1].length != 0 && stringLike(innerText,suggested[k1])) {
                    suggestedContain1 = true
                    break
                }
            }
            if (suggestedContain1) {
                x.setAttribute("fbkill_checked", "");
                if (x.children.length == 0) {
                    if (destroyTopDiv(x)) {
                        log("刪除為你推薦(Kill suggested)")
                        log(x)
                        log(innerText)
                        window.test01 = x
                    }
                }
            }
        }
        //console.log(wallSup)
        if (!isArticalPart && wallSup) {
            //console.log(sponsored);
            let sponsoredContain1 = false
            for (let k2 = 0; k2 < sponsored.length; k2++) {
                let s=sponsored[k2]
                if (sponsored[k2].length != 0 && stringLike(innerText,sponsored[k2])) {
                    sponsoredContain1 = true
                    break
                }
            }
            if (sponsoredContain1) {
                x.setAttribute("fbkill_checked", "");
                //x.innerHTML="刪除"
                if (destroyTopDiv(x)) {
                    log("刪除贊助(Kill sponsored) tag:"+x.tagName)
                    log(x)
                    log(innerText)
                    //window.test01 = x
                }
            }
        }
        if (wallWord) {
            let wordKillContain1 = false
            for (let k3 = 0; k3 < wordKill.length; k3++) {
                if (wordKill[k3].length != 0 &&x.tagName=="DIV" && innerText.includes(wordKill[k3])) {
                    wordKillContain1 = true
                    break
                }
            }
            if (wordKillContain1) {
                x.setAttribute("fbkill_checked", "");
                if (destroyTopDiv(x)) {
                    log("刪除關鍵字(Kill word)")
                    //console.log(x.tagName)
                    log(x)
                    window.test01 = x
                }
            }
        }
        function stringLike(a,b)
        {
            //console.log(a)
            //console.log(b)
            a=a.replace(/ /g,"").replace(/\r/g,"").replace(/\n/g,"")
            if(a=="") return false
            //b=b.replace(/ /g,"")
            let result=false
            for(let j=0,i=0;j<a.length;j++){
                if(a[j]==b[i]){
                    i++;
                    if(i>=b.length){
                        result=true
                        break
                    }
                }
            }
            if(result){
                return result
            }
            for(let j=0,i=b.length-1;j<a.length;j++){
                if(a[j]==b[i]){
                    i--;
                    if(i<0){
                        result=true
                        break
                    }
                }
            }
            return result
            //let result=a.match(new RegExp(b.split("").join(".*")))!=null
            /*if(result){
                console.log(a)
                console.log(b)
            }*/
            //console.log(result)
            //return a.match(new RegExp(b.split("").join(".*")))!=null
            //return a.contains(b)
        }
    }
    if (isMobile) {
        console.log("phone")
        sponsored = "贊助-Sponsored-広告".split(/-/g)
        var timerID;
        function run2() {
            var spanz = document.querySelectorAll("div._52jc > span:not([fbkill_checked])")
            for (let i = 0; i < spanz.length; i++) {
                let x = spanz[i]
                if (x == null) continue;
                let sponsoredContain1 = false
                for (let k2 = 0; k2 < sponsored.length; k2++) {
                    if (sponsored[k2].length != 0 && x.innerText.contains(sponsored[k2])) {
                        sponsoredContain1 = true
                        break
                    }
                }
                if (sponsoredContain1) {
                    x.innerHTML = "貓咪哈哈哈";
                    //x.setAttribute("fbkill_checked", "");
                    //x.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none"
                    console.log("kill one")
                    destroyTopDiv(x)
                }
            }
        }
        function run() {
            run2()
            clearInterval(timerID)
            timerID = setInterval(run2, 500);
            var x = document.querySelectorAll("a, img")
            for (let i = 0; i < x.length; i++) {
                let xx = x[i]
                xx.addEventListener("click", run)
            }
        }
        setTimeout(() => {
            run()
        }, 3000);
    } else {
        log("PC");
        run();
        //window.addEventListener("load", run);
        function run() {
            log("load");
            isLoaded = true;
            function useDB() {
                transaction = db.transaction(["fbkill"], "readwrite");
                objectStore = transaction.objectStore("fbkill");
            }
            //let firstTime = localStorage.getItem("fbkill_firstTime");
            checkSetting();
            function checkSetting() {
                if (document.querySelector("#windowForSetting")) {
                    return;
                } else {
                    if (init) {
                        console.log("reset setting");
                    }
                }
                let windowForSetting = document.createElement("div");
                document.body.appendChild(windowForSetting)
                windowForSetting.id = "windowForSetting"
                windowForSetting.style.cssText = `border: 2px solid black;
line-height: 2.2em;
font-size: 18px;
display: none;
position: fixed;
z-index: 99;
left: 50%;
top: 50%;
color: red;
width: 300px;
height: fit-content;
background-color: white;
padding: 10px;
transform: translate(-50%,-50%);`
                windowForSetting.innerHTML = `FB贊助殺手<ruby>設定<rt>Settings</rt></ruby>框框:<br>
[Ctrl+Shift+X/Q]<ruby>關閉<rt>Close</rt></ruby><br>
<ruby>為你推薦<rt>Suggested for you</rt></ruby>:<input type="checkBox" id="fbkill_checkBox1" onchange="fbkill_onChange1(event);"><br>
<ruby>動態牆贊助<rt>Wall Sponsored</rt></ruby>:<input type="checkBox" id="fbkill_checkBox2" onchange="fbkill_onChange2(event);"><br>
<ruby>動態牆文字<rt>Wall word</rt></ruby>:<input type="checkBox" id="fbkill_checkBox3" onchange="fbkill_onChange3(event);">
<hr>
<ruby>以-分隔<rt>Split by -</rt></ruby><br>
<ruby>為你推薦關鍵字<rt>Suggested for you keyword</rt></ruby>:<br><textarea oninput="fbkill_onInput1(event)" id="fbkill_textarea1">為你推薦-Suggested for you</textarea><br>
<ruby>動態牆贊助關鍵字<rt>Wall Sponsored keyword</rt></ruby>:<br><textarea oninput="fbkill_onInput2(event)" id="fbkill_textarea2">贊助-Sponsored</textarea><br>
<hr>
<ruby>以行分隔<rt>Split by line</rt></ruby><br>
<ruby>文章關鍵字<rt>kill word</rt></ruby>:<br><textarea oninput="fbkill_onInput3(event)" id="fbkill_textarea3"></textarea><br>
<ruby>自動刪除30前的文章(增進流暢度)<rt>Auto kill article before 30 (Improve fluency)</rt></ruby>:<input type="checkBox" id="fbkill_checkBox4" onchange="fbkill_onChange4(event);"><br>
<ruby>暴力模式<rt>Violent Mode</rt></ruby><br><ruby>(對大部分使用者有效)<rt>(Efficiency bad, but to most user effect.)</rt></ruby>:<input type="checkBox" id="fbkill_checkBox5" onchange="fbkill_onChange5(event);">`;

                fbkill_checkBox1=document.getElementById("fbkill_checkBox1")
                fbkill_checkBox2=document.getElementById("fbkill_checkBox2")
                fbkill_checkBox3=document.getElementById("fbkill_checkBox3")
                fbkill_checkBox4=document.getElementById("fbkill_checkBox4")
                fbkill_checkBox5=document.getElementById("fbkill_checkBox5")
                fbkill_textarea1=document.getElementById("fbkill_textarea1")
                fbkill_textarea2=document.getElementById("fbkill_textarea2")
                fbkill_textarea3=document.getElementById("fbkill_textarea3")

                request = window.indexedDB.open("fbkill", 2);
                request.onerror = function (event) {
                    // Do something with request.errorCode!
                    log("error db")
                    log(event)
                };
                request.onsuccess = function (event) {
                    // Do something with request.result!
                    console.log("FB Sponsored Killer:success db load")
                    db = request.result;
                    useDB()

                    function getDataTextarea(name, target) {
                        let objectStoreRequest = objectStore.get(name)
                        objectStoreRequest.onsuccess = function (event) {
                            target.value = objectStoreRequest.result
                        }
                    }
                    getDataTextarea("fbkill_forYouPushKeyword", fbkill_textarea1);
                    //fbkill_textarea1.value = objectStore.get("fbkill_forYouPushKeyword")
                    getDataTextarea("fbkill_wallSupKeyword", fbkill_textarea2);
                    //fbkill_textarea2.value = objectStore.get("fbkill_wallSupKeyword")
                    getDataTextarea("fbkill_word", fbkill_textarea3);
                    //fbkill_textarea3.value = objectStore.get("fbkill_word")
                    function getDataCheckbox(name, target, checkBox,callback) {
                        let objectStoreRequest = objectStore.get(name)
                        objectStoreRequest.onsuccess = function (event) {
                            if(typeof(objectStoreRequest.result)=="undefined"){
                                objectStore.add("no", name);
                                checkBox.checked =false;
                                return;
                            }
                            this[target] = objectStoreRequest.result
                            checkBox.checked = objectStoreRequest.result == "yes"
                            updateData()
                            if(callback!=null) callback();
                        }
                        return objectStoreRequest;
                    }
                    getDataCheckbox("fbkill_forYouPush", "forYouPush", fbkill_checkBox1)
                    //forYouPush = objectStore.get("fbkill_forYouPush") == "yes";
                    getDataCheckbox("fbkill_wallSup", "wallSup", fbkill_checkBox2)
                    //wallSup = objectStore.get("fbkill_wallSup") == "yes";
                    getDataCheckbox("fbkill_wallWord", "wallWord", fbkill_checkBox3)
                    //wallWord = objectStore.get("fbkill_wallWord") == "yes";
                    getDataCheckbox("fbkill_autoKillOld30", "autoKillOld30", fbkill_checkBox4)
                    //autoKillOld30 = objectStore.get("fbkill_autoKillOld30") == "yes";
                    killInterval=null;
                    getDataCheckbox("fbkill_violentMode", "violentMode", fbkill_checkBox5, ()=>{
                        if(fbkill_checkBox5.checked){
                            log("violentMode");
                            killInterval= setInterval(kill,500);
                        }else{
                            log("normalMode");
                            if(killInterval!=null) clearInterval(killInterval)
                            trySetKillAndOvserve()
                            setTimeout(trySetKillAndOvserve,2000)
                        }
                    });

                    updateData();

                    GM_registerMenuCommand('Open/Close Setting(開關設定)', ()=>
                    {
                        if (windowForSetting.style.display != "block") {
                            windowForSetting.style.display = "block"
                        } else {
                            windowForSetting.style.display = "none"
                        }
                    }, 'X');
                    GM_registerMenuCommand('Manul Start Observe(手動開始觀察)',()=>
                    {
                        console.log("fbkill:startObserve()");
                        kill()
                        startObserve()
                    },"E");
                };
                request.onupgradeneeded = function (event) {
                    var db = event.target.result;

                    // Create an objectStore for this database
                    objectStore = db.createObjectStore("fbkill");

                    //objectStore.add({ key: "aaa", id: 333 })
                    //objectStore.add("asd", "xxx")

                    objectStore.add("yes", "fbkill_forYouPush");
                    objectStore.add("yes", "fbkill_wallSup");
                    objectStore.add("no", "fbkill_wallWord");
                    objectStore.add("no", "fbkill_firstTime");

                    objectStore.add("為你推薦-Suggested for you-회원님을 위한 추천-おすすめ", "fbkill_forYouPushKeyword");

                    //thank "https://greasyfork.org/zh-TW/scripts/404309-facebook-hide-ads-a-k-a-sponsored-posts/code"
                    objectStore.add("Geborg-የተከፈለበት ማስታወቂያ-إعلان مُموَّل-পৃষ্ঠপোষকতা কৰা-Yatiyanaka-Sponsor dəstəkli-Рэклама-Спонсорирано-Paeroniet-Sponzorirano-সৌজন্যে-Patrocinat-پاڵپشتیکراو-Spunsurizatu-Sponzorováno-Giisponsoran-Noddwyd-Sponsoreret-Gesponsert-Χορηγούμενη-Sponsored-Reklamo-Publicidad-Sponsitud-Babestua-دارای پشتیبانی مالی-Sponsoroitu-Stuðlað-Commandité-Sponsore-Urraithe-Patrocinado-Oñepatrosinapyre-Χορηγούμενον-प्रायोजित-Hirdetés-Bersponsor-Sponsorizzata-広告-Disponsori-Демеушілік көрсеткен-បានឧបត្ថម្ភ-ໄດ້ຮັບການສະໜັບສະໜູນ-Спонзорирано-സ്പോൺസർ ചെയ്തത്-Ивээн тэтгэсэн-प्रायोजित-Ditaja-प्रायोजित-Gesponsord-ପ୍ରଯୋଜିତ-ਸਰਪ੍ਰਸਤੀ ਪ੍ਰਾਪਤ-Sponsorowane-تمويل شوي-Patrocinado-Реклама-प्रायोजितः |-අනුග්‍රහය දක්වන ලද-La maalgeliyey-Sponsrad-స్పాన్సర్ చేసినవి-ได้รับการสนับสนุน-May Sponsor-Sponsorlu-ⵉⴷⵍ-Реклама-تعاون کردہ-Được tài trợ-赞助内容-贊助", "fbkill_wallSupKeyword");
                    objectStore.add("", "fbkill_word");
                    objectStore.add("no", "fbkill_autoKillOld30");

                    console.log("FB贊助殺手,初次使用,自動初始化,全開")

                    fbkill_checkBox5.checked=false;
                    trySetKillAndOvserve()
                };
                init = true;
            }

            /*
            if (localStorage.getItem("fbkill_autoKillOld30") == null) {
                localStorage.setItem("fbkill_autoKillOld30", "no");
            }
            if (localStorage.getItem("fbkill_forYouPushKeyword") == null) {
                localStorage.setItem("fbkill_forYouPushKeyword", "為你推薦-Suggested for you-회원님을 위한 추천-おすすめ");
            }
            if (localStorage.getItem("fbkill_wallSupKeyword") == null) {
                localStorage.setItem("fbkill_wallSupKeyword", "贊助-Sponsored-広告");
            }*/

            fbkill_onChange1 = function (e) {
                checkSetting()
                useDB()
                forYouPush = fbkill_checkBox1.checked;
                log("為你推薦過濾狀態:" + forYouPush);
                //localStorage.setItem("fbkill_forYouPush", forYouPush ? "yes" : "no");
                objectStore.put(forYouPush ? "yes" : "no", "fbkill_forYouPush").onsuccess = () => {
                    log("fbkill_forYouPush-ok");
                }
                updateData();
                kill();
            }
            fbkill_onChange2 = function (e) {
                useDB()
                checkSetting()
                wallSup = fbkill_checkBox2.checked;
                log("動態牆贊助過濾狀態:" + wallSup);
                //localStorage.setItem("fbkill_wallSup", wallSup ? "yes" : "no");
                objectStore.put(wallSup ? "yes" : "no", "fbkill_wallSup")
                updateData();
                kill();
            }
            fbkill_onChange3 = function (e) {
                checkSetting()
                useDB()
                wallWord = fbkill_checkBox3.checked;
                log("動態牆文字過濾狀態:" + wallWord);
                objectStore.put(wallWord ? "yes" : "no", "fbkill_wallWord");
                updateData();
                kill();
            }
            fbkill_onChange4 = function (e) {
                checkSetting()
                useDB()
                autoKillOld30 = fbkill_checkBox4.checked;
                log("自動刪除30前的文章狀態:" + autoKillOld30);
                objectStore.put(autoKillOld30 ? "yes" : "no", "fbkill_autoKillOld30");
                updateData();
                kill();
            }
            fbkill_onChange5 = function (e) {
                checkSetting()
                useDB()
                violentMode = fbkill_checkBox5.checked;
                log("模式:" + violentMode);
                objectStore.put(violentMode ? "yes" : "no", "fbkill_violentMode");
                updateData();
                kill();
            }
            fbkill_onInput1 = function (e) {
                checkSetting()
                useDB()
                objectStore.put(fbkill_textarea1.value, "fbkill_forYouPushKeyword");
                log("更新為你推薦關鍵字:" + fbkill_textarea1.value);
                updateData();
                kill();
            }
            fbkill_onInput2 = function (e) {
                checkSetting()
                useDB()
                objectStore.put(fbkill_textarea2.value, "fbkill_wallSupKeyword");
                log("更新贊助關鍵字:" + fbkill_textarea2.value);
                updateData();
                kill();
            }
            fbkill_onInput3 = function (e) {
                checkSetting()
                useDB()
                objectStore.put(fbkill_textarea3.value, "fbkill_word");
                log("更新贊助關鍵字:" + fbkill_textarea3.value);
                updateData();
                kill();
            }

            document.onkeydown = function (e) {
                checkSetting()
                if (e.ctrlKey && e.shiftKey && (e.key == "x" || e.keyCode == 88 || e.which == 88 || e.Key == "q" || e.which == 81)) {
                    //log(e);
                    if (windowForSetting.style.display != "block") {
                        windowForSetting.style.display = "block"
                    } else {
                        windowForSetting.style.display = "none"
                    }
                }else if(e.ctrlKey && e.shiftKey &&e.keyCode == 69){
                    console.log("fbkill:startObserve()");
                    kill()
                    startObserve()
                }
            }
            if (!Date.now) {
                Date.now = function now() {
                    return new Date().getTime();
                };
            }
            function nullGet(a){
                if(a==null){
                    const varToString = a => Object.keys(a)[0]
                    return document.getElementById(varToString({a}))
                }
                else{
                    return a
                }
            }
            function updateData() {

                forYouPush = fbkill_checkBox1.checked;
                wallSup = fbkill_checkBox2.checked
                wallWord = fbkill_checkBox3.checked
                autoKillOld30 = fbkill_checkBox4.checked
                suggested = fbkill_textarea1.value.split(/-/g)
                sponsored = fbkill_textarea2.value.split(/-/g)
                wordKill = fbkill_textarea3.value.split(/\n/g)
            }

            let triggerOnce = false;
            function triggerKill() {
                triggerOnce = true;
            }

            let retryCount = 0, retryTimeoutID;
            let fbIcon;
            var crashCheckTimer=null;
            function trySetKillAndOvserve() {
                try {
                    checkSetting()
                    startObserve()
                    if(crashCheckTimer!=null){
                        clearInterval(crashCheckTimer)
                    }
                    crashCheckTimer=setInterval(()=>{
                        if(mo==null){
                            console.log("reset startObserve")
                            startObserve()
                        }
                    },1000)
                    function startObs(){
                        feedz=null;
                        fbIcon=null
                        for(let i=1;i<10;i++){
                            retryTimeoutID = setTimeout(startObserve, 1000*i);
                        }
                    }
                    if(fbIcon==null){
                        fbIcon=document.querySelector("a[aria-label=Facebook]");
                        fbIcon.addEventListener("click",(e)=>{
                            log("fbIcon click");
                            startObs()
                        });
                    }
                    let ulz = document.querySelectorAll("li")
                    if (ulz != null) {
                        for(let i=0;i<ulz.length;i++){
                            ulz[i].onclick= (e) => {
                                log("li click");
                                startObs()
                            }
                        }
                    }
                    if(!logOutStartObserve){
                        console.log("FB Sponsored Killer:success startObserve")
                        logOutStartObserve=true
                    }
                } catch (ex) {
                    clearTimeout(retryTimeoutID)
                    retryTimeoutID = setTimeout(trySetKillAndOvserve, 1000);
                    retryCount++
                    if (retryCount >= 10) {
                        console.log("FB Sponsored Killer:give up retry");
                        clearTimeout(retryTimeoutID);
                    }
                }
                kill();
            }

            //document.addEventListener('DOMNodeInserted', triggerKill);
            //<div role="feed">
            let pageArticle = {};
            function getArticle() {
                if (typeof pageArticle[window.location] == "undefined") {
                    pageArticle[window.location] = {};
                    pageArticle[window.location].article = [];
                    let article = pageArticle[window.location].article;
                    try
                    {
                        let f1 = document.querySelectorAll("div[role=article]")[0];
                        article.push(f1);
                        let gf1 = document.querySelectorAll("div[role=article]")[0];
                        article.push(gf1);
                    }
                    catch{}
                }
                return pageArticle[window.location].article;
            }
            var feedz=null;
            var mo=null;
            //setInterval(startObserve,500)
            var freezeTime;
            function startObserve() {
                if (mo != null) {
                    mo.disconnect()
                }

                mo = new MutationObserver((mutations) => {
                    //console.log(mutations);
                    let added = false;
                    for (var i = 0; i < mutations.length; i++) {
                        var mutation = mutations[i];
                        // your code
                        if (mutation.addedNodes.length > 0) {
                            added = true;
                            //log(mutation);
                            for (let j = 0; j < mutation.addedNodes.length; j++) {
                                const mDiv = mutation.addedNodes[j];
                                //if (mDiv.querySelector("div.du4w35lb")!=null)
                                {
                                    log(mDiv);
                                    //console.log(sponsored);
                                    //b:not([fbkill_checked])
                                    var children = mDiv.querySelectorAll("b:not([fbkill_checked]),div:not([fbkill_checked]),span:not([fbkill_checked])")
                                    for (let k = 0; k < children.length; k++) {
                                        const mDivChild = children[k];
                                        XDivOrB(mDivChild);
                                    }
                                    let article = getArticle();
                                    article.push(mDiv);
                                    if (autoKillOld30) {
                                        while (article.length > 30) {
                                            log("remove");
                                            var old30 = article.shift();
                                            log(old30);
                                            if (old30 != null) {
                                                //log(pageArticle);
                                                //old30.remove();
                                                old30.style.display = "none";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                });
                //log(window.location);
                log("obs")
                feedz = document.querySelectorAll("div[role=feed]");
                for (let i = 0; i < feedz.length; i++) {
                    const f = feedz[i];
                    mo.observe(f, {
                        childList: true
                    });
                }
            }
        }
    }
})();
/*
document.body.addEventListener("MouseWheel",kill)
document.body.addEventListener("MouseDown",kill)
*/