Skip to content

Instantly share code, notes, and snippets.

@fullyninja
Last active February 14, 2020 04:13
Show Gist options
  • Save fullyninja/dffd4488378a6cb9134bc3ec2e08bddf to your computer and use it in GitHub Desktop.
Save fullyninja/dffd4488378a6cb9134bc3ec2e08bddf to your computer and use it in GitHub Desktop.
Tampermonkey: K2 Smartforms Designer Rule Editor improvements
// ==UserScript==
// @name K2 - Smartform Designer Rules
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Highlight a rule in K2 Smartforms designer that has the word TEST or FIX as the comment. Also displays the comments below a rule.
// @author Peter Evans
// @match http://example.com/designer/
// @grant none
// @require https://cdn.walkme.com/player/resources/wmjQuery3315.js
// ==/UserScript==
function showComments() {
if (document.querySelector('.tm-comment')) {
console.log('Skipping');
}
else if (document.querySelector('.rule-item-wrapper div[style="display: block;"].comments')) {
console.log('Adding comment block.');
let commentBlocks = $('.rule-item-wrapper div[style="display: block;"].comments');
commentBlocks.each(function(i, el) {
let textVal = el.getAttribute('Title');
$(`<div class='tm-comment'><em style="background-color: skyblue;">${textVal}</em></div>`).insertBefore(el);
});
}
}
function highlightRules() {
// Highlight TEST rules.
if (document.querySelector('.rule-item-wrapper div[Title^="TEST"]')) {
console.log('Found TEST');
$('.rule-item-wrapper div[Title^="TEST"]').each(function(i, el) {
el.closest('div.rule-item-wrapper').setAttribute('style','background: pink');
});
}
// Highlight FIX rules.
if (document.querySelector('.rule-item-wrapper div[Title^=FIX]')) {
console.log('Found FIX');
$('.rule-item-wrapper div[Title^=FIX]').each(function(i, el) {
el.closest('div.rule-item-wrapper').setAttribute('style','background: PaleGoldenrod');
});
}
}
(function() {
'use strict';
let observer = new MutationObserver(function(mutations) {
highlightRules();
showComments();
});
observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment