Skip to content

Instantly share code, notes, and snippets.

@salmonmoose
Created March 17, 2023 08:56
Show Gist options
  • Save salmonmoose/0ca40e51741db3da129c4af8fe4a3638 to your computer and use it in GitHub Desktop.
Save salmonmoose/0ca40e51741db3da129c4af8fe4a3638 to your computer and use it in GitHub Desktop.
Userscript to bold characters at start of each word.
// ==UserScript==
// @name First character highlight
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Highlight the first 2 characters of words to aid with readability
// @author salmonmoose
// @match *://*/*
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @grant none
// ==/UserScript==
/* global $ */
/* global jQuery */
(function() {
'use strict';
var stylesheet = `
.userscript_embiggen {
font-weight: bold;
}
`;
jQuery.fn.embiggen = function () {
const regex = /\b(\w{2})(\w*)([^\w]*)/g;
return this.each(function () {
var matches = $(this).text().matchAll(regex);
$(this).text("");
for (const match of matches) {
var $bold = $("<span>", {"class": "userscript_embiggen"});
$bold.text(match[1]);
$rest.text(match[2]);
$(this).append($bold, match[2], match[3]);
};
});
};
function createUserStyleSheets() {
var $styles = $("<style>");
$styles.text(stylesheet);
$('body').append($styles);
}
createUserStyleSheets();
$('span').embiggen();
$('p').embiggen();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment