Skip to content

Commit

Permalink
suggestions now include text and values for #91
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Jan 28, 2014
1 parent 42d91fe commit 3083ab0
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,38 @@ let suggestOtherSelectors cssSelector =
}
}
return ids;"""
let classes = js classesViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection<System.Object> |> Seq.map (fun item -> item.ToString()) |> Array.ofSeq
let ids = js idsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection<System.Object> |> 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<System.Object> |> Seq.map (fun item -> "." + item.ToString()) |> Array.ofSeq
let ids = js idsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection<System.Object> |> Seq.map (fun item -> "#" + item.ToString()) |> Array.ofSeq
let values = js valuesViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection<System.Object> |> Seq.map (fun item -> item.ToString()) |> Array.ofSeq
let texts = js textsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection<System.Object> |> 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
Expand Down

0 comments on commit 3083ab0

Please sign in to comment.