Changed around line 7
-
Changed around line 94
+ .loading {
+ position: fixed;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ background: rgba(255, 255, 255, 0.8);
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ z-index: 1000;
+ }
Changed around line 130
-
- Calculate FocusRating (Basic)
-
+
Changed around line 145
- let embeddings = [];
- let projectedPoints = [];
Changed around line 174
- // Automatically trigger analysis
- calculateFocusArea();
- // Rest of the JavaScript remains the same
Changed around line 224
- function analyzeText() {
- const text = document.getElementById("textInput").value;
- embeddings = basicEmbedding(text);
- projectedPoints = simplePCA(embeddings);
- updateVisualization();
- }
-
- function analyzeTextPro() {
- window.location = "https://buy.stripe.com/9AQ3fYgzfgHbguY5kP";
- }
-
- function updateVisualization() {
+ function updateVisualization(
+ projectedPoints,
+ messages,
+ focusEmbedding = null,
+ ) {
- chart = new Chart(ctx, {
- type: "scatter",
- data: {
- datasets: [
+ const datasets = [
+ {
+ label: "Thoughts",
+ data: projectedPoints.map((point, index) => ({
+ x: point[0],
+ y: point[1],
+ message: messages[index],
+ })),
+ backgroundColor: "rgba(0, 102, 204, 0.5)",
+ },
+ ];
+
+ // Add focus point if provided
+ if (focusEmbedding) {
+ datasets.push({
+ label: "Target",
+ data: [
- label: "Thought Embeddings",
- data: projectedPoints.map((point) => ({
- x: point[0],
- y: point[1],
- })),
- backgroundColor: "rgba(0, 102, 204, 0.5)",
+ x: focusEmbedding[0],
+ y: focusEmbedding[1],
+ message: document.getElementById("focusThought").value,
- },
+ backgroundColor: "rgba(255, 0, 0, 0.8)",
+ pointRadius: 8,
+ });
+ }
+
+ chart = new Chart(ctx, {
+ type: "scatter",
+ data: { datasets },
Changed around line 275
+ plugins: {
+ tooltip: {
+ callbacks: {
+ label: function (context) {
+ return context.raw.message;
+ },
+ },
+ },
+ legend: {
+ display: true,
+ },
+ },
- function calculateFocusArea() {
- const focusThought = document
- .getElementById("focusThought")
- .value.toLowerCase();
- const text = document.getElementById("textInput").value;
- const lines = text
- .toLowerCase()
- .split(/\n+/)
- .filter((w) => w.length > 0);
+ function showLoading() {
+ const loadingDiv = document.createElement("div");
+ loadingDiv.className = "loading";
+ loadingDiv.id = "loadingIndicator";
+
+ const spinnerHTML = `
+
+
+ border-top: 4px solid #0066cc;
+ border-radius: 50%;
+ width: 40px;
+ height: 40px;
+ animation: spin 1s linear infinite;
+ margin: 0 auto;
+ margin-bottom: 10px;">
+
+
+ `;
- const totalLines = lines.length;
- const hits = lines.filter((line) => line.includes(focusThought)).length;
- const focusRating = (100 * hits) / totalLines;
+ loadingDiv.innerHTML = spinnerHTML;
+ document.body.appendChild(loadingDiv);
+ }
- document.getElementById("results").innerHTML = `
-
RateMyFocus Results
-
Total Thoughts: ${totalLines}
-
FocusRating for ${focusThought}: ${focusRating.toFixed(0)}% ๐
- `;
+ function hideLoading() {
+ const loadingDiv = document.getElementById("loadingIndicator");
+ if (loadingDiv) {
+ loadingDiv.remove();
+ }
+
+ function analyzeText() {
+ showLoading();
+
+ setTimeout(() => {
+ const text = document.getElementById("textInput").value;
+ const focusThought = document.getElementById("focusThought").value;
+ const lines = text.split(/\n+/).filter((line) => line.length > 0);
+
+ const totalLines = lines.length;
+ const hits = lines.filter((line) =>
+ line.toLowerCase().includes(focusThought.toLowerCase()),
+ ).length;
+
+ const focusRating = (100 * hits) / totalLines;
+
+ const embeddings = basicEmbedding(text);
+ const focusEmbedding = basicEmbedding(focusThought)[0];
+ const projectedPoints = simplePCA(embeddings);
+
+ const focusProjected = simplePCA([focusEmbedding])[0];
+
+ updateVisualization(projectedPoints, lines, focusProjected);
+
+ document.getElementById("results").innerHTML = `
+
RateMyFocus Results
+
Total Thoughts: ${totalLines}
+
FocusRating for ${focusThought}: ${focusRating.toFixed(1)}% ๐
+
Using basic word matching
+ `;
+
+ hideLoading();
+ }, 100); // Small delay to ensure loading indicator shows even for quick operations
+ }
+
+ async function analyzeTextPro() {
+ window.location = "https://buy.stripe.com/9AQ3fYgzfgHbguY5kP";
+ }
+
+ // Add the spin animation to the existing style section
+ const styleSheet = document.styleSheets[0];
+ styleSheet.insertRule(
+ `
+ @keyframes spin {
+ 0% { transform: rotate(0deg); }
+ 100% { transform: rotate(360deg); }
+ }
+ `,
+ styleSheet.cssRules.length,
+ );