From 3083ab04f3c998f51a9c7b89c78da4f1ad9d2110 Mon Sep 17 00:00:00 2001 From: Chris Holt Date: Mon, 27 Jan 2014 22:28:17 -0600 Subject: [PATCH] suggestions now include text and values for #91 --- canopy/canopy.fs | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/canopy/canopy.fs b/canopy/canopy.fs index 87f23dc9..3098e172 100644 --- a/canopy/canopy.fs +++ b/canopy/canopy.fs @@ -108,16 +108,38 @@ let suggestOtherSelectors cssSelector = } } return ids;""" - let classes = js classesViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> item.ToString()) |> Array.ofSeq - let ids = js idsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> item.ToString()) |> Array.ofSeq - Array.append classes ids - |> Seq.distinct |> List.ofSeq - |> remove "." |> remove "#" |> Array.ofList - |> Array.Parallel.map (fun u -> levenshtein cssSelector u) - |> Array.sortBy (fun r -> r.distance) - |> Seq.take 5 - |> Seq.map (fun r -> r.selector) |> List.ofSeq - |> (fun suggestions -> reporter.suggestSelectors cssSelector suggestions) + let valuesViaJs = """ + var values = []; + var all = document.getElementsByTagName('*'); + for (var i=0, max=all.length; i < max; i++) { + if(all[i].value && all[i].value !== "") { + values.push(all[i].value); + } + } + return values;""" + let textsViaJs = """ + var texts = []; + var all = document.getElementsByTagName('*'); + for (var i=0, max=all.length; i < max; i++) { + if(all[i].text && all[i].tagName !== 'SCRIPT' && all[i].text !== "") { + texts.push(all[i].text); + } + } + return texts;""" + let classes = js classesViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> "." + item.ToString()) |> Array.ofSeq + let ids = js idsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> "#" + item.ToString()) |> Array.ofSeq + let values = js valuesViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> item.ToString()) |> Array.ofSeq + let texts = js textsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> item.ToString()) |> Array.ofSeq + Array.append classes ids + |> Array.append values + |> Array.append texts + |> Seq.distinct |> List.ofSeq + |> remove "." |> remove "#" |> Array.ofList + |> Array.Parallel.map (fun u -> levenshtein cssSelector u) + |> Array.sortBy (fun r -> r.distance) + |> Seq.take 5 + |> Seq.map (fun r -> r.selector) |> List.ofSeq + |> (fun suggestions -> reporter.suggestSelectors cssSelector suggestions) let describe text = puts text