Skip to content

Instantly share code, notes, and snippets.

@michaeldurland
Last active November 13, 2019 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeldurland/4d32a415a0068d6d4b3c3c9c20f680af to your computer and use it in GitHub Desktop.
Save michaeldurland/4d32a415a0068d6d4b3c3c9c20f680af to your computer and use it in GitHub Desktop.
Workflowy Strikethrough script
// ==UserScript==
// @name Workflowy Strikethrough script
// @namespace http://tampermonkey.net/
// @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 https://workflowy.com/*
// @grant none
// @require http://code.jquery.com/jquery-3.4.1.min.js
// ==/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; ' +
'}';
j("<style>")
.prop("type", "text/css")
.html(class_strikethrough)
.appendTo("head");
// 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.
j('.strikethrough').removeClass("strikethrough");
// 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) {
WF.save(); // 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