Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Workflowy Strikethrough script
// ==UserScript==
// @name Workflowy Strikethrough script
// @namespace
// @version 1.0
// @description Adds a style to the page for Strikethrough text, and sets any items with the tag #st to use that style
// @author Michael Durland
// @match*
// @grant none
// @require
// ==/UserScript==
(function() {
'use strict';
var j = jQuery.noConflict();
// Add a style to the document for strikethrough formatting.
var class_strikethrough = '' +
'.strikethrough { ' +
'color: #ccc !important; ' +
'text-decoration: line-through !important; ' +
.prop("type", "text/css")
// Define a function to add the strikethrough formatting class to all parents of nodes with the #st tag.
function update_strikethroughs() {
// Need to remove first in case the #st tag was removed.
// Need to add the class to the parent of the #st tag so that the entire item gets the strikethrough formatting.
j('.contentTag[title="Filter #st"]').parents("div.content").addClass("strikethrough");
// Set a periodic timer to update the styles.
setInterval(update_strikethroughs, 200);
// Setup a keyboard shortcut of "Alt -" to toggle strikethrough on the current node.
window.addEventListener('keydown', function(e) {
let is_minus_key = (e.key == '-');
if (is_minus_key && e.altKey) {; // need to save first. Otherwise the API might return stale data.
var current_item = WF.focusedItem();
if (current_item) {
var item_text = current_item.getName();
if (item_text) {
let is_strikethrough = item_text.includes("#st");
if (is_strikethrough) {
// Remove the tag.
item_text = item_text.replace("#st", "").trim();
else {
// Add the tag.
item_text = item_text + " #st";
// Strip off whitespace. This is needed if the #st tag is removed.
// Otherwise the string is left with a leading space if the tag was at
// the front of the string, or a trailing space if the tag was at
// the end of the string.
WF.setItemName(current_item, item_text);
}, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment