# titleps - faded rule in the header of a document

I am creating a document with the titleps package and was wondering if anyone could suggest a code that replicates a faded grey headrule such as that created with fancyhdr in fading tikz fancyhdr problem in book printing. The code below gives the basic structure of the headers in my document

\setheadrule{0pt}% Header rule
\sethead[\textbf{\thepage} Abstract Algebra]% even left
[]% even centre
[]% even right
{}% odd left
{}% odd centre
{\chaptertitle \textbf{\thepage}}% odd right


I tried to make a new command with \makeheadrule but to no avail. Tikz seems to be the way forward but I'm having trouble figuring it out. I'd like the faded line to be the same length as the bit of text in the header which it underlines, as in the link provided.

\documentclass{book}
\usepackage{amssymb}
\usepackage{titleps}
\usepackage{tikz}

\newpagestyle{main}%
[\textbf{\thepage} Abstract Algebra]% even left
[]% even centre
[]% even right
{}% odd left
{}% odd centre
{\chaptertitle\ $\thicksim$ \textbf{\thepage}}% odd right
}
\pagestyle{main}

{\raisebox{-.3\baselineskip}%
{\ifodd\count0%
\makebox[\textwidth][r]%
{\tikz\fill[darkgray,path fading=west] (0,0) rectangle (4.98,0.02);}%
\else
\makebox[\textwidth][l]%
{\tikz\fill[darkgray,path fading=east] (0,0) rectangle (4.98,0.02);}%
\fi
}%
}

\usepackage{blindtext}
\begin{document}
\chapter{First chapter}
\Blindtext[20]
\end{document}