Poster IDs: Difference between revisions

From Bibliotheca Anonoma
(Initial version)
 
mNo edit summary
Line 5: Line 5:
<code>
<code>
func IDStyle(s string) string {
func IDStyle(s string) string {
//Initially equals 0
      //Initially equals 0
var hash int64
      var hash int64


//Iterate over bytes in the string
      //Iterate over bytes in the string
for _, r := range []byte(s) {
      for _, r := range []byte(s) {
hash = ((hash << 5) - hash) + int64(r)
            hash = ((hash << 5) - hash) + int64(r)
}
      }


red := (hash >> 24) & 0xFF
      red := (hash >> 24) & 0xFF
green := (hash >> 16) & 0xFF
      green := (hash >> 16) & 0xFF
blue := (hash >> 8) & 0xFF
      blue := (hash >> 8) & 0xFF


result := fmt.Sprintf("background-color: rgb(%d, %d, %d);", red, green, blue)
      result := fmt.Sprintf("background-color: rgb(%d, %d, %d);", red, green, blue)


//Determines how light the color just computed is
      //Determines how light the color just computed is
light := float64(red)*0.299+float64(green)*0.587+float64(blue)*0.114 > 125
      light := float64(red)*0.299+float64(green)*0.587+float64(blue)*0.114 > 125


if light {
      if light {
result += "color: black;"
            result += "color: black;"
} else {
      } else {
result += "color: white;"
            result += "color: white;"
}
      }


//e.g. "background-color: rbg(10, 20, 30); color: white"
      //e.g. "background-color: rbg(10, 20, 30); color: white"
return result
      return result
}
}
</code>
</code>

Revision as of 16:15, 5 September 2022

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

}