Shuttle SEO Switch

Adds automatic h1, h2 and h3 tag conversion from custom styles in Shuttle Data WYSIWYG-editors

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

//
// Written by Glenn Wiking
// Script Version: 0.1.2
//
//
// ==UserScript==
// @name        Shuttle SEO Switch
// @namespace   SEO
// @description Adds automatic h1, h2 and h3 tag conversion from custom styles in Shuttle Data WYSIWYG-editors
// @version     0.1.2
// @icon        https://dlw0tascjxd4x.cloudfront.net/assets/img/symbol.svg

// @include     *.shuttle.be/admin/*
// @include			*app.shuttle.be/*
// @require			https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js 
// @require			https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js

// ==/UserScript==

$(window).on("load", function() {
  function apply() {
    let buttonHeading = $(".cke_panel_frame").contents().find(".cke_panel_listItem a[title*='Heading']").parent();
    let buttonText = $(".cke_panel_frame").contents().find(".cke_panel_listItem a[title*='Text']").parent();
    buttonHeading.off("click");
    buttonText.off("click");
    buttonHeading.on("click", function() {
      let heading = parseInt( $(this).find("> a").attr("title").split("Heading ")[1] );
      console.log( heading );
      
      $(".cke_wysiwyg_frame:visible").each( function() {
        let headings = $(this).contents().find("p > span.custom-style-h"+ heading +"");
        console.log( headings );
        headings.each( function() {
          $(this).parent().prepend("<h"+ heading +" class='custom-style-h"+ heading +"'></h"+ heading +">");
          $(this).contents().appendTo( $(this).prev("h"+heading) );
          $(this).remove();
        });
      });
      
    });
    buttonText.on("click", function() {
      let heading = $(this).find("> a").attr("title");
      console.log( heading );
    });
    $(".cke_source, iframe.cke_wysiwyg_frame").parent().addClass("seo-avail");
    $(".seo-avail:visible").each( function() {
      if ( $(this).prev().find(".cke_seo").length == 0 ) {
        let sourceClone = $(".cke_toolbar:nth-last-child(2)").clone();
        $(this).prev().find("> .cke_toolbox").append( sourceClone );
        $(this).prev().find("> .cke_toolbox .cke_toolbar:last").addClass("cke_seo");
        let seoDude = $(".cke_seo");
        $(this).prev().find("> .cke_toolbox .cke_button__source:first").closest(".cke_toolbar").addClass("cke_source-tool");
        $(this).prev().find("> .cke_toolbox .cke_button[title='Source']").closest(".cke_toolbar:not(.cke_seo):not(.cke_source-tool)").remove();
        
        console.log(seoDude.find("a"));
        seoDude.find(".cke_button_label").text("SEO");
        seoDude.find(".cke_button").attr("title", "SEO");
        seoDude.find(".cke_button").off("click");
        seoDude.find("a").attr("onclick","").attr("onkeydown","").attr("onfocus","").attr("onblur","");
      }
		});
    //console.log( $(".cke_seo:visible") );
    
    $(".cke_seo:visible").each( function() {
    	$(this).off("click");
      $(this).on("click", function() {
      	let innerItem = $(this).closest(".cke_inner").find("iframe.seo").contents().find("span[class^='custom-style-h']");
        innerItem.each( function() {
          let headingSet = parseInt( $(this).attr("class").split("custom-style-h")[1] );
          $(this).parent().prepend("<h"+ headingSet +" class='custom-style-h"+ headingSet +"'></h"+ headingSet +">");
          $(this).contents().appendTo( $(this).prev("h"+headingSet) );
          $(this).hide();
          
          console.log( headingSet );
        });
        
        	console.log( innerItem );
      });
    });
  }
  
  $(".shuttle-Panel").on("click", apply);
  setInterval( function() {
  	$(".cke_source, iframe.cke_wysiwyg_frame").addClass("seo");
    $(".seo").off("click");
    $(".seo").on("click", apply());
  },500 );
  
  $("head").append("<style type='text/css'>.seo-avail {border: 1px solid #7d03ab !important} .cke_top .cke_seo .cke_button__source_icon {background-position: 0 -624px !important;} .cke_top .cke_seo .cke_button {width: 46px !important;}</style>");
});