Greasy Fork

Greasy Fork is available in English.

VK-Gif

Gif на аватар VK

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name VK-Gif
// @description Gif на аватар VK
// @author Last8Exile
// @license MIT
// @version 1.35
// @noframes
// @match *://vk.com/*
// @namespace http://greasyfork.icu/users/61164
// ==/UserScript==

(function() {
    'use strict';
    if (window.top != window.self)
        return;

    document.body.addEventListener("DOMNodeInserted",refresh);
    refresh();

    function refresh()
    {
        var profile = document.querySelector(".Profile");
        var updated;
        if (profile === null)
            return;

        updated = profile.getAttribute("avatar");
        if (updated !== null)
            return;

        var statusBar = document.querySelector(".ProfileInfo__status");
        if (statusBar === null)
            return;
        var statusText = statusBar.innerText;
        var posDocument = statusText.lastIndexOf("<!>");
        var posInternet = statusText.lastIndexOf("<?>");

        var avatar = document.querySelector(".vkuiImageBase__img");
        if (avatar === null)
            return;

        if (posDocument >= 0)
        {
            var link = statusText.slice(posDocument+3);

            var request = new XMLHttpRequest();

            var page = document.createElement("div");

            var qr = new XMLHttpRequest();
            qr.open('get',link);
            qr.send();
            qr.onreadystatechange=function()
            {
                if (this.responseText === "")
                    return;
                updated = profile.getAttribute("avatar");
                if (updated !== null)
                    return;

                page.innerHTML=this.responseText;
                var image = page.querySelector("img");
                var imageSrc = image.src;
                var questPos = imageSrc.lastIndexOf("?");
                var gifLink = imageSrc.slice(0,questPos);

                GetMeta(gifLink,function(w,h) {avatar.height = CalcHeight(w,h,avatar.width);});
                avatar.src = gifLink;
                statusBar.innerText = statusText.slice(0,posDocument); //Удалите эту строчку чтобы скрипт оставлял ссылку на картинку в статусе.
                profile.setAttribute("avatar","updated");
            };
        }
        else if (posInternet >= 0)
        {
            var gifLink = statusText.slice(posInternet+3);
            GetMeta(gifLink,function(w,h) {avatar.height = CalcHeight(w,h,avatar.width);});
            avatar.src = gifLink;
            statusBar.innerText = statusText.slice(0,posInternet); //Удалите эту строчку чтобы скрипт оставлял ссылку на картинку в статусе.
            profile.setAttribute("avatar","updated");
        }
        else
        {
            profile.setAttribute("avatar","updated");
            return;
        }
    }
    function CalcHeight(nWidth, nHeight, defWidth)
    {
        var coef = 1.0*nWidth/defWidth;
        return nHeight/coef;
    }
    function GetMeta(url, callback)
    {
        var img = new Image();
        img.src = url;
        img.onload = function() { callback(this.width, this.height); };
    }
})();