Greasy Fork is available in English.

Tilda Publishing Helper: Recid of Blocks, Additionnal Buttons

try to take over the world!

As of 04/12/2018. See the latest version.

// ==UserScript==
// @name         Tilda Publishing Helper: Recid of Blocks, Additionnal Buttons
// @namespace    https://roman-kosov.ru
// @version      0.10.2
// @description  try to take over the world!
// @author       Roman Kosov
// @copyright    2018, Roman Kosov (https://greasyfork.org/users/167647)
// @match        https://tilda.cc/projects/
// @match        https://tilda.cc/page/?*
// @match        https://tilda.cc/projects/settings/?*
// @require      http://code.jquery.com/jquery-1.10.2.min.js
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    /* Делаем редирект, если страница недоступна для редактирования */
    var textBody = $('body').text();

    if (textBody === "You can't edit this project.." || textBody === "This page belongs to another account, so you can't see or edit it...") {
        if(window.location.href.indexOf("projectid=") !== -1) {
            var projectid = window.location.href.substr(window.location.href.indexOf("projectid=")+10, 6);
            var pageid = "";
            var url = "";

            if(window.location.href.indexOf("pageid=") !== -1) {
                pageid = window.location.href.substr(window.location.href.indexOf("pageid=")+7, 7);
            }

            if(projectid) {
                url = "https://project" + projectid + ".tilda.ws/";
            }

            if(pageid) {
                url += "page" + pageid + ".html";
            }

            window.location.href = url;
        }
    }

    /* Добавляем recid для каждого блока на странице */
    $("div.record").each(function (index) {
        var recordid = $(this).attr("recordid");
        var recid = "#rec" + recordid;
        var copy = `var temp = $('<input>'); $('body').append(temp); temp.val('#rec' + $('#record${recordid}').attr('recordid')).select(); document.execCommand('copy'); temp.remove();`
        $(this).children("div#mainleft").children("div")
            .append(`<div class="tp-record-edit-icons-left__one-right-space"></div>` +
                    `<div class="tp-record-edit-icons-left__one" style="cursor: pointer;" title="Скопировать номер блока">` +
                    `<div class="tp-record-edit-icons-left__item-title">` +
                    `<span onclick="${copy}"class="tp-record-edit-icons-left__item-tplcod">${recid}</span>` +
                    `</div>` +
                    `</div>`);

        $("#record" + recordid + " > div:nth-child(1):not(.mainright)").appendTo($(this)
                                                                                 .children("div#mainleft").children("div")).removeClass().css("padding", "7px 15px");
    });

    /* Делаем боковое меню плавающим */
    var isEmail;
    if($("[data-menu-item='#ss_menu_fonts']")) {
        $('head').append('<style> .ss-wrapper {} .ss-menu { position: -webkit-sticky; position: sticky; border: 1px solid #dddddd; margin: 2px; } .ss-menu__item a { padding: 16px 30px; font-size: 16px; } .ss-menu__wrapper { margin-bottom: 0px !important } </style>');
        isEmail = $("[data-menu-item='#ss_menu_fonts']").css("display");
    }

    $('head').append('<style> .ss-content { margin-top: -' + (isEmail == "none" ? 630 : 770 ) + 'px } </style>');

    $("li[data-menu-item]").click(function() {
        $('html,body').animate({
            scrollTop: $('body').offset().top+105
        }, 300 );
    });

    /* Добавляем кнопку заявок к карточкам проектов */
    var lang = "";
    $(".td-sites-grid__cell").each(function() {
        var id = $(this).attr("id").replace("project", "");
        var buttons = $(this).find(".td-site__settings");
        var link = $(this).find("a[href^='/projects/?projectid=']:not(.td-site__section-one)");
        var leads = "",
            settings = "";

//        console.log($(link).text());

        if($(link).text().includes("Редактировать сайт")) {
            lang = "RU";
            leads = "Заявки";
            settings = "Настройки";
            $(link).html("Редактировать");
        } else if ($(link).text().includes("Edit site")) {
            lang = "EN";
            leads = "Leads";
            settings = "Settings";
            $(link).html("EDIT");
        } else {
            return;
        }

        $( '<table class="td-site__settings"><tbody><tr><td><img src="/tpl/img/td-icon-leads.png" width="20px" height="14px" style="padding:5px;"></td><td class="td-site__settings-title"><a href="./leads/?projectid=' + id + '">' + leads + '</a></td></tr></tbody></table>' ).appendTo($(buttons).parent());
        $( '<table class="td-site__settings"><tbody><tr><td><img src="/tpl/img/td-site__settings.png" width="14px" height="14px" style="padding:5px;"></td><td class="td-site__settings-title"><a href="./settings/?projectid=' + id + '">' + settings + '</a></td></tr></tbody></table>' ).appendTo($(buttons).parent());
    });

    $('head').append('<style> .td-site__settings { margin-right: 15px; } .td-site__settings-title { font-size: 12px; } .td-site__url-link { font-size: 14px; } .td-site__section-two { padding: 0 30px;} </style>');

    /* Добавляем три дополнительные кнопки в раздела «Аналитика & SEO» (неактуально после 23.11.18) */
    var projectid = $("[name='projectid']").val();
    $("a.js-metrika-connect-state").each(function() {
        if(this.text.includes("Перейти в раздел")) {
            lang = "RU";
        } else if(this.text.includes("Go to panel")) {
            lang = "EN";
        }

        if (lang === "RU" || lang === "EN") {
            $( "<br><br>" ).appendTo(this.parentNode);
            $("<a>", {
                'class': "ss-btn",
                'href': "https://tilda.cc/projects/redirects/?projectid=" + projectid,
                html: (lang === "RU" ? '301 редиректы' : '301 redirects')
            }).appendTo(this.parentNode);
            $( "<span>", {
                html: '&emsp;'
            } ).appendTo(this.parentNode);

            $("<a>", {
                'class': "ss-btn",
                'href': "https://tilda.cc/projects/favicons/?projectid=" + projectid,
                html: (lang === "RU" ? 'Иконки для сайта' : 'Icons for site')
            }).appendTo(this.parentNode);
            $( "<span>", {
                html: '&emsp;'
            } ).appendTo(this.parentNode);

            $("<a>", {
                'class': "ss-btn",
                'href': "https://tilda.cc/projects/https/?projectid=" + projectid,
                html: (lang === "RU" ? 'Настройка HTTPS' : 'HTTPS settings')
            }).appendTo(this.parentNode);
            $( "<span>", {
                html: '&emsp;'
            } ).appendTo(this.parentNode);
        }
    });
})();