Greasy Fork

来自缓存

Greasy Fork is available in English.

Dribbble Extender

Shows who follows you on your following list

当前为 2016-08-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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     http://greasyfork.icu/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);
    });
})();