SSC Better like button

additional "Like button" without reload whole post

Stan na 01-06-2017. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name  SSC Better like button
// @author el nino
// @namespace el nino
// @description additional "Like button" without reload whole post
// @include http://www.skyscrapercity.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js
// @version 1.1.0
// @grant none
// ==/UserScript==

var like_active = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAvElEQVQ4jc3SMUoDARQE0OcSJFhIWCwsci4LsQgWnsIL5ACWwSpYpExlYW3hAQQJiARtl5xgUiQhURLJZkEcmGr+DP8Pn3+BcB4eQhVm4SVcZ61fhOelVoVR6K7EMryGbGE/3O7Q3sOZcLdjYB8OjsLUap36+CrQaVBfp8Bbg4BJgUGDgHuhFR4PKPAptEBoh2EN8zCcfNslC16Gj1+M03CVLbdsBh2HXvj8YbwJ7b3bCafL9x6Hsn6/f4U5kqizcoBXWVYAAAAASUVORK5CYII="; 


//Append like button
$("<img>", {
    "src": "data:image/png;base64," + like_active,
    "class": "fast-like", 
    "style": "display:inline; cursor: pointer;",
    "width": "16px", "height": "16px"})
    .appendTo(".dbtech-thanks-button-control");

$(".fast-like").click(function() {
    var postid = $(this).parent().data("postid");
    sendLike(postid);

});

function sendLike(postid){
    $.ajax({
        type: "POST",
        url: "http://www.skyscrapercity.com/thanks.php",
        data: {
            "securitytoken": SECURITYTOKEN,
            "do": "ajax",
            "action": "entry",            
            "varname": "likes",
            "contenttype": "post",
            "p": postid
        }
    }).done(function(data) {
        var tagData = $(data),
            origData = data;
        data = {
            thanksEntries: {},
            colorOptions: {}
        };
        var singleVals = {
            0: 'entries',
            1: 'actions',
            2: 'error'
        };
        if (tagData.find('colorOption').length) {
            tagData.find('colorOption').each(function() {
                var tagData2 = $(this);
                if (typeof data.colorOptions[tagData2.attr('varname')] == 'undefined') {
                    data.colorOptions[tagData2.attr('varname')] = {};
                }
                data.colorOptions[tagData2.attr('varname')][tagData2.attr('numclicks')] = {
                    color: tagData2.text(),
                    settings: tagData2.attr('settings')
                };
            });
        }
        if (tagData.find('thanksEntry').length) {
            tagData.find('thanksEntry').each(function() {
                data.thanksEntries[$(this).text()] = $(this).attr('numclicks');
            });
        }
        for (var i in singleVals) {
            data[singleVals[i]] = '';
            if (tagData.find(singleVals[i]).length) {
                data[singleVals[i]] = tagData.find(singleVals[i]).text();
            } else if (singleVals[i] != 'error') {
                data['error'] = origData;
            }
        }
        if (data.error) {
            alert(data.error);
            console.error(timeStamp() + "AJAX Error: %s", data.error);
            return true;
        }
        $('#dbtech_thanks_entries_' + postid).html(data.entries);
        $('#dbtech_thanks_actions_' + postid).html(data.actions);
        if (typeof data.thanksEntries != 'undefined') {
            thanksOptions.thanksEntries[postid] = data.thanksEntries;
            switch (thanksOptions.contenttype) {
                case 'post':
                    _colourPost(postid);
                    _displayPost(postid);
                    break;
            }
        }
        if (data.colorOptions) {
            thanksOptions.colorOptions = data.colorOptions;
        }
    });    
}