Poster IDs

From Bibliotheca Anonoma
Revision as of 16:15, 5 September 2022 by Chakatan (talk | contribs)

Boards such as /pol/ and /bant/ support unique poster IDs that let you recognize the individual behind posts throughout a thread.

These IDs are displayed with colors on 4chan but colorless on FoolFuuka. We've been able to locate the code computing the color within 4chan's JS extension and offer a simplified Golang version below:

func IDStyle(s string) string {

     //Initially equals 0
     var hash int64
     //Iterate over bytes in the string
     for _, r := range []byte(s) {
           hash = ((hash << 5) - hash) + int64(r)
     }
     red := (hash >> 24) & 0xFF
     green := (hash >> 16) & 0xFF
     blue := (hash >> 8) & 0xFF
     result := fmt.Sprintf("background-color: rgb(%d, %d, %d);", red, green, blue)
     //Determines how light the color just computed is
     light := float64(red)*0.299+float64(green)*0.587+float64(blue)*0.114 > 125
     if light {
           result += "color: black;"
     } else {
           result += "color: white;"
     }
     //e.g. "background-color: rbg(10, 20, 30); color: white"
     return result

}