How to recognize the current text format

I am trying to write a plugin for automatic document formatting, such as automatically changing character spacing and line spacing, etc. The problem I am currently facing is how to recognize the current text format? How to obtain whether the current element is a paragraph or a title? I have reviewed some API documentation, but I have not found a method that can be implemented.

Hello,
What do you mean by title? Please explain in more detail what text formats you would like to distinguish

I am trying to find the properties of the current element, such as font size, color, line spacing, etc. I only found some setter function of these, but no getter.

Hello

  1. As for the font size, there is the following method (no documentation for now):
var run = Api.GetDocument().GetElement(0).GetElement(0)
console.log(run.GetFontSize())

It returns size hps.
2. For the color, check out this link: SetColor - ONLYOFFICE Api Documentation

JavaScript

var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oRun = oParagraph.GetElement(2);
var oTextPr = oRun.GetTextPr();
var oColor = oTextPr.GetColor();
console.log(oColor.GetClassType())
  1. As for line spacing, please check out the following link:
    GetSpacingAfter - ONLYOFFICE Api Documentation

emm, is there some api that I can change all elements of a specific style? I try to traverse full document to match style, but failed.

You can use the following script:

var oDocument = Api.GetDocument()
var arrParagraphs = oDocument.GetAllParagraphs()
var oNewDocumentStyle = oDocument.GetStyle("Heading 6");

arrParagraphs.forEach((par) => {
        if (par.GetStyle()) {
            if (par.GetStyle().GetName() == 'Normal'){
                par.SetStyle(oNewDocumentStyle)
        }
    }
})