Dribbble Extender

Shows who follows you on your following list

2016/08/04のページです。最新版はこちら

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Dribbble Extender
// @description  Shows who follows you on your following list
// @author       Kos
// @namespace    http://tampermonkey.net/
// @version      0.2
// @license      CC BY-SA 2.0
// @homepage     https://greasyfork.org/scripts/22003-dribbble-extender
// @include      https://dribbble.com/*/following
// @require	 https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant        none
// ==/UserScript==

;(function() {
    'use strict';
    
    var followers = [],
        cacheKey = location.pathname.replace(/\/(.*?)\/.*/, '$1');
    
    // functions for working with localStorage
    
    function lsTest()
    {
        var test = 'test';
        try
        {
            localStorage.setItem(test, test);
            localStorage.removeItem(test);
            return true;
        }
        catch(e)
        {
            return false;
        }
    }
        
    function getLocalStorageArray(name)
    {
        var list = localStorage.getItem(name);
        if (!list)
        {
            return [];
        }
        return JSON.parse(list);
    }
    
    function saveUpdatedFollowersList(list)
    {
        localStorage.setItem(cacheKey+'_followers_latest', JSON.stringify(list));
    }
    
    function addFollowerLocalStorage(id)
    {
        var list = getLocalStorageArray(cacheKey+'_followers_latest');
        
        if (list.indexOf(id) == -1)
        {
            list.push(id);
        }
        
        saveUpdatedFollowersList(list);
    }
    
    function saveFinishedAmountOfFollowers()
    {
        var list = getLocalStorageArray(cacheKey+'_followers_latest');
        
        localStorage.setItem(cacheKey+'_followers', JSON.stringify(list));
        saveUpdatedFollowersList([]);
        
        // update on page
        followers = list;
    }

    var localStorageAvailable = lsTest();
    
    $(document).ready(function(){
        var fetchActive = false,
            fullFetchFinished = false,
            curPage = 1,
            parseDelay = 200,
            repaintDelay = 2500,
            waitForAllFetch = false,
            skipParseCounter = 0;
        
        if (localStorageAvailable)
        {
            followers = getLocalStorageArray(cacheKey+'_followers');
            
            // if have previously saved followers, increase delay,
            // update on page only when all users parsed
            if (followers.length)
            {
                parseDelay += 300;
                waitForAllFetch = true;
            }
            
            // clear previously parsed data, to parse all new
            saveUpdatedFollowersList([]);
        }
        
        function getPage(page)
        {
            page = Math.round(page);
            fetchActive = true;
            $.ajax({
                url: 'https://'+document.location.hostname+document.location.pathname.replace('following', 'followers')+'?page='+page
            }).done(function(data){
                
                var match = data.match(/Dribbble\.PlayerCards\.update\({"id":\d+,"users":(\[.*?\])/),
                arr = JSON.parse(match[1]);
                
                for (var i = 0; i < arr.length; i++)
                {
                    setFollowed(arr[i].id);
                }
                
                fetchActive = false;
                curPage++;
            }).fail(function(data){
                fetchActive = false;
                if (data.status == 404)
                {
                    fullFetchFinished = true;
                    return;
                }
                if (data.status == 403)
                {
                    //alert('Request limit exceeded. Wait one minute and refresh page.');
                    // skip next n parse times
                    skipParseCounter = 20;
                    return;
                }
            });
        }
        
        function setFollowed(id)
        {
            id = Math.round(id);
            
            if (!waitForAllFetch && followers.indexOf(id) == -1)
            {
                followers.push(id);
            }
            
            if (localStorageAvailable)
            {
                addFollowerLocalStorage(id);
            }
        }
        
        function paintFollowed()
        {
            // clear previously set marks if any
            $('.us-follows-you').removeClass('us-follows-you');
            $('.us-follows-you-mark').remove();
            
            for (var i = 0; i < followers.length; i++)
            {
                var userBlock = $('.user-row-'+followers[i]);
                
                userBlock.addClass('us-follows-you');

                var title = userBlock.find('.hover-card-parent');
                title.html('<span title="Follows you" class="us-follows-you-mark" style="color:'+(!fullFetchFinished ? '#7d8e99' : '#2cff5a')+'">✓ </span>'+title.html());
            }
        }
        
        var interval = setInterval(function(){
            if (fullFetchFinished)
            {
                clearInterval(interval);
                if (localStorageAvailable)
                {
                    saveFinishedAmountOfFollowers();
                }
                return;
            }
            // skip and reduce counter
            if (skipParseCounter > 0)
            {
                skipParseCounter--;
                return;
            }
            
            if (!fetchActive)
            {
                getPage(curPage);
            }
        }, parseDelay);
        
        // paint then set repaint with delay
        paintFollowed();
        setInterval(paintFollowed, repaintDelay);
    });
})();