notion-word-count

Get word count of Notion document

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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.

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

// ==UserScript==
// @name            notion-word-count
// @namespace       https://greasyfork.org/scripts/413663-notion-word-count
// @author          starrybouquet
// @match           https://www.notion.so/*
// @version         0.0.1
// @description     Get word count of Notion document
// ==/UserScript==

window.onload = function (){
    // add button
    var moreButton = document.getElementsByClassName('notion-topbar-more-button')[0];
    var countButton = document.createElement('button');
    countButton.textContent = 'Word Count';
    countButton.id = 'wordcount-userscript-button'
    countButton.setAttribute('style', 'element {user-select: none;transition: background 20ms ease-in 0s;cursor: pointer;display: inline-flex;align-items: center;flex-shrink: 0;white-space: nowrap;height: 28px;border-radius: 3px;font-size: 14px;line-height: 1.2;min-width: 0px;padding-left: 8px;padding-right: 8px;color: rgb(55, 53, 47);');
    countButton.onclick = getWordCount;
    moreButton.before(countButton);

    // get current wordcount on click (NOT automatically updated)
    function getWordCount(e) {
        var input = document.getElementsByClassName('notion-page-content')[0];
        // regex gratefully based on https://stackoverflow.com/questions/38102141/how-to-make-a-word-count-that-contains-html-tags-using-javascript
        // console.log(input.innerText);
        cont = input.innerText.replace(/<[^>]*>/g," ");
        cont = cont.replace(/\s+/g, ' ');
        cont = cont.replace('—', ' ');
        cont = cont.trim();
        var words = cont.split(" ").length;
        countButton.textContent = 'Word Count: ' + String(words);
    }
}