This is just a simple demostration of how a website could keep track of user interaction via CSS variables and url selector values.
By using the required attribute for the input text, we can just use a CSS selector which validates wether the input text is present calling the url('serverURL') every keyup event.
Every time the user enters some value, the new url for the background is updated via js.
Note: This code should be used as a learning resource and user tracking without its consent should be discouraged totally.
<div>
<input type="text" id="userText" name="userText" required />
</div>
:root{
--keyLogURL: url('http://localhost:3000/user-input');
}
input:valid {
background: var(--keyLogURL);
color:green;
}
// Changing the value of the CSS variable with the new text value
const inputText = document.getElementById('userText');
const endpoint = 'user-input';
const cssVar = '--keyLogURL';
inputText.addEventListener("keyup", e => {
const value = e.target.value;
const cssURL = getComputedStyle(document.documentElement)
.getPropertyValue(cssVar);
const cssURLSliced = cssURL.slice(0, cssURL.indexOf(endpoint)) + endpoint;
const root = document.documentElement;
root.style.setProperty(cssVar, `${cssURLSliced}?z=${value}`);
});
$ git clone https://github.com/axelgalicia/css-tracking.git
$ npm install
$ npm start
Open the browser on http://localhost:3000/index.html and start typing.
Server will capture it.
Author: Axel Galicia
Date: May 12, 2019