Waifuist 8chan Enhancer 2

Early version of an updated script for 8chan: Post counting and notify, quick reply, images from links.

目前為 2014-09-24 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           Waifuist 8chan Enhancer 2
// @include        https://8chan.co/*
// @description    Early version of an updated script for 8chan: Post counting and notify, quick reply, images from links.
// @version        0.0.6
// @namespace https://greasyfork.org/users/2657
// ==/UserScript==

//check if thread
if (window.location.href.indexOf("res") > -1) {
    
    //Config Vars
    var Configs = {counter:"ON", linkimgopt:"ON", menu:"ON", configmenu:"ON", arrows:"ON", noko:"ON", antiflood:"ON", quickreply:"ON", inlinereply:"ON", linkstoview:"OFF"};
    $('form:first-of-type').addClass( "postboxy" );
    
    //Load Configs System
    if (localStorage.getItem('Configs')){
        var Configs2 = localStorage.getItem('Configs');
        Configs = JSON.parse(Configs2);
    };
    
    //Configs Saver
    function save(){
        localStorage.setItem("Configs", JSON.stringify(Configs));
    };
    
    //Notifier/Counter
    if (Configs["counter"] == "ON") {
        var count = 0;
        
        $('#favicon').remove();
        $('head').append('<link href="http://i.imgur.com/wBQJqld.png" id="favicon" rel="shortcut icon">');
        $('hr:last-of-type').addClass( "bottomhr" );
        
        $(document).on( "new_post", function() {
            count++;
            if (Configs["linkimgopt"] == "ON") {linkimg();};
            if (Configs["inlinereply"] == "ON") {genreply();};
            $('.clear').removeClass();
            $('.bottomhr').before('<br class="clear">');
            
        });
        
        var title_regex = /^\(\d+\) (.*)$/;
        var original_title = document.title;
        var match = title_regex.exec(document.title);
        if (match != null) {
            original_title = match[1];
        };
        
        setInterval(function() {
            var state2 = document["visibilityState"];
            if (state2 == "visible"){
                count = 0;};
            if (count > 0 && state2 == "hidden") {
                document.title = '('+count+') '+original_title;
                $('#favicon').remove();
                $('head').append('<link href="http://i.imgur.com/lfAW4fq.png" id="favicon" rel="shortcut icon">');
            };
        }, 10000);
        
        var onVisibilityChange = function (args) {
            var state = document["visibilityState"];
            if (state == "visible")
            {
                document.title = original_title;
                count = 0;
                $('#favicon').remove();
                $('head').append('<link href="http://i.imgur.com/wBQJqld.png" id="favicon" rel="shortcut icon">');
            }
        };
        
        document.addEventListener("visibilitychange", onVisibilityChange, false);
        
    };
    
    //Menu
    if (Configs["menu"] == "ON") {
        $('body').append("<div class='menu' style='position:fixed; right:10%; bottom:20%; width:49px; background:grey;'></div>")
        if (Configs["arrows"] == "ON") {
            $('.menu').append("<center><font size='30'><a alt='Scroll Up' style='text-decoration: none' href='javascript:window.scrollTo(0,0);'>▲</a><br><a style='text-decoration: none' href='javascript:window.scrollTo(0,900000000);'>▼</a>")
        };
    };
    
    //Config Menu
    if (Configs["configmenu"] == "ON") {
        $("body").append("<div class='optionslink' style='cursor: pointer; cursor: hand; width:auto;'>[Script Options]</div>")
        $("body").append("<div class='optionsmenu' style='display:none; position:fixed; right:10%; top:5%; width:200px; height:300px; background:grey; padding:5px;'></div>")
        $(document).on('click', ".optionslink", function() {
            $(".optionsmenu").css("display","inline");
            $('.optionslink').html("[Close Script Options]");
            $('.optionslink').attr('class', 'optionslinkclose');
            show_quick_reply();
        });
        $(document).on('click', ".optionslinkclose", function() {
            $(".optionsmenu").css("display","none");
            $('.optionslinkclose').html("[Script Options]");
            $('.optionslinkclose').attr('class', 'optionslink');
        });
    };
    
    $(".optionsmenu").append("<div class='linkimg' style='cursor: pointer; cursor: hand; width:auto;'>Links to Images [" + Configs["linkimgopt"] + "]</div>");
    $(document).on('click', ".linkimg", function() {
        imgchange = Configs["linkimgopt"];
        if ( imgchange === "ON") {imgchange = "OFF";} else {imgchange = "ON";};    
        Configs["linkimgopt"] = imgchange;
        $('.linkimg').html("Links to Images [" + Configs["linkimgopt"] + "]");
        save();
    });
    
    $(".optionsmenu").append("<div class='antiflood' style='cursor: pointer; cursor: hand; width:auto;'>Anti Flood [" + Configs["antiflood"] + "]</div>");
    $(document).on('click', ".antiflood", function() {
        floodchange = Configs["antiflood"];
        if ( floodchange === "ON") {floodchange = "OFF";} else {floodchange = "ON";};    
        Configs["antiflood"] = floodchange;
        $('.antiflood').html("Anti Flood [" + Configs["antiflood"] + "]");
        save();
    });
    
    $(".optionsmenu").append("<div class='quickreply' style='cursor: pointer; cursor: hand; width:auto;'>Quick Reply [" + Configs["quickreply"] + "]</div>");
    $(document).on('click', ".quickreply", function() {
        qrchange = Configs["quickreply"];
        if ( qrchange === "ON") {qrchange = "OFF";} else {qrchange = "ON";};    
        Configs["quickreply"] = qrchange;
        $('.quickreply').html("Quick Reply [" + Configs["quickreply"] + "]");
        save();
    });
    
    $(".optionsmenu").append("<div class='arrows' style='cursor: pointer; cursor: hand; width:auto;'>Scroll Arrows [" + Configs["arrows"] + "]</div>");
    $(document).on('click', ".arrows", function() {
        arrowschange = Configs["arrows"];
        if ( arrowschange === "ON") {arrowschange = "OFF";} else {arrowschange = "ON";};    
        Configs["arrows"] = arrowschange;
        $('.arrows').html("Scroll Arrows [" + Configs["arrows"] + "]");
        save();
    });
    
    $(".optionsmenu").append("<div class='inlinereply' style='cursor: pointer; cursor: hand; width:auto;'>In-Line Reply [" + Configs["inlinereply"] + "]</div>");
    $(document).on('click', ".inlinereply", function() {
        inlinechange = Configs["inlinereply"];
        if ( inlinechange === "ON") {inlinechange = "OFF";} else {inlinechange = "ON";};    
        Configs["inlinereply"] = inlinechange;
        $('.inlinereply').html("In-Line Reply [" + Configs["inlinereply"] + "]");
        save();
    });
    
    $(".optionsmenu").append("<div class='linkstoview' style='cursor: pointer; cursor: hand; width:auto;'>View Image Buttons [" + Configs["linkstoview"] + "]</div>");
    $(document).on('click', ".linkstoview", function() {
        link2viewchange = Configs["linkstoview"];
        if ( link2viewchange === "ON") {link2viewchange = "OFF";} else {link2viewchange = "ON";};    
        Configs["linkstoview"] = link2viewchange;
        $('.linkstoview').html("View Images Buttons [" + Configs["linkstoview"] + "]");
        save();
    });
    
    //linkimg
    function linkimg(){
        $('a[href$=".png"][rel="nofollow"], a[href$=".jpg"][rel="nofollow"], a[href$=".gif"][rel="nofollow"]').each(function(){
            $(this).replaceWith('<div class="linkedimg2" style="width:100px;display:inline-block;"><img class="linkedimg2" style="max-width: 100%;" src="' + $(this).attr('href') + '" /></div>');
        });
        
        $(document).on('click', ".linkedimg2", function() {
            $(this).css('width', 'auto');
            $(this).attr('class', 'clicked');
        });
        
        $(document).on('click', ".clicked", function() {
            $(this).css('width', '100px');
            $(this).attr('class', 'linkedimg2');
        });
        
    };
    
    if (Configs["linkimgopt"] == "ON") {linkimg();};
    
    //linkstoview
    function linkstoview(){
        $('a[href$=".png"][rel="nofollow"], a[href$=".jpg"][rel="nofollow"], a[href$=".gif"][rel="nofollow"]').each(function(){
            var linkURL = $(this).attr('href');
            $(this).replaceWith('<div class="viewbutton" id="' + $(this).attr('href') + '"><b>[Click to View Image]</b> <br>' + $(this).attr('href') + '</a></div>')
                                });
            
            
            $(document).on('click', ".viewbutton", function() {
                $(this).replaceWith('<br><div class="linkedimg2" style="width:100px;display:inline-block;"><img class="linkedimg2" style="max-width: 100%;" src="' + $(this).attr('id') + '" /></div>');
            });
            
            $(document).on('click', ".linkedimg2", function() {
                $(this).css('width', 'auto');
                $(this).attr('class', 'clicked');
            });
            
            $(document).on('click', ".clicked", function() {
                $(this).css('width', '100px');
                $(this).attr('class', 'linkedimg2');
            });
            
        };
                                                                                                                    
                                                                                                                    if (Configs["linkstoview"] == "ON") {linkstoview();};
        
        // Quick Reply
        if (Configs["quickreply"] == "ON") {
            
            $('.menu').append("<center><font size='30'><a style='text-decoration: none' class='QR'><img style='cursor: pointer; cursor: hand;' src='http://i.imgur.com/f8L6S1O.png'></a><a style='text-decoration:none;display:none;cursor: pointer; cursor: hand;' class='QR2'>X</a><br>");
            $('body').on('click', '.QR', function() {
                $('.close-btn').click();
                $('.postboxy').after("<div class='dummytext' style='height:301px;'></div>");
                $('.postboxy').css({"background-color":"#D1D1D1", position:"fixed", bottom:"10%", right:"calc(10% + 49px)"});   
                $(".posttable").css("margin","auto");
                $(".QR").css("display","none");
                $(".QR2").css("display","inline");
                
            });
            $('body').on('click', '.QR2', function() {
                $( ".dummytext" ).remove();
                $('.postboxy').css({"background-color":"", position:"", bottom:"", right:""});
                $('.postboxy').insertAfter($('.banner'));
                $(".posttable").css("margin","auto");
                $(".QR").css("display","inline");
                $(".QR2").css("display","none");
                
            });
        };
        
        // In-Line Reply
        if (Configs["inlinereply"] == "ON") {
            $('table:first-of-type').addClass( "posttable" );
            function quotador(id){
                $("textarea[id*='body']")[0].value += '>>' + id + '\n';
                reply_id = 'reply_' + id;
                $( ".dummytext" ).remove();
                $('.banner').after("<div class='dummytext' style='height:301px;'></div>");
                $('.postboxy').insertAfter("#" + reply_id);   
                $(".posttable").css("margin","inherit");
                $(".QR").css("display","none");
                $(".QR2").css("display","inline");
            };
            
            function genreply(){
                $("iframe").removeAttr('style');
                if(window.location.href.indexOf("res") > -1) {
                    $('.quotes').remove();
                    $( "div[id^='reply_']" ).each(function() {
                        var replyid = $(this).attr("id")
                        replyid = replyid.replace("reply_", "");
                        $(this).append('<div class="quotes" id="'+ replyid +'" style=" float: right; clear: both; background-color: #FF6600; border: 1px solid; margin: 3px; padding: 3px; cursor: pointer; cursor: hand;">Reply</div>');
                        
                    })};
            };
            
            genreply();
            
            $('body').on('click', 'div.quotes', function() {
                var currentId = $(this).attr('id');
                $(".postboxy").removeAttr('style');
                quotador(currentId);
            });
            
        };
        
        
        
        //smaller functions
        
        if (Configs["antiflood"] == "ON") {
            
            function makeid(){
                var text = "";
                var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";    
                for( var i=0; i < 10; i++ )
                    text += possible.charAt(Math.floor(Math.random() * possible.length));    
                return text;
            };
            
            function checkandffill(){
                $("#body").each(function() {
                    if($(this).val() === "")
                        var number = 12345678 + Math.floor(Math.random() * 6);
                    $("#body").text(makeid());
                });};
            
            $nofill = 'no';
            
            $(".post_no").click(function(){
                $nofill = 'yes';
            });
            
            $("input[name='post']").click(function(){	
                if($nofill === "no"){
                    window.onload=checkandffill();
                };
            });
            
        };
        
        //autonoko
        if (Configs["noko"] == "ON") {
            function noko(){
                document.getElementsByName("email", "input")[0].value = "noko";
            };
            
            
        };
        
    };