The fact hat matrix of the uncentered data and one of the centered data has the linear relationship makes it possible.
Let's say the linear model $Y=X\beta+\epsilon$.
This model has the hat matrix $H=X(X'X)^{-1}X$ as known.
And let's consider the centered linear model $Y_c=X_c \beta_c+\epsilon$
where $Y_c=Y-\frac{1}{n} 1_n 1_n' Y$ is the centered response vector and the $X_c=X_d-\frac{1}{n} 1_n 1_n' X_d$ is the centered design matrix ($X_d$ is the design matrix $X$ without column of ones.) and it has no column of ones for intercept because this model passes the origin. This has the hat matrix $H_c=X_c(X_c'X_c)^{-1}X_c'$.
$X = \begin{bmatrix}1_n & X_d\end{bmatrix}$
$X'X = \begin{bmatrix}1_n'1_n & 1_n'X_d \\ X_d'1_n&X_d'X_d\end{bmatrix}$
$(X'X)^{-1}=\begin{bmatrix} 1/n+1/n^2 1_n'X_d(X_c'X_c)^{-1} X_d' 1_n & -1/n 1_n'X_d (X_c'X_c)^{-1} \\ -1/n (X_c'X_c)^{-1} X_d' 1_n &(X_c'X_c)^{-1} \end{bmatrix}$
$\begin{align} X(X'X)^{-1}X'&= 1/n 1_n 1_n' + 1/n^2 1_n 1_n' X_d(X_c'X_c)^{-1} X_d' 1_n1_n'-1/n X_d (X_c'X_c)^{-1} X_d' 1_n 1_n'-1/n 1_n 1_n'X_d (X_c'X_c)^{-1} X_d'+ X_d(X_c'X_c)^{-1}X_d'\\
&=1/n 1_n1_n' + (1/n 1_n1_n' -I)X_d (X_c'X_c)^{-1} X_d' (1/n 1_n1_n' -I) \\
&=1/n 1_n1_n'+X_c(X_c'X_c)^{-1}X_c'
\end{align}$
So $H=H_c+1/n 1_n1_n'$.
The result from the answer of second link in the question can be written as
$D_i^2 = (n-1)\left(h_i - \frac{1}{n}\right)=(n-1) h_{c i}$
Therefore we can use hat matrix for the measure of the distance as well.
I am not a native English speaker so any improvement of this answer is very welcomed.