VK-Gif

Gif на аватар VK

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name VK-Gif
// @description Gif на аватар VK
// @author Last8Exile
// @license MIT
// @version 1.35
// @noframes
// @match *://vk.com/*
// @namespace https://greasyfork.org/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); };
    }
})();