Greasy Fork is available in English.

Tilda Publishing Helper: Recid of Blocks, Additionnal Buttons

try to take over the world!

28.11.2018 itibariyledir. En son verisyonu görün.

// ==UserScript==
// @name         Tilda Publishing Helper: Recid of Blocks, Additionnal Buttons
// @namespace    https://roman-kosov.ru
// @version      0.8.4
// @description  try to take over the world!
// @author       Roman Kosov
// @copyright    2018, Roman Kosov (https://greasyfork.org/users/167647)
// @match        https://tilda.cc/page/?*
// @match        https://tilda.cc/projects/settings/?*
// @match        https://tilda.cc/projects/statistics/tilda/?*
// @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;
        $(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\">" +
                    "<div class=\"tp-record-edit-icons-left__item-title\"><span 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");
    });

    /* Делаем боковое меню плавающим */
    $('head').append('<style> .ss-menu { position: -webkit-sticky; position: sticky; border-bottom: 1px solid #dddddd; } .ss-content { margin-top: -800px } .ss-menu__item a { padding: 16px 30px; } .ss-menu__wrapper { margin-bottom: 0px !important } </style>');

    /* Добавляем три дополнительные кнопки в раздела «Аналитика & SEO» (неактуально после 23.11.18) */
    var projectid = $("[name='projectid']").val();
    var lang = "";
    $("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);
        }
    });
})();