// ==UserScript==// @name BitBoxes// @namespace https://scriptspry.com/// @version 0.1// @license MIT// @description Checkboxes for bitbucket cause we need them! ☐☑☒// @author You// @match https://bitbucket.org/*// @grant none// ==/UserScript==((()=>{/** * Gets an array of the matching text nodes contained by the specified element. * @param {!Element} elem * The DOM element which will be traversed. * @param {function(!Node,!Element):boolean} opt_fnFilter * Optional function that if a true-ish value is returned will cause the * text node in question to be added to the array to be returned from * getTextNodesIn(). The first argument passed will be the text node in * question while the second will be the parent of the text node. * @return {!Array.<!--Node-->} * Array of the matching text nodes contained by the specified element. * * // Source & Thanks to: http://cwestblog.com/2014/03/14/javascript-getting-all-text-nodes/ * **/functiongetTextNodesIn(elem,opt_fnFilter){lettextNodes=[];if(elem){for(letnodes=elem.childNodes,i=nodes.length;i--;){constnode=nodes[i];constnodeType=node.nodeType;if(nodeType==3){if(!opt_fnFilter||opt_fnFilter(node,elem)){textNodes.push(node);}}elseif(nodeType==1||nodeType==9||nodeType==11){textNodes=textNodes.concat(getTextNodesIn(node,opt_fnFilter));}}}returntextNodes;}constreplacements=newMap([[newRegExp('\\[_\\]','igm'),'☐'],[newRegExp('\\[x\\]','igm'),'☒'],[newRegExp('\\[-\\]','igm'),'☑'],[newRegExp('\\[v\\]','igm'),'☑'],[newRegExp('\\[\\*\\]','igm'),'☑']]);constregexes=Array.from(replacements.keys());consthasSymbol=node=>regexes.find(s=>node.textContent.match(s));constboxify=()=>{document.querySelectorAll('li').forEach(li=>{getTextNodesIn(li,hasSymbol).forEach(textNode=>{for(const[symbol,replacement]ofreplacements)textNode.textContent=textNode.textContent.replace(symbol,replacement);});});};if(jQuery!==undefined)jQuery(boxify);elsewindow.addEventListener('load','DOMContentLoaded',boxify,false);}))();
Comments (2)
Nkansah Rexford
How would I use it if I want to?
script spry
Install Tampermonkey and create a new script using this code.
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.
How would I use it if I want to?
Install Tampermonkey and create a new script using this code.