Skip to content

Instantly share code, notes, and snippets.

@jnory
Forked from takasek/wf_text_counter.js
Last active November 4, 2019 14:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnory/b39cd65508fbaa2fa39ebed932ca47a7 to your computer and use it in GitHub Desktop.
Save jnory/b39cd65508fbaa2fa39ebed932ca47a7 to your computer and use it in GitHub Desktop.
Text counter for WorkFlowy を2019年でも使えるように修正したもの
(function() {
var g = window.textCounter_g;
if (g) {
$("#textCountDart, #textCounter").remove();
clearInterval(g.textCounting);
window.textCounter_g = null;
return;
}
g = window.textCounter_g = {};
var countText = function() {
var $content = $(getSelection().focusNode.parentNode);
if (!$content) return;
g.$textCountee = $content.parents().filter(".project").first();
if (!g.$textCountee) return;
var text = g.$textCountee.find(".name>.content").text();
$("#textCounter").text(text.substring(0,10)+(text.length>10?"…":"") + " : " + text.length);
};
var styles = {
"font-size" : "13px",
color : $("#helpButton").css("color"),
"background-image" : $(".header").css("background-image"),
"background-color" : $(".header").css("background-color"),
float : "right"
};
styles["padding"] = "8px 0px 8px 10px";
$('<div id="textCountDart">🎯</div>').css(styles).click(function(){
countText();
}).appendTo($(".header"));
styles["padding"] = "8px 20px 8px 0px";
$('<div id="textCounter">←Click to count!</div>').css(styles).appendTo($(".header"));
g.textCounting = setInterval(countText,1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment