Help counting word letters change half to bold Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
IVWidth
Posts: 17
Joined: 14 Mar 2021, 13:58

Help counting word letters change half to bold

Post by IVWidth » 23 May 2022, 09:04

I need help/direction/links making a script that can count the number of letters in a word, divide by two, round up. Change that many letters in that word to bold. Retain capitalization and formatting, hyphenated or words joined with a forward slash are calculated separately, retaining the hyphen/slash as not bold.

This script would be used as a plug-in for websites, ideally, but at least editable text files. It is a method to improve reading ability for neurodivergent persons called online “bionic reading”. AHK is preferred, I’m not opposed to a different coding solution to inject into a website using code monkey, this just isn’t the forum to ask for that.

This may/may not be a good pre-existing example of this code working.

Thank you!

User avatar
Spawnova
Posts: 554
Joined: 08 Jul 2015, 00:12
Contact:

Re: Help counting word letters change half to bold  Topic is solved

Post by Spawnova » 23 May 2022, 10:17

I'm sure there is a ton of ways to do this, and probably a lot better than mine but here is some quick code that should do what you want

Code: Select all

input := "This may/may not be a good pre-existing example of this code working."

msgbox % clipboard := ProcessString(input)
exitapp

ProcessString(str) {
	static boldTagStart := "[b]", boldTagEnd := "[/b]"   ;bold tags to be used around the word
	word := ""	;current word is empty
	last := 0 ;last letter was not a word
	output := ""
	loop,parse,str
	{
		if (RegExMatch(a_loopfield,"i)[a-z]")) { ;if it is specifically a-z only then add to current word
			word .= a_loopfield
			last := 1 ;last character was a word character
		} else if (last = 1) {
			boldLength := (ceil(strlen(word) / 2))
			output .= boldTagStart SubStr(word,1,boldLength) boldTagEnd   ;add the start of the word with bold tags
			output .= SubStr(word,boldLength+1) a_loopfield		;add the rest of the word + the non word character
			last := 0
			word := "" ;reset word
		} else if (last = 0) {
			output .= a_loopfield  ;if not a letter then just add as normal
		}
	}
	return output
}
and the output from that is This may/may not be a good pre-existing example of this code working.

dipstick5000
Posts: 31
Joined: 21 Jan 2020, 22:01

Re: Help counting word letters change half to bold

Post by dipstick5000 » 23 May 2022, 16:22

I like to start off with, "This is probably not the best way," but you could always run wordpad or something, paste the text, have AHK change the text via mouse clicks or controls (not well understood by me), save the file or not, copy the new text with the new formatting. I hope this is not wasting your time. I'm often able to get stuff to work by doing it the wrong way, since I'm stupid, and I don't understand big words like "aphasia."

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: Help counting word letters change half to bold

Post by Chunjee » 24 May 2022, 16:11

Not sure I believe would help anyone read faster or better; but I forked this userscript into my own which fixes some stuff: https://github.com/Chunjee/bread.userscript.js
Requires Tampermonkey or other userscript extension.
I noticed some bugs so it's not perfect.
Image

If speed reading is the goal; may I suggest https://www.squirt.io/ instead
Last edited by Chunjee on 26 May 2022, 16:40, edited 1 time in total.

IVWidth
Posts: 17
Joined: 14 Mar 2021, 13:58

Re: Help counting word letters change half to bold

Post by IVWidth » 25 May 2022, 13:00

The goal isn't speed reading, it's reading focus and comprehension for those with certain disabilities. Read more here https://bionic-reading.com/. If it does nothing for you, you're one of the fortunate ones that doesn't need it. Those of us whom it does help is what this code will be used for. Some app developers are making apps for it but are trying to profit from it (allegedly). Having a disability should not be a financial liability. Making solutions that are free and available to all is my desire.

Thank you everyone for your feedback and code examples. I'll do what I can with it from here.


Post Reply

Return to “Ask for Help (v1)”